跳到主要内容

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

浏览文件

guest_memory_container_test.go

30 行 · 968 B历史下载
1package cage
2
3import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "strings"
8 "testing"
9)
10
11func TestContainerMemorySetupNeverInvokesKernelOrSwapCommands(t *testing.T) {
12 bash, err := exec.LookPath("bash")
13 if err != nil {
14 t.Skip("bash is unavailable")
15 }
16 directory := t.TempDir()
17 // Every host-changing operation in this script requires sudo. A container
18 // detection must skip the entire block, including installation of services.
19 for name, body := range map[string]string{"systemd-detect-virt": "#!/bin/sh\nexit 0\n", "sudo": "#!/bin/sh\necho unexpected-host-operation >&2\nexit 91\n"} {
20 if err := os.WriteFile(filepath.Join(directory, name), []byte(body), 0700); err != nil {
21 t.Fatal(err)
22 }
23 }
24 cmd := exec.Command(bash, "-e", "-s")
25 cmd.Env = []string{"PATH=" + directory}
26 cmd.Stdin = strings.NewReader(guestMemory)
27 if output, err := cmd.CombinedOutput(); err != nil || len(output) > 0 {
28 t.Fatalf("container touched kernel setup: %v %s", err, output)
29 }
30}