跳到主要内容

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

浏览文件

file_poll_test.go

60 行 · 1.9 KB历史下载
1package workbench
2
3import (
4 "encoding/json"
5 "net/http"
6 "os/exec"
7 "strings"
8 "testing"
9)
10
11func TestDesktopFileRequestsReportTransportFailureAsUnavailable(t *testing.T) {
12 if _, err := exec.LookPath(sshExecutable()); err != nil {
13 t.Skip("SSH unavailable")
14 }
15 s := testServer(t)
16 s.ready = true
17 // This isolated profile has no SSH config. The shipped SSH entry fails
18 // locally, without connecting to any running VM or host service.
19 w := request(s, "GET", "/api/input/files/desktop/requests", "", "", true)
20 if w.Code != http.StatusServiceUnavailable {
21 t.Fatalf("transport failure became bad user input: %d %s", w.Code, w.Body.String())
22 }
23}
24
25func TestDesktopFilePollDistinguishesUnopenedAndBrokenDesktop(t *testing.T) {
26 bash, err := exec.LookPath("bash")
27 if err != nil {
28 t.Skip("bash unavailable")
29 }
30 fixture := `systemctl() {
31 printf '%s\n' "$DESKTOP_STATE"
32 [ "$DESKTOP_STATE" = active ]
33}
34`
35 for _, state := range []string{"inactive", "activating", "active", "failed", ""} {
36 t.Run(state, func(t *testing.T) {
37 // The final command stands for contacting the broker. It must only
38 // run for an active service; a failed service cannot become empty success.
39 script := "DESKTOP_STATE='" + state + "'\n" + fixture + desktopFilesPoll + "printf broker-contacted"
40 cmd := exec.Command(bash, "--noprofile", "--norc", "-s")
41 cmd.Stdin = strings.NewReader(script)
42 out, err := cmd.CombinedOutput()
43 switch state {
44 case "inactive", "activating":
45 var result map[string]any
46 if err != nil || json.Unmarshal(out, &result) != nil || result["available"] != false {
47 t.Fatalf("unopened desktop became error: %s %v", out, err)
48 }
49 case "active":
50 if err != nil || string(out) != "broker-contacted" {
51 t.Fatalf("live broker not polled: %s %v", out, err)
52 }
53 default:
54 if err == nil || strings.Contains(string(out), "broker-contacted") {
55 t.Fatalf("broken service hidden: %s %v", out, err)
56 }
57 }
58 })
59 }
60}