chatccc 0.2.196 → 0.2.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/agent-prompts/cursor_specific.md +13 -13
  2. package/bin/cccagent.mjs +17 -17
  3. package/config.sample.json +27 -27
  4. package/package.json +1 -1
  5. package/src/__tests__/agent-reload-config-rpc.test.ts +99 -0
  6. package/src/__tests__/builtin-chat-session.test.ts +277 -181
  7. package/src/__tests__/builtin-cli-json.test.ts +39 -39
  8. package/src/__tests__/builtin-config.test.ts +33 -33
  9. package/src/__tests__/builtin-context.test.ts +163 -163
  10. package/src/__tests__/builtin-file-tools.test.ts +224 -196
  11. package/src/__tests__/builtin-session-select.test.ts +116 -116
  12. package/src/__tests__/builtin-sigint.test.ts +56 -56
  13. package/src/__tests__/cards.test.ts +109 -109
  14. package/src/__tests__/ccc-adapter.test.ts +114 -113
  15. package/src/__tests__/chatgpt-subscription-rpc.test.ts +89 -89
  16. package/src/__tests__/chatgpt-subscription.test.ts +135 -135
  17. package/src/__tests__/chrome-devtools-guard.test.ts +165 -165
  18. package/src/__tests__/claude-raw-stream-log.test.ts +87 -0
  19. package/src/__tests__/codex-raw-stream-log.test.ts +120 -0
  20. package/src/__tests__/config-reload.test.ts +10 -10
  21. package/src/__tests__/config-sample.test.ts +18 -18
  22. package/src/__tests__/cursor-adapter.test.ts +113 -113
  23. package/src/__tests__/feishu-avatar.test.ts +40 -40
  24. package/src/__tests__/orchestrator.test.ts +181 -154
  25. package/src/__tests__/raw-stream-log.test.ts +106 -106
  26. package/src/__tests__/session.test.ts +40 -40
  27. package/src/__tests__/sim-platform.test.ts +12 -12
  28. package/src/__tests__/web-ui.test.ts +209 -209
  29. package/src/adapters/ccc-adapter.ts +121 -119
  30. package/src/adapters/claude-adapter.ts +603 -566
  31. package/src/adapters/codex-adapter.ts +57 -32
  32. package/src/adapters/cursor-adapter.ts +264 -264
  33. package/src/adapters/raw-stream-log.ts +124 -124
  34. package/src/agent-reload-config-rpc.ts +34 -0
  35. package/src/builtin/cli.ts +473 -461
  36. package/src/builtin/context.ts +323 -323
  37. package/src/builtin/file-tools.ts +1072 -915
  38. package/src/builtin/index.ts +404 -353
  39. package/src/builtin/session-select.ts +48 -48
  40. package/src/builtin/sigint.ts +50 -50
  41. package/src/cards.ts +195 -195
  42. package/src/chatgpt-subscription-rpc.ts +27 -27
  43. package/src/chatgpt-subscription.ts +299 -299
  44. package/src/chrome-devtools-guard.ts +318 -318
  45. package/src/config.ts +125 -125
  46. package/src/feishu-api.ts +49 -49
  47. package/src/index.ts +8 -13
  48. package/src/orchestrator.ts +166 -145
  49. package/src/runtime-reload.ts +34 -0
  50. package/src/session.ts +141 -141
  51. package/src/web-ui.ts +205 -205
@@ -91,12 +91,12 @@ import {
91
91
  stopSession,
92
92
  startUnifiedDisplayLoop,
93
93
  stopUnifiedDisplayLoop,
94
- _setProcessAliveForTest,
95
- _resetProcessAliveForTest,
96
- _setProcessMonitorIntervalForTest,
97
- _resetProcessMonitorIntervalForTest,
98
- setSessionEffortOverride,
99
- } from "../session.ts";
94
+ _setProcessAliveForTest,
95
+ _resetProcessAliveForTest,
96
+ _setProcessMonitorIntervalForTest,
97
+ _resetProcessMonitorIntervalForTest,
98
+ setSessionEffortOverride,
99
+ } from "../session.ts";
100
100
  import {
101
101
  activePrompts,
102
102
  bindChatToSession,
@@ -896,17 +896,17 @@ describe("getSessionStatus", () => {
896
896
  expect(status!.effort).not.toBeNull();
897
897
  // model 必为字符串(留空时显示 '(留空)',否则为环境变量值);不应是占位符
898
898
  expect(typeof status!.model).toBe("string");
899
- expect(status!.model.length).toBeGreaterThan(0);
900
- });
901
-
902
- it("Codex session status uses the per-session effort override", async () => {
903
- mockSessionInfo("chat-codex", { sessionId: "sid-codex-effort", tool: "codex" });
904
- setSessionEffortOverride("sid-codex-effort", "xhigh");
905
-
906
- const status = await getSessionStatus("chat-codex");
907
-
908
- expect(status!.effort).toBe("xhigh");
909
- });
899
+ expect(status!.model.length).toBeGreaterThan(0);
900
+ });
901
+
902
+ it("Codex session status uses the per-session effort override", async () => {
903
+ mockSessionInfo("chat-codex", { sessionId: "sid-codex-effort", tool: "codex" });
904
+ setSessionEffortOverride("sid-codex-effort", "xhigh");
905
+
906
+ const status = await getSessionStatus("chat-codex");
907
+
908
+ expect(status!.effort).toBe("xhigh");
909
+ });
910
910
 
911
911
  it("Cursor 会话:effort 恒为 null(卡片渲染时隐藏该行,避免显示无意义的 effort)", async () => {
912
912
  mockSessionInfo("chat-cursor", { sessionId: "sid-cur", tool: "cursor" });
@@ -942,29 +942,29 @@ describe("getSessionStatus", () => {
942
942
  expect(status!.model).toBe(UNKNOWN_MODEL_PLACEHOLDER);
943
943
  });
944
944
 
945
- it("Cursor 会话:adapter.getSessionInfo 抛错时降级为占位符(不阻塞 /state)", async () => {
946
- mockSessionInfo("chat-cursor", { sessionId: "sid-cur", tool: "cursor" });
947
- _setAdapterForToolForTest(
948
- "cursor",
949
- mockAdapter(() => {
950
- throw new Error("simulated adapter failure");
951
- }),
952
- );
953
- const status = await getSessionStatus("chat-cursor");
954
- expect(status!.model).toBe(UNKNOWN_MODEL_PLACEHOLDER);
955
- expect(status!.effort).toBeNull();
956
- });
957
-
958
- it("CCC Agent 会话:model 来自 ccc 配置且 effort 恒为 null", async () => {
959
- mockSessionInfo("chat-ccc", { sessionId: "session-ccc", tool: "ccc" });
960
-
961
- const status = await getSessionStatus("chat-ccc");
962
-
963
- expect(status!.model).toBeTruthy();
964
- expect(status!.model).not.toBe(UNKNOWN_MODEL_PLACEHOLDER);
965
- expect(status!.effort).toBeNull();
966
- });
967
- });
945
+ it("Cursor 会话:adapter.getSessionInfo 抛错时降级为占位符(不阻塞 /state)", async () => {
946
+ mockSessionInfo("chat-cursor", { sessionId: "sid-cur", tool: "cursor" });
947
+ _setAdapterForToolForTest(
948
+ "cursor",
949
+ mockAdapter(() => {
950
+ throw new Error("simulated adapter failure");
951
+ }),
952
+ );
953
+ const status = await getSessionStatus("chat-cursor");
954
+ expect(status!.model).toBe(UNKNOWN_MODEL_PLACEHOLDER);
955
+ expect(status!.effort).toBeNull();
956
+ });
957
+
958
+ it("CCC Agent 会话:model 来自 ccc 配置且 effort 恒为 null", async () => {
959
+ mockSessionInfo("chat-ccc", { sessionId: "session-ccc", tool: "ccc" });
960
+
961
+ const status = await getSessionStatus("chat-ccc");
962
+
963
+ expect(status!.model).toBeTruthy();
964
+ expect(status!.model).not.toBe(UNKNOWN_MODEL_PLACEHOLDER);
965
+ expect(status!.effort).toBeNull();
966
+ });
967
+ });
968
968
 
969
969
  describe("getAllSessionsStatus", () => {
970
970
  let registryFile = "";
@@ -62,21 +62,21 @@ describe("SimulatedPlatform", () => {
62
62
  await expect(SimulatedPlatform.setChatAvatar("t", "ch1", "claude", "busy")).resolves.toBeUndefined();
63
63
  });
64
64
 
65
- it("纯函数 extractSessionInfo 正常工作", () => {
66
- const result = SimulatedPlatform.extractSessionInfo("Claude Code Session: a1b2c3d4-e5f6-7890-abcd-ef1234567890");
67
- expect(result).toEqual({ sessionId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", tool: "claude" });
68
- });
69
-
70
- it("pure extractSessionInfo recognizes ccc session ids", () => {
71
- const result = SimulatedPlatform.extractSessionInfo("CCC Session: session-20260702-121530-a1b2c3");
72
- expect(result).toEqual({ sessionId: "session-20260702-121530-a1b2c3", tool: "ccc" });
73
- });
74
-
75
- it("纯函数 formatDelayNotice 正常工作", () => {
65
+ it("纯函数 extractSessionInfo 正常工作", () => {
66
+ const result = SimulatedPlatform.extractSessionInfo("Claude Code Session: a1b2c3d4-e5f6-7890-abcd-ef1234567890");
67
+ expect(result).toEqual({ sessionId: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", tool: "claude" });
68
+ });
69
+
70
+ it("pure extractSessionInfo recognizes ccc session ids", () => {
71
+ const result = SimulatedPlatform.extractSessionInfo("CCC Session: session-20260702-121530-a1b2c3");
72
+ expect(result).toEqual({ sessionId: "session-20260702-121530-a1b2c3", tool: "ccc" });
73
+ });
74
+
75
+ it("纯函数 formatDelayNotice 正常工作", () => {
76
76
  const notice = SimulatedPlatform.formatDelayNotice(Date.now() - 20 * 60 * 1000, "测试消息");
77
77
  expect(notice).toBeDefined();
78
78
  expect(notice).toContain("延迟送达");
79
79
  // 近期消息不触发
80
80
  expect(SimulatedPlatform.formatDelayNotice(Date.now(), "test")).toBeNull();
81
81
  });
82
- });
82
+ });
@@ -1,209 +1,209 @@
1
- import { describe, it, expect } from "vitest";
2
- import {
3
- PAGE_HTML,
4
- chooseStartPath,
5
- getRestartRequiredReasons,
6
- unflattenConfig,
7
- } from "../web-ui.ts";
8
-
9
- describe("unflattenConfig", () => {
10
- it("maps Claude subagent model into claude.subagentModel", () => {
11
- expect(
12
- unflattenConfig({
13
- CHATCCC_ANTHROPIC_MODEL: "claude-sonnet-4-6",
14
- CHATCCC_ANTHROPIC_SUBAGENT_MODEL: "claude-haiku-4-5-20251001",
15
- }),
16
- ).toEqual({
17
- claude: {
18
- model: "claude-sonnet-4-6",
19
- subagentModel: "claude-haiku-4-5-20251001",
20
- },
21
- });
22
- });
23
-
24
- it("maps Claude apiKey and baseUrl into claude config", () => {
25
- expect(
26
- unflattenConfig({
27
- CHATCCC_ANTHROPIC_API_KEY: "sk-test-key",
28
- CHATCCC_ANTHROPIC_BASE_URL: "https://api.example.com",
29
- }),
30
- ).toEqual({
31
- claude: {
32
- apiKey: "sk-test-key",
33
- baseUrl: "https://api.example.com",
34
- },
35
- });
36
- });
37
-
38
- it("maps Cursor and Codex alternative models into agent config", () => {
39
- expect(
40
- unflattenConfig({
41
- CHATCCC_CURSOR_ALTERNATIVE_MODEL: "gpt-5.5-high",
42
- CHATCCC_CODEX_ALTERNATIVE_MODEL: "gpt-5.3-codex",
43
- }),
44
- ).toEqual({
45
- cursor: {
46
- alternativeModel: "gpt-5.5-high",
47
- },
48
- codex: {
49
- alternativeModel: "gpt-5.3-codex",
50
- },
51
- });
52
- });
53
-
54
- it("maps Chrome CDP guard fields into chromeDevtools config", () => {
55
- expect(
56
- unflattenConfig({
57
- CHATCCC_CHROME_DEVTOOLS_ENABLED: true,
58
- CHATCCC_CHROME_DEVTOOLS_PORT: "15166",
59
- CHATCCC_CHROME_DEVTOOLS_PATH: "C:/Program Files/Google/Chrome/Application/chrome.exe",
60
- }),
61
- ).toEqual({
62
- chromeDevtools: {
63
- enabled: true,
64
- port: 15166,
65
- chromePath: "C:/Program Files/Google/Chrome/Application/chrome.exe",
66
- },
67
- });
68
- });
69
- });
70
-
71
- describe("getRestartRequiredReasons", () => {
72
- const baseConfig = {
73
- feishu: { appId: "cli_old", appSecret: "secret_old" },
74
- platforms: {
75
- feishu: { enabled: true, platformType: "feishu" },
76
- ilink: { enabled: true, reuseTokenOnStart: true },
77
- },
78
- chromeDevtools: { enabled: false, port: 15166, chromePath: "" },
79
- port: 18080,
80
- claude: {
81
- enabled: true,
82
- defaultAgent: true,
83
- model: "",
84
- subagentModel: "",
85
- effort: "",
86
- apiKey: "",
87
- baseUrl: "",
88
- maxTurn: 0,
89
- },
90
- cursor: {
91
- enabled: true,
92
- defaultAgent: false,
93
- path: "",
94
- model: "",
95
- alternativeModel: "",
96
- avatarBatteryMode: "apiPercent",
97
- onDemandMonthlyBudget: 1000,
98
- },
99
- codex: {
100
- enabled: true,
101
- defaultAgent: false,
102
- path: "",
103
- model: "",
104
- alternativeModel: "",
105
- effort: "",
106
- },
107
- };
108
-
109
- it("does not require restart for agent and Chrome runtime settings", () => {
110
- expect(
111
- getRestartRequiredReasons(baseConfig, {
112
- ...baseConfig,
113
- chromeDevtools: { enabled: true, port: 15167, chromePath: "C:/Chrome/chrome.exe" },
114
- claude: { ...baseConfig.claude, model: "claude-sonnet", apiKey: "sk-test", maxTurn: 8 },
115
- cursor: { ...baseConfig.cursor, path: "C:/cursor-agent.cmd", model: "cursor-model" },
116
- codex: { ...baseConfig.codex, path: "C:/codex.cmd", model: "gpt-5.3-codex", effort: "high" },
117
- }),
118
- ).toEqual([]);
119
- });
120
-
121
- it("requires restart for port, Feishu credentials, platform type, and platform lifecycle", () => {
122
- expect(
123
- getRestartRequiredReasons(baseConfig, {
124
- ...baseConfig,
125
- feishu: { appId: "cli_new", appSecret: "secret_new" },
126
- platforms: {
127
- feishu: { enabled: false, platformType: "lark" },
128
- ilink: { enabled: false, reuseTokenOnStart: false },
129
- },
130
- port: 18081,
131
- }),
132
- ).toEqual([
133
- "port",
134
- "feishu.appId",
135
- "feishu.appSecret",
136
- "platforms.feishu.platformType",
137
- "platforms.feishu.enabled",
138
- "platforms.ilink.enabled",
139
- "platforms.ilink.reuseTokenOnStart",
140
- ]);
141
- });
142
- });
143
-
144
- describe("dashboard edit modal", () => {
145
- it("shows the edit modal and overlay when a section edit button is clicked", () => {
146
- expect(PAGE_HTML).toContain("function editSection(section)");
147
- expect(PAGE_HTML).toContain("document.getElementById('edit-modal').classList.remove('hidden');");
148
- expect(PAGE_HTML).toContain("document.getElementById('edit-overlay').classList.remove('hidden');");
149
- });
150
-
151
- it("uses plain alternative model labels for Cursor and Codex", () => {
152
- expect(PAGE_HTML).toContain("field-CHATCCC_CURSOR_ALTERNATIVE_MODEL");
153
- expect(PAGE_HTML).toContain("field-CHATCCC_CODEX_ALTERNATIVE_MODEL");
154
- expect(PAGE_HTML).toContain("备选模型");
155
- });
156
-
157
- it("shows config effect scope hints", () => {
158
- expect(PAGE_HTML).toContain("生效范围:保存后下一条消息或下个新会话生效");
159
- expect(PAGE_HTML).toContain("生效范围:飞书开关、App ID、App Secret 或平台类型变更需要重启 ChatCCC");
160
- });
161
- });
162
-
163
- // ---------------------------------------------------------------------------
164
- // chooseStartPath — /api/start 的路径选择
165
- // 关键护栏:
166
- // - setup 模式(hasInplaceActivateHook=true)下 isServiceRunning 永远为 true
167
- // (setup 进程自己占着 PID 文件),必须无条件走 inplace;否则用户点
168
- // "保存并启动"将永远拿到 "Service is already running"。
169
- // - dashboard 模式 + service 已运行(通常就是当前进程自己)→ "reload":
170
- // 用户点"保存并启动"想让新 config 生效,但服务正在跑——不真重启,仅
171
- // 调用 reloadConfigFromDisk() 刷新进程内 export let 常量。绝不能再
172
- // 返回"already running"挡用户路。
173
- // - dashboard 模式 + service 未运行 → spawn 一个新的(旧 service 退出后场景)。
174
- // ---------------------------------------------------------------------------
175
-
176
- describe("chooseStartPath", () => {
177
- it("setup 模式(注入 inplace hook)→ inplace(不管 PID 文件状态)", () => {
178
- expect(
179
- chooseStartPath({
180
- hasInplaceActivateHook: true,
181
- isServiceRunning: true,
182
- }),
183
- ).toBe("inplace");
184
- expect(
185
- chooseStartPath({
186
- hasInplaceActivateHook: true,
187
- isServiceRunning: false,
188
- }),
189
- ).toBe("inplace");
190
- });
191
-
192
- it("dashboard 模式 + service 已运行 → reload(仅刷新 config,不真重启)", () => {
193
- expect(
194
- chooseStartPath({
195
- hasInplaceActivateHook: false,
196
- isServiceRunning: true,
197
- }),
198
- ).toBe("reload");
199
- });
200
-
201
- it("dashboard 模式 + service 未运行 → spawn", () => {
202
- expect(
203
- chooseStartPath({
204
- hasInplaceActivateHook: false,
205
- isServiceRunning: false,
206
- }),
207
- ).toBe("spawn");
208
- });
209
- });
1
+ import { describe, it, expect } from "vitest";
2
+ import {
3
+ PAGE_HTML,
4
+ chooseStartPath,
5
+ getRestartRequiredReasons,
6
+ unflattenConfig,
7
+ } from "../web-ui.ts";
8
+
9
+ describe("unflattenConfig", () => {
10
+ it("maps Claude subagent model into claude.subagentModel", () => {
11
+ expect(
12
+ unflattenConfig({
13
+ CHATCCC_ANTHROPIC_MODEL: "claude-sonnet-4-6",
14
+ CHATCCC_ANTHROPIC_SUBAGENT_MODEL: "claude-haiku-4-5-20251001",
15
+ }),
16
+ ).toEqual({
17
+ claude: {
18
+ model: "claude-sonnet-4-6",
19
+ subagentModel: "claude-haiku-4-5-20251001",
20
+ },
21
+ });
22
+ });
23
+
24
+ it("maps Claude apiKey and baseUrl into claude config", () => {
25
+ expect(
26
+ unflattenConfig({
27
+ CHATCCC_ANTHROPIC_API_KEY: "sk-test-key",
28
+ CHATCCC_ANTHROPIC_BASE_URL: "https://api.example.com",
29
+ }),
30
+ ).toEqual({
31
+ claude: {
32
+ apiKey: "sk-test-key",
33
+ baseUrl: "https://api.example.com",
34
+ },
35
+ });
36
+ });
37
+
38
+ it("maps Cursor and Codex alternative models into agent config", () => {
39
+ expect(
40
+ unflattenConfig({
41
+ CHATCCC_CURSOR_ALTERNATIVE_MODEL: "gpt-5.5-high",
42
+ CHATCCC_CODEX_ALTERNATIVE_MODEL: "gpt-5.3-codex",
43
+ }),
44
+ ).toEqual({
45
+ cursor: {
46
+ alternativeModel: "gpt-5.5-high",
47
+ },
48
+ codex: {
49
+ alternativeModel: "gpt-5.3-codex",
50
+ },
51
+ });
52
+ });
53
+
54
+ it("maps Chrome CDP guard fields into chromeDevtools config", () => {
55
+ expect(
56
+ unflattenConfig({
57
+ CHATCCC_CHROME_DEVTOOLS_ENABLED: true,
58
+ CHATCCC_CHROME_DEVTOOLS_PORT: "15166",
59
+ CHATCCC_CHROME_DEVTOOLS_PATH: "C:/Program Files/Google/Chrome/Application/chrome.exe",
60
+ }),
61
+ ).toEqual({
62
+ chromeDevtools: {
63
+ enabled: true,
64
+ port: 15166,
65
+ chromePath: "C:/Program Files/Google/Chrome/Application/chrome.exe",
66
+ },
67
+ });
68
+ });
69
+ });
70
+
71
+ describe("getRestartRequiredReasons", () => {
72
+ const baseConfig = {
73
+ feishu: { appId: "cli_old", appSecret: "secret_old" },
74
+ platforms: {
75
+ feishu: { enabled: true, platformType: "feishu" },
76
+ ilink: { enabled: true, reuseTokenOnStart: true },
77
+ },
78
+ chromeDevtools: { enabled: false, port: 15166, chromePath: "" },
79
+ port: 18080,
80
+ claude: {
81
+ enabled: true,
82
+ defaultAgent: true,
83
+ model: "",
84
+ subagentModel: "",
85
+ effort: "",
86
+ apiKey: "",
87
+ baseUrl: "",
88
+ maxTurn: 0,
89
+ },
90
+ cursor: {
91
+ enabled: true,
92
+ defaultAgent: false,
93
+ path: "",
94
+ model: "",
95
+ alternativeModel: "",
96
+ avatarBatteryMode: "apiPercent",
97
+ onDemandMonthlyBudget: 1000,
98
+ },
99
+ codex: {
100
+ enabled: true,
101
+ defaultAgent: false,
102
+ path: "",
103
+ model: "",
104
+ alternativeModel: "",
105
+ effort: "",
106
+ },
107
+ };
108
+
109
+ it("does not require restart for agent and Chrome runtime settings", () => {
110
+ expect(
111
+ getRestartRequiredReasons(baseConfig, {
112
+ ...baseConfig,
113
+ chromeDevtools: { enabled: true, port: 15167, chromePath: "C:/Chrome/chrome.exe" },
114
+ claude: { ...baseConfig.claude, model: "claude-sonnet", apiKey: "sk-test", maxTurn: 8 },
115
+ cursor: { ...baseConfig.cursor, path: "C:/cursor-agent.cmd", model: "cursor-model" },
116
+ codex: { ...baseConfig.codex, path: "C:/codex.cmd", model: "gpt-5.3-codex", effort: "high" },
117
+ }),
118
+ ).toEqual([]);
119
+ });
120
+
121
+ it("requires restart for port, Feishu credentials, platform type, and platform lifecycle", () => {
122
+ expect(
123
+ getRestartRequiredReasons(baseConfig, {
124
+ ...baseConfig,
125
+ feishu: { appId: "cli_new", appSecret: "secret_new" },
126
+ platforms: {
127
+ feishu: { enabled: false, platformType: "lark" },
128
+ ilink: { enabled: false, reuseTokenOnStart: false },
129
+ },
130
+ port: 18081,
131
+ }),
132
+ ).toEqual([
133
+ "port",
134
+ "feishu.appId",
135
+ "feishu.appSecret",
136
+ "platforms.feishu.platformType",
137
+ "platforms.feishu.enabled",
138
+ "platforms.ilink.enabled",
139
+ "platforms.ilink.reuseTokenOnStart",
140
+ ]);
141
+ });
142
+ });
143
+
144
+ describe("dashboard edit modal", () => {
145
+ it("shows the edit modal and overlay when a section edit button is clicked", () => {
146
+ expect(PAGE_HTML).toContain("function editSection(section)");
147
+ expect(PAGE_HTML).toContain("document.getElementById('edit-modal').classList.remove('hidden');");
148
+ expect(PAGE_HTML).toContain("document.getElementById('edit-overlay').classList.remove('hidden');");
149
+ });
150
+
151
+ it("uses plain alternative model labels for Cursor and Codex", () => {
152
+ expect(PAGE_HTML).toContain("field-CHATCCC_CURSOR_ALTERNATIVE_MODEL");
153
+ expect(PAGE_HTML).toContain("field-CHATCCC_CODEX_ALTERNATIVE_MODEL");
154
+ expect(PAGE_HTML).toContain("备选模型");
155
+ });
156
+
157
+ it("shows config effect scope hints", () => {
158
+ expect(PAGE_HTML).toContain("生效范围:保存后下一条消息或下个新会话生效");
159
+ expect(PAGE_HTML).toContain("生效范围:飞书开关、App ID、App Secret 或平台类型变更需要重启 ChatCCC");
160
+ });
161
+ });
162
+
163
+ // ---------------------------------------------------------------------------
164
+ // chooseStartPath — /api/start 的路径选择
165
+ // 关键护栏:
166
+ // - setup 模式(hasInplaceActivateHook=true)下 isServiceRunning 永远为 true
167
+ // (setup 进程自己占着 PID 文件),必须无条件走 inplace;否则用户点
168
+ // "保存并启动"将永远拿到 "Service is already running"。
169
+ // - dashboard 模式 + service 已运行(通常就是当前进程自己)→ "reload":
170
+ // 用户点"保存并启动"想让新 config 生效,但服务正在跑——不真重启,仅
171
+ // 调用 reloadConfigFromDisk() 刷新进程内 export let 常量。绝不能再
172
+ // 返回"already running"挡用户路。
173
+ // - dashboard 模式 + service 未运行 → spawn 一个新的(旧 service 退出后场景)。
174
+ // ---------------------------------------------------------------------------
175
+
176
+ describe("chooseStartPath", () => {
177
+ it("setup 模式(注入 inplace hook)→ inplace(不管 PID 文件状态)", () => {
178
+ expect(
179
+ chooseStartPath({
180
+ hasInplaceActivateHook: true,
181
+ isServiceRunning: true,
182
+ }),
183
+ ).toBe("inplace");
184
+ expect(
185
+ chooseStartPath({
186
+ hasInplaceActivateHook: true,
187
+ isServiceRunning: false,
188
+ }),
189
+ ).toBe("inplace");
190
+ });
191
+
192
+ it("dashboard 模式 + service 已运行 → reload(仅刷新 config,不真重启)", () => {
193
+ expect(
194
+ chooseStartPath({
195
+ hasInplaceActivateHook: false,
196
+ isServiceRunning: true,
197
+ }),
198
+ ).toBe("reload");
199
+ });
200
+
201
+ it("dashboard 模式 + service 未运行 → spawn", () => {
202
+ expect(
203
+ chooseStartPath({
204
+ hasInplaceActivateHook: false,
205
+ isServiceRunning: false,
206
+ }),
207
+ ).toBe("spawn");
208
+ });
209
+ });