跳到主要内容

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

浏览文件

session_summary_accounts_test.go

79 行 · 2.6 KB历史下载
1package workbench
2
3import (
4 "encoding/json"
5 "testing"
6
7 "github.com/google/uuid"
8)
9
10func TestSessionSummaryAccountAfterRestartAndSwitch(t *testing.T) {
11 profile, workspace := t.TempDir(), t.TempDir()
12 id := uuid.NewString()
13 // Older records store the binding in Account without an account_id in the summary.
14 record := &mobileRecord{
15 mobileSession: mobileSession{
16 mobileSummary: mobileSummary{ID: id, Workspace: workspace, Title: "对话"},
17 Turns: []mobileTurn{},
18 },
19 CLIID: uuid.NewString(), Account: claudeSelection{ID: "first-account"},
20 }
21 if err := writePrivate(mobileRecordPath(profile, id), record); err != nil {
22 t.Fatal(err)
23 }
24 store := &mobileCLIStore{}
25 granted := map[string]bool{workspace: true}
26 check := func(want string) {
27 t.Helper()
28 list, err := store.summaries(profile, granted, false)
29 if err != nil || len(list) != 1 {
30 t.Fatalf("summaries: %v, %v", list, err)
31 }
32 data, err := json.Marshal(list[0])
33 if err != nil {
34 t.Fatal(err)
35 }
36 var view map[string]any
37 if err := json.Unmarshal(data, &view); err != nil {
38 t.Fatal(err)
39 }
40 if view["account_id"] != want {
41 t.Fatalf("account_id = %v, want %s", view["account_id"], want)
42 }
43 }
44 check("first-account")
45 // A running conversation must report its current binding, rather than the cached one.
46 record.Account.ID = "second-account"
47 store.active = map[string]*mobileRun{id: {record: record}}
48 check("second-account")
49 if err := writePrivate(mobileRecordPath(profile, id), record); err != nil {
50 t.Fatal(err)
51 }
52 store = &mobileCLIStore{}
53 check("second-account")
54}
55
56func TestSessionSummaryRunningRequiresFreshProcessObservation(t *testing.T) {
57 profile, workspace, id := t.TempDir(), t.TempDir(), uuid.NewString()
58 record := &mobileRecord{mobileSession: mobileSession{mobileSummary: mobileSummary{
59 ID: id, Workspace: workspace, Running: true,
60 }, Turns: []mobileTurn{}}, Terminal: true, CLIID: uuid.NewString()}
61 if err := writePrivate(mobileRecordPath(profile, id), record); err != nil {
62 t.Fatal(err)
63 }
64 store := &mobileCLIStore{}
65 check := func(want bool) {
66 t.Helper()
67 list, err := store.summaries(profile, map[string]bool{workspace: true}, false)
68 if err != nil || len(list) != 1 || list[0].Running != want {
69 t.Fatalf("running = %v, want %v; error = %v", list, want, err)
70 }
71 }
72 check(false) // Persisted activity cannot disable a session after restart.
73 store.running = map[string]bool{id: true}
74 check(true) // An idle external process is running even without a busy turn.
75 store.active = map[string]*mobileRun{id: {record: record}}
76 check(true)
77 store.running = map[string]bool{}
78 check(false)
79}