跳到主要内容

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

浏览文件

disk_test.go

58 行 · 1.7 KB历史下载
1package host
2
3import (
4 "bytes"
5 "fmt"
6 "os"
7 "path/filepath"
8 "strings"
9 "testing"
10)
11
12// A VM folder not made yet uses its nearest existing parent.
13func TestWarnDiskSpace(t *testing.T) {
14 t.Setenv("HOME", t.TempDir())
15 missing := filepath.Join(t.TempDir(), "not", "yet")
16 var b bytes.Buffer
17 WarnDiskSpace(missing, 1<<30, &b)
18 if !strings.HasPrefix(b.String(), "Warning: ~") {
19 t.Errorf("no warning: %q", b.String())
20 }
21 b.Reset()
22 WarnDiskSpace(missing, 0, &b)
23 WarnDiskSpace(missing, 1, &b)
24 if b.Len() != 0 {
25 t.Errorf("warned: %q", b.String())
26 }
27}
28
29// Native QA passes a profile-side junction to a second volume with different
30// free space. The missing child models Lima's first launch before setup.
31func TestDiskSpaceBeforeVMDirectoryExists(t *testing.T) {
32 alias, target := os.Getenv("CAGE_TEST_DISK_SPACE_ALIAS"), os.Getenv("CAGE_TEST_DISK_SPACE_VOLUME")
33 if alias == "" || target == "" {
34 t.Skip("requires a test link to a second volume")
35 }
36 missing := filepath.Join(alias, "cage-disk-qa-absent", "lima")
37 if _, err := os.Stat(missing); !os.IsNotExist(err) {
38 t.Fatal("expected missing QA child", err)
39 }
40 want, ok := FreeGiB(target)
41 if !ok {
42 t.Fatal("cannot read physical volume")
43 }
44 got, ok := FreeGiB(missing)
45 if !ok || got != want {
46 t.Fatalf("logical free = %d, expected physical free = %d (ok=%v)", got, want, ok)
47 }
48 var warning bytes.Buffer
49 WarnDiskSpace(missing, want, &warning)
50 if warning.Len() != 0 {
51 t.Fatal("spurious low space warning", warning.String())
52 }
53 WarnDiskSpace(missing, want+1, &warning)
54 if !strings.Contains(warning.String(), fmt.Sprintf("~%d GiB free", want)) {
55 t.Fatalf("wrong preflight warning %q", warning.String())
56 }
57 t.Logf("first-run space check: %d GiB available on target", got)
58}