提交记录修改internal/workbench/browser_workspaces.go+3 −1看文件
修改internal/workbench/project_remove_test.go+33 −0看文件
修改internal/workbench/windows_browser_client_test.go+3 −0看文件
| @@ -85,7 +85,9 @@ func (s *Server) browserStateForHost(body []byte) ([]byte, error) { | ||
| 85 | 85 | byGuest := make(map[string]string, len(authorized)) |
| 86 | 86 | for _, hostPath := range authorized { |
| 87 | 87 | if s.macosGuest != nil { |
| 88 | 删除: byGuest[macOSProjectPath(s.macosGuest.User, hostPath)] = hostPath | |
| 88 | 新增: guestPath := macOSProjectPath(s.macosGuest.User, hostPath) | |
| 89 | 新增: byGuest[guestPath] = hostPath | |
| 90 | 新增: byGuest[filepath.Base(guestPath)] = hostPath | |
| 89 | 91 | } else { |
| 90 | 92 | byGuest[guestPath(hostPath)] = hostPath |
| 91 | 93 | } |
| @@ -1,10 +1,12 @@ | ||
| 1 | 1 | package workbench |
| 2 | 2 | |
| 3 | 3 | import ( |
| 4 | 新增: "context" | |
| 4 | 5 | "encoding/json" |
| 5 | 6 | "io" |
| 6 | 7 | "net/http" |
| 7 | 8 | "os" |
| 9 | 新增: "os/exec" | |
| 8 | 10 | "path/filepath" |
| 9 | 11 | "slices" |
| 10 | 12 | "strings" |
| @@ -253,3 +255,34 @@ func TestAgentProjectRemovalUsesSharedOwner(t *testing.T) { | ||
| 253 | 255 | t.Fatal("agent removal did not revoke grant", err) |
| 254 | 256 | } |
| 255 | 257 | } |
| 258 | 新增: | |
| 259 | 新增:func TestProjectRemovalRejectsRestoredMacOSEditor(t *testing.T) { | |
| 260 | 新增: s := testServer(t) | |
| 261 | 新增: root, _ := filepath.EvalSymlinks(t.TempDir()) | |
| 262 | 新增: s.macosGuest = &guestos.MacOSProfile{Instance: "mac", User: "guestdev"} | |
| 263 | 新增: s.ready = true | |
| 264 | 新增: s.preferences.ClaudeTerminalCommand = "custom-shell" | |
| 265 | 新增: if err := s.rememberSharedProject(root); err != nil { | |
| 266 | 新增: t.Fatal(err) | |
| 267 | 新增: } | |
| 268 | 新增: client := fixtureWindowsBrowserClient(t) | |
| 269 | 新增: start := client.start | |
| 270 | 新增: client.start = func(ctx context.Context) (*exec.Cmd, error) { | |
| 271 | 新增: command, err := start(ctx) | |
| 272 | 新增: if err == nil { | |
| 273 | 新增: command.Env = append(command.Env, "CAGE_BROWSER_EDITOR_WORKSPACE="+filepath.Base(macOSProjectPath(s.macosGuest.User, root))) | |
| 274 | 新增: } | |
| 275 | 新增: return command, err | |
| 276 | 新增: } | |
| 277 | 新增: s.windowsBrowserControl = client | |
| 278 | 新增: body, err := s.browserAction(t.Context(), "tabs", nil) | |
| 279 | 新增: var state struct { | |
| 280 | 新增: Tabs []struct { | |
| 281 | 新增: Workspace string `json:"workspace"` | |
| 282 | 新增: } `json:"tabs"` | |
| 283 | 新增: } | |
| 284 | 新增: if err != nil || json.Unmarshal(body, &state) != nil || len(state.Tabs) != 1 || state.Tabs[0].Workspace != root { | |
| 285 | 新增: t.Fatal("restored editor lost host workspace", string(body), err) | |
| 286 | 新增: } | |
| 287 | 新增: removeProjectRequest(t, s, root, 409) | |
| 288 | 新增:} | |
| @@ -50,6 +50,9 @@ func TestWindowsBrowserRelayHelper(t *testing.T) { | ||
| 50 | 50 | time.Sleep(time.Hour) |
| 51 | 51 | case "/tabs": |
| 52 | 52 | result = map[string]any{"active": "tab", "tabs": []any{}} |
| 53 | 新增: if workspace := os.Getenv("CAGE_BROWSER_EDITOR_WORKSPACE"); workspace != "" { | |
| 54 | 新增: result = map[string]any{"active": "tab", "tabs": []any{map[string]any{"id": "tab", "kind": "editor", "workspace": workspace, "blocked": true}}} | |
| 55 | 新增: } | |
| 53 | 56 | case "/events": |
| 54 | 57 | result = map[string]any{"sequence": 2, "events": []any{}} |
| 55 | 58 | if request.Input.After == 2 { |

