跳到主要内容

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

浏览文件

migrate_unix_test.go

71 行 · 1.9 KB历史下载
1//go:build unix
2
3package vm
4
5import (
6 "context"
7 "io"
8 "os"
9 "path/filepath"
10 "syscall"
11 "testing"
12)
13
14func device(p string) (uint64, bool) {
15 var st syscall.Stat_t
16 if err := syscall.Stat(p, &st); err != nil {
17 return 0, false
18 }
19 return uint64(st.Dev), true
20}
21
22// To another file system: copied, then removed (rename cannot).
23func TestMoveOldAcrossFS(t *testing.T) {
24 ctx := context.Background()
25 l := newTestLima(t)
26 old := os.Getenv("LIMA_HOME")
27 from, _ := device(old)
28 other := ""
29 for _, d := range []string{"/dev/shm", os.Getenv("AGENT_VM_TEST_OTHER_FS")} {
30 if dev, ok := device(d); d != "" && ok && dev != from {
31 other = d
32 break
33 }
34 }
35 if other == "" {
36 t.Skip("no other file system: set AGENT_VM_TEST_OTHER_FS")
37 }
38 none := []Mount{}
39 if err := l.Create(ctx, "agent-vm-p-12345678", "template:debian-13", Settings{CPUs: 1, Mounts: &none}, io.Discard); err != nil {
40 t.Fatal(err)
41 }
42 dir := filepath.Join(old, "agent-vm-p-12345678")
43 os.WriteFile(filepath.Join(dir, "x.tmp"), []byte("x"), 0o644)
44 os.Symlink("lima.yaml", filepath.Join(dir, "link"))
45 tmp, err := os.MkdirTemp(other, "avm")
46 if err != nil {
47 t.Skip(err)
48 }
49 t.Cleanup(func() { os.RemoveAll(tmp) })
50 now := filepath.Join(tmp, "lima")
51 if err := MoveOld(ctx, old, now, "agent-vm-p-12345678", "p-12345678"); err != nil {
52 t.Fatal(err)
53 }
54 if _, err := os.Stat(dir); !os.IsNotExist(err) {
55 t.Error("left in the old home")
56 }
57 moved := filepath.Join(now, "p-12345678")
58 if _, err := os.Stat(filepath.Join(moved, "x.tmp")); err == nil {
59 t.Error("x.tmp was moved")
60 }
61 if l, err := os.Readlink(filepath.Join(moved, "link")); err != nil || l != "lima.yaml" {
62 t.Errorf("link: %q %v", l, err)
63 }
64 l2, err := NewLima(now, t.TempDir())
65 if err != nil {
66 t.Fatal(err)
67 }
68 if inst, err := l2.Get(ctx, "p-12345678"); err != nil || inst.CPUs != 1 || inst.Status != Stopped {
69 t.Fatalf("in the new home: %+v %v", inst, err)
70 }
71}