跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

host_clone_test.go

98 行 · 3.5 KB历史下载
1package workbench
2
3import (
4 "encoding/json"
5 "net/http"
6 "net/http/httptest"
7 "os"
8 "path/filepath"
9 "runtime"
10 "strings"
11 "testing"
12
13 "github.com/google/uuid"
14 "github.com/sylvinus/agent-vm/internal/guestos"
15 "github.com/sylvinus/agent-vm/internal/hostimage"
16)
17
18func TestHostClonePreviewReusesPendingChoiceAndExistingDisk(t *testing.T) {
19 if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" {
20 t.Skip("fixture uses the Apple Silicon installation kit")
21 }
22 s := testServer(t)
23 s.exe = filepath.Join(s.profile, "bin", "cage")
24 for _, name := range []string{"prepare-macos-media.sh", "provision-macos-workbench.sh", "project/cage-sshfs", "native-browser/macos-native-browser.mjs", "cage-finish-initial-setup"} {
25 path := filepath.Join(filepath.Dir(s.exe), "guest-os", name)
26 if err := os.MkdirAll(filepath.Dir(path), 0700); err != nil {
27 t.Fatal(err)
28 }
29 if err := os.WriteFile(path, []byte("fixture"), 0600); err != nil {
30 t.Fatal(err)
31 }
32 }
33 plan := hostimage.Plan{
34 Host: hostimage.Identity{System: "macos", Version: "26.5", Build: "25F71", Arch: "arm64"},
35 Version: "26.5", Build: "25F71", Format: "ipsw", Bytes: 1 << 30,
36 URL: "https://updates.cdn-apple.com/fixture.ipsw", Digest: "sha256:" + strings.Repeat("a", 64),
37 }
38 install := guestos.Installation{Version: 1, ID: uuid.New(), System: "macos", Source: plan}
39 if err := guestos.SaveInstallation(s.profile, install); err != nil {
40 t.Fatal(err)
41 }
42 for _, started := range []bool{false, true} {
43 if started {
44 if err := os.MkdirAll(filepath.Join(s.profile, "state", "lima", "mac"), 0700); err != nil {
45 t.Fatal(err)
46 }
47 }
48 r := httptest.NewRequest(http.MethodGet, "/api/environment/guest-systems/clone", nil)
49 r.AddCookie(&http.Cookie{Name: s.cookieName() + "-desktop", Value: trustedViewProof(s.token)})
50 w := httptest.NewRecorder()
51 s.hostClone(w, r)
52 if w.Code != http.StatusOK {
53 t.Fatalf("preview: %d %s", w.Code, w.Body.String())
54 }
55 var result struct {
56 Plan hostimage.Plan `json:"plan"`
57 MinimumFreeGiB int `json:"minimum_free_gib"`
58 InstallationStarted bool `json:"installation_started"`
59 }
60 if err := json.Unmarshal(w.Body.Bytes(), &result); err != nil {
61 t.Fatal(err)
62 }
63 minimum := 33
64 if started {
65 minimum = 1
66 }
67 if result.Plan != plan || result.MinimumFreeGiB != minimum || result.InstallationStarted != started {
68 t.Fatalf("pending source or remaining disk budget changed: %+v", result)
69 }
70 }
71}
72
73func TestPendingLinuxCloneRetryReturnsToInstallerAdmission(t *testing.T) {
74 if runtime.GOOS == "linux" {
75 t.Skip("this case verifies rejection on a different host family")
76 }
77 s := testServer(t)
78 install := guestos.Installation{
79 Version: 1, ID: uuid.New(), System: "ubuntu-22.04",
80 Source: hostimage.Plan{
81 Host: hostimage.Identity{System: "ubuntu-22.04", Version: "22.04", Arch: "amd64"},
82 Version: "22.04", Format: "qcow2", Path: filepath.Join(s.profile, "ubuntu.img"),
83 Digest: "sha256:" + strings.Repeat("a", 64),
84 },
85 }
86 if err := guestos.SaveInstallation(s.profile, install); err != nil {
87 t.Fatal(err)
88 }
89 for _, body := range []string{`{}`, `{"guest_system":"ubuntu-22.04"}`} {
90 r := httptest.NewRequest(http.MethodPost, "/api/start", strings.NewReader(body))
91 r.AddCookie(&http.Cookie{Name: s.cookieName() + "-desktop", Value: trustedViewProof(s.token)})
92 w := httptest.NewRecorder()
93 s.start(w, r)
94 if w.Code == http.StatusOK || s.jobs.snapshot().Running {
95 t.Fatal("pending clone bypassed installer admission through the generic start path")
96 }
97 }
98}