跳到主要内容

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

浏览文件

runscript_test.go

58 行 · 1.7 KB历史下载
1package runscript
2
3import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "strings"
8 "testing"
9
10 "github.com/sylvinus/agent-vm/internal/paths"
11)
12
13func TestProjectPath(t *testing.T) {
14 // Both spellings, on every host: backslashes never reach here, the
15 // callers pass the project dir Host-spelled.
16 for _, win := range []bool{false, true} {
17 old := paths.Windows
18 paths.Windows = func() bool { return win }
19 dir := "/p"
20 if win {
21 dir = "C:/p"
22 }
23 for v, want := range map[string]string{
24 "": dir + "/.agent-vm.runtime.sh",
25 ".mytool/run.sh": dir + "/.mytool/run.sh",
26 "/etc/mytool/r.sh": "/etc/mytool/r.sh",
27 } {
28 t.Setenv("AGENT_VM_PROJECT_RUNTIME", v)
29 if got := ProjectPath(dir); got != want {
30 t.Errorf("windows=%v %q: %q, want %q", win, v, got, want)
31 }
32 }
33 paths.Windows = old
34 }
35}
36
37// The same answers as the awk program the VM runs.
38func TestInterpreterAWK(t *testing.T) {
39 if _, err := exec.LookPath("awk"); err != nil {
40 t.Skip("no awk")
41 }
42 for _, c := range []string{
43 "", "echo hi\n", "#!/bin/bash\n", "#!/bin/bash -e\n", "#!/bin/sh\r\n", "#!/usr/bin/env bash\n",
44 "#!/usr/bin/env -S bash -e\n", "#!/usr/bin/env FOO=1 sh\n", "#!/usr/bin/env\n", "#!env -i\n", "#!\n",
45 "#! /bin/bash\n", "#!/usr/bin/python3\n", "#!/bin/zsh\n", "#!/bin/bash", "#!/opt/x/env\n", "#!\tsh\n",
46 "#!/usr/bin/env -S\n", "#!/bin/dash\n", " #!/bin/bash\n",
47 } {
48 f := filepath.Join(t.TempDir(), "s")
49 os.WriteFile(f, []byte(c), 0o644)
50 out, err := exec.Command("awk", ShebangAWK, f).Output()
51 if err != nil {
52 t.Fatal(err)
53 }
54 if got := Interpreter(c); got != strings.TrimSuffix(string(out), "\n") {
55 t.Errorf("Interpreter(%q) = %q, awk %q", c, got, out)
56 }
57 }
58}