跳到主要内容

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

浏览文件

ubuntu_test.go

71 行 · 2.4 KB历史下载
1package hostimage_test
2
3import (
4 "context"
5 "encoding/json"
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10
11 "github.com/sylvinus/agent-vm/internal/hostimage"
12 "github.com/sylvinus/agent-vm/internal/limaembed"
13)
14
15func TestUbuntu2204PinnedImageAndPersistentTemplate(t *testing.T) {
16 template, err := limaembed.ReadImageTemplate("ubuntu-22.04")
17 if err != nil {
18 t.Fatal(err)
19 }
20 identity := hostimage.Identity{System: "ubuntu-22.04", Version: "22.04", Arch: "amd64"}
21 state := t.TempDir()
22 plan, err := hostimage.Resolve(context.Background(), identity, state, t.TempDir(), template, nil)
23 if err != nil || !strings.Contains(plan.URL, "/jammy/release-20261106/") || len(plan.Digest) != 71 {
24 t.Fatalf("source: %+v %v", plan, err)
25 }
26 plan.Path = filepath.Join(state, "ubuntu.img")
27 if err := hostimage.WriteLinuxTemplate(state, plan); err != nil {
28 t.Fatal(err)
29 }
30 saved, err := hostimage.Load(filepath.Join(state, "guest-media"))
31 if err != nil || saved != plan {
32 t.Fatalf("persistent media: %+v %v", saved, err)
33 }
34 path, err := hostimage.LinuxTemplate(state)
35 if err != nil {
36 t.Fatal(err)
37 }
38 data, err := os.ReadFile(path)
39 var config struct{ Images []map[string]string }
40 if err != nil || json.Unmarshal(data, &config) != nil || len(config.Images) != 1 || config.Images[0]["location"] != plan.Path {
41 t.Fatalf("template changed source or added fallbacks: %s %v", data, err)
42 }
43 plan.URL = "https://cloud-images.ubuntu.com.evil.test/ubuntu.img"
44 if err := plan.Validate(); err == nil {
45 t.Fatal("accepted an untrusted Ubuntu image source")
46 }
47}
48
49func TestUbuntuChoiceNeverFallsBackAfterMetadataLoss(t *testing.T) {
50 for _, removed := range []string{"host-system.yaml", "host-system-source.json"} {
51 state := t.TempDir()
52 template, _ := limaembed.ReadImageTemplate("ubuntu-22.04")
53 plan, err := hostimage.Resolve(t.Context(), hostimage.Identity{System: "ubuntu-22.04", Version: "22.04", Arch: "arm64"}, state, state, template, nil)
54 if err != nil {
55 t.Fatal(err)
56 }
57 plan.Path = filepath.Join(state, "ubuntu.img")
58 if err := hostimage.WriteLinuxTemplate(state, plan); err != nil {
59 t.Fatal(err)
60 }
61 if system, err := hostimage.LinuxSystem(state); err != nil || system != "ubuntu-22.04" {
62 t.Fatalf("identity: %q %v", system, err)
63 }
64 if err := os.Remove(filepath.Join(state, "guest-media", removed)); err != nil {
65 t.Fatal(err)
66 }
67 if _, err := hostimage.LinuxTemplate(state); err == nil {
68 t.Fatalf("silently fell back after losing %s", removed)
69 }
70 }
71}