跳到主要内容

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

浏览文件

diagnostics_guest_test.go

60 行 · 2.3 KB历史下载
1package workbench
2
3import (
4 "encoding/json"
5 "fmt"
6 "os"
7 "os/exec"
8 "path/filepath"
9 "runtime"
10 "strings"
11 "testing"
12 "time"
13)
14
15func TestMacOSGuestDiagnosticCollectorBoundsAndFilters(t *testing.T) {
16 if runtime.GOOS == "windows" {
17 t.Skip("macOS guest collector requires POSIX directory descriptors and file ownership")
18 }
19 if _, err := exec.LookPath("uv"); err != nil {
20 t.Skip("uv is required for the guest collector")
21 }
22 home := t.TempDir()
23 directory := filepath.Join(home, "Library", "Logs", "Cage")
24 if err := os.MkdirAll(directory, 0700); err != nil {
25 t.Fatal(err)
26 }
27 var events strings.Builder
28 stamp := time.Now().UTC().Format(time.RFC3339)
29 for index := 0; index < 150; index++ {
30 fmt.Fprintf(&events, "{\"time\":%q,\"source\":\"window\",\"reason\":\"frame_unavailable\"}\n", stamp)
31 }
32 if err := os.WriteFile(filepath.Join(directory, "window-1.jsonl"), []byte(events.String()), 0600); err != nil {
33 t.Fatal(err)
34 }
35 events.Reset()
36 fmt.Fprintf(&events, "{\"time\":%q,\"source\":\"window\",\"reason\":\"after_rotation\"}\n", stamp)
37 fmt.Fprintln(&events, `{"time":"2020-01-01T00:00:00Z","source":"window","reason":"old_event"}`)
38 fmt.Fprintf(&events, "{\"time\":%q,\"source\":\"window\",\"reason\":\"password=private-secret\"}\n", time.Now().UTC().Format(time.RFC3339))
39 fmt.Fprintln(&events, "invalid JSON")
40 fmt.Fprintln(&events, `{"time":123,"source":"window","reason":"invalid_timestamp"}`)
41 if err := os.WriteFile(filepath.Join(directory, "window.jsonl"), []byte(events.String()), 0600); err != nil {
42 t.Fatal(err)
43 }
44 cmd := exec.Command("uv", "run", "--no-project", "python", "-I", "-c", macOSDiagnosticCollector)
45 cmd.Env = append(os.Environ(), "HOME="+home, "USERPROFILE="+home)
46 output, err := cmd.Output()
47 if err != nil {
48 t.Fatal(err)
49 }
50 var result struct {
51 Version int `json:"version"`
52 Lines string `json:"lines"`
53 }
54 if json.Unmarshal(output, &result) != nil || result.Version != 1 || strings.Count(result.Lines, "\n") != 150 || len(result.Lines) > 48<<10 || strings.Contains(result.Lines, "private-secret") || strings.Contains(result.Lines, "old_event") {
55 t.Fatalf("guest diagnostics escaped the bounded fixed schema: %s", output)
56 }
57 if !strings.Contains(result.Lines, "after_rotation") {
58 t.Fatal("missing newest event from current file after same-second rotation")
59 }
60}