chatccc 0.2.250 → 0.2.252
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.
- package/deepccc-agent/os-prompts/darwin.md +8 -8
- package/deepccc-agent/os-prompts/linux.md +8 -8
- package/deepccc-agent/os-prompts/win32.md +11 -11
- package/deepccc-agent/package-lock.json +2027 -2027
- package/deepccc-agent/package.json +65 -65
- package/deepccc-agent/src/__tests__/chat-session.test.ts +877 -852
- package/deepccc-agent/src/__tests__/context.test.ts +341 -341
- package/deepccc-agent/src/__tests__/skills.test.ts +284 -284
- package/deepccc-agent/src/context.ts +465 -465
- package/deepccc-agent/src/file-tools.ts +38 -38
- package/deepccc-agent/src/index.ts +72 -37
- package/deepccc-agent/src/skills.ts +205 -205
- package/package.json +74 -74
- package/src/__tests__/builtin-chat-session.test.ts +532 -532
- package/src/__tests__/builtin-context.test.ts +319 -319
- package/src/__tests__/builtin-skills.test.ts +284 -284
- package/src/__tests__/config-utils.test.ts +40 -40
- package/src/__tests__/session-ccc-config.test.ts +66 -66
- package/src/__tests__/web-ui.test.ts +438 -438
|
@@ -1,438 +1,438 @@
|
|
|
1
|
-
import { createServer } from "node:http";
|
|
2
|
-
import type { AddressInfo } from "node:net";
|
|
3
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
4
|
-
|
|
5
|
-
// 关键:mock installer 模块,避免 /api/claude-sdk/install 触发真实 npm 下载(220MB)
|
|
6
|
-
const installClaudeSdkMock = vi.hoisted(() => vi.fn());
|
|
7
|
-
vi.mock("../claude-sdk-installer.ts", () => ({
|
|
8
|
-
getClaudeSdkInstalledVersion: () => null,
|
|
9
|
-
getLastInstallProgress: () => ({ phase: "idle", percent: 0, message: "" }),
|
|
10
|
-
installClaudeSdk: installClaudeSdkMock,
|
|
11
|
-
isClaudeSdkInstalled: () => false,
|
|
12
|
-
isInstallRunning: () => false,
|
|
13
|
-
}));
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
AGENT_TEAM_PAGE_HTML,
|
|
17
|
-
PAGE_HTML,
|
|
18
|
-
chooseStartPath,
|
|
19
|
-
createUiRouter,
|
|
20
|
-
getRestartRequiredReasons,
|
|
21
|
-
unflattenConfig,
|
|
22
|
-
} from "../web-ui.ts";
|
|
23
|
-
|
|
24
|
-
describe("Agent Team page", () => {
|
|
25
|
-
it("adds a prominent global entry to the ChatCCC page", () => {
|
|
26
|
-
expect(PAGE_HTML).toContain('href="/agent-team"');
|
|
27
|
-
expect(PAGE_HTML).toContain('class="agent-team-entry"');
|
|
28
|
-
expect(PAGE_HTML).toContain("Agent Team");
|
|
29
|
-
expect(PAGE_HTML).toContain("linear-gradient");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("contains only the Agent Team title as page content", () => {
|
|
33
|
-
expect(AGENT_TEAM_PAGE_HTML).toContain("<title>Agent Team</title>");
|
|
34
|
-
expect(AGENT_TEAM_PAGE_HTML).toContain("<h1>Agent Team</h1>");
|
|
35
|
-
expect(AGENT_TEAM_PAGE_HTML).not.toContain("dashboard-view");
|
|
36
|
-
expect(AGENT_TEAM_PAGE_HTML).not.toContain("wizard-view");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("serves the Agent Team page from its own route", async () => {
|
|
40
|
-
const server = createServer(createUiRouter());
|
|
41
|
-
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
42
|
-
const port = (server.address() as AddressInfo).port;
|
|
43
|
-
try {
|
|
44
|
-
const response = await fetch(`http://127.0.0.1:${port}/agent-team`);
|
|
45
|
-
expect(response.status).toBe(200);
|
|
46
|
-
expect(await response.text()).toBe(AGENT_TEAM_PAGE_HTML);
|
|
47
|
-
} finally {
|
|
48
|
-
await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("unflattenConfig", () => {
|
|
54
|
-
it("maps Claude subagent model into claude.subagentModel", () => {
|
|
55
|
-
expect(
|
|
56
|
-
unflattenConfig({
|
|
57
|
-
CHATCCC_ANTHROPIC_MODEL: "claude-sonnet-4-6",
|
|
58
|
-
CHATCCC_ANTHROPIC_SUBAGENT_MODEL: "claude-haiku-4-5-20251001",
|
|
59
|
-
}),
|
|
60
|
-
).toEqual({
|
|
61
|
-
claude: {
|
|
62
|
-
model: "claude-sonnet-4-6",
|
|
63
|
-
subagentModel: "claude-haiku-4-5-20251001",
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("maps Claude apiKey and baseUrl into claude config", () => {
|
|
69
|
-
expect(
|
|
70
|
-
unflattenConfig({
|
|
71
|
-
CHATCCC_ANTHROPIC_API_KEY: "sk-test-key",
|
|
72
|
-
CHATCCC_ANTHROPIC_BASE_URL: "https://api.example.com",
|
|
73
|
-
}),
|
|
74
|
-
).toEqual({
|
|
75
|
-
claude: {
|
|
76
|
-
apiKey: "sk-test-key",
|
|
77
|
-
baseUrl: "https://api.example.com",
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("maps Cursor and Codex runtime settings into agent config", () => {
|
|
83
|
-
expect(
|
|
84
|
-
unflattenConfig({
|
|
85
|
-
CHATCCC_CURSOR_ALTERNATIVE_MODEL: "gpt-5.5-high",
|
|
86
|
-
CHATCCC_CODEX_ALTERNATIVE_MODEL: "gpt-5.3-codex",
|
|
87
|
-
CHATCCC_CODEX_FAST_MODE: true,
|
|
88
|
-
}),
|
|
89
|
-
).toEqual({
|
|
90
|
-
cursor: {
|
|
91
|
-
alternativeModel: "gpt-5.5-high",
|
|
92
|
-
},
|
|
93
|
-
codex: {
|
|
94
|
-
alternativeModel: "gpt-5.3-codex",
|
|
95
|
-
fastMode: true,
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("maps CCC Agent settings into ccc config", () => {
|
|
101
|
-
expect(
|
|
102
|
-
unflattenConfig({
|
|
103
|
-
CHATCCC_CCC_ENABLED: true,
|
|
104
|
-
CHATCCC_CCC_DEFAULT_AGENT: true,
|
|
105
|
-
CHATCCC_CCC_API_KEY: "sk-test-ccc",
|
|
106
|
-
CHATCCC_CCC_BASE_URL: "https://api.deepseek.com/v1",
|
|
107
|
-
CHATCCC_CCC_MODEL: "deepseek-v4-flash",
|
|
108
|
-
CHATCCC_CCC_ALTERNATIVE_MODEL: "deepseek-v4-pro",
|
|
109
|
-
CHATCCC_CCC_EFFORT: "max",
|
|
110
|
-
CHATCCC_CCC_PROVIDER: "anthropic",
|
|
111
|
-
}),
|
|
112
|
-
).toEqual({
|
|
113
|
-
ccc: {
|
|
114
|
-
enabled: true,
|
|
115
|
-
defaultAgent: true,
|
|
116
|
-
DEEPSEEK_API_KEY: "sk-test-ccc",
|
|
117
|
-
DEEPSEEK_BASE_URL: "https://api.deepseek.com/v1",
|
|
118
|
-
model: "deepseek-v4-flash",
|
|
119
|
-
alternativeModel: "deepseek-v4-pro",
|
|
120
|
-
effort: "max",
|
|
121
|
-
provider: "anthropic",
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("maps Chrome CDP guard fields into chromeDevtools config", () => {
|
|
127
|
-
expect(
|
|
128
|
-
unflattenConfig({
|
|
129
|
-
CHATCCC_CHROME_DEVTOOLS_ENABLED: true,
|
|
130
|
-
CHATCCC_CHROME_DEVTOOLS_PORT: "15166",
|
|
131
|
-
CHATCCC_CHROME_DEVTOOLS_PATH: "C:/Program Files/Google/Chrome/Application/chrome.exe",
|
|
132
|
-
}),
|
|
133
|
-
).toEqual({
|
|
134
|
-
chromeDevtools: {
|
|
135
|
-
enabled: true,
|
|
136
|
-
port: 15166,
|
|
137
|
-
chromePath: "C:/Program Files/Google/Chrome/Application/chrome.exe",
|
|
138
|
-
},
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("maps the Web UI startup preference into webUi config", () => {
|
|
143
|
-
expect(
|
|
144
|
-
unflattenConfig({
|
|
145
|
-
CHATCCC_WEB_UI_OPEN_ON_START: false,
|
|
146
|
-
}),
|
|
147
|
-
).toEqual({
|
|
148
|
-
webUi: {
|
|
149
|
-
openOnStart: false,
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe("getRestartRequiredReasons", () => {
|
|
156
|
-
const baseConfig = {
|
|
157
|
-
feishu: { appId: "cli_old", appSecret: "secret_old" },
|
|
158
|
-
platforms: {
|
|
159
|
-
feishu: { enabled: true, platformType: "feishu" },
|
|
160
|
-
ilink: { enabled: true, reuseTokenOnStart: true },
|
|
161
|
-
},
|
|
162
|
-
webUi: { openOnStart: true },
|
|
163
|
-
chromeDevtools: { enabled: false, port: 15166, chromePath: "" },
|
|
164
|
-
port: 18080,
|
|
165
|
-
claude: {
|
|
166
|
-
enabled: true,
|
|
167
|
-
defaultAgent: true,
|
|
168
|
-
model: "",
|
|
169
|
-
subagentModel: "",
|
|
170
|
-
effort: "",
|
|
171
|
-
apiKey: "",
|
|
172
|
-
baseUrl: "",
|
|
173
|
-
maxTurn: 0,
|
|
174
|
-
},
|
|
175
|
-
cursor: {
|
|
176
|
-
enabled: true,
|
|
177
|
-
defaultAgent: false,
|
|
178
|
-
path: "",
|
|
179
|
-
model: "",
|
|
180
|
-
alternativeModel: "",
|
|
181
|
-
avatarBatteryMode: "apiPercent",
|
|
182
|
-
onDemandMonthlyBudget: 1000,
|
|
183
|
-
},
|
|
184
|
-
codex: {
|
|
185
|
-
enabled: true,
|
|
186
|
-
defaultAgent: false,
|
|
187
|
-
path: "",
|
|
188
|
-
model: "",
|
|
189
|
-
alternativeModel: "",
|
|
190
|
-
effort: "",
|
|
191
|
-
fastMode: false,
|
|
192
|
-
},
|
|
193
|
-
ccc: {
|
|
194
|
-
enabled: true,
|
|
195
|
-
defaultAgent: false,
|
|
196
|
-
DEEPSEEK_API_KEY: "sk-test-ccc",
|
|
197
|
-
DEEPSEEK_BASE_URL: "https://api.deepseek.com/v1",
|
|
198
|
-
model: "deepseek-v4-pro",
|
|
199
|
-
alternativeModel: "",
|
|
200
|
-
},
|
|
201
|
-
};
|
|
202
|
-
|
|
203
|
-
it("does not require restart for agent and Chrome runtime settings", () => {
|
|
204
|
-
expect(
|
|
205
|
-
getRestartRequiredReasons(baseConfig, {
|
|
206
|
-
...baseConfig,
|
|
207
|
-
chromeDevtools: { enabled: true, port: 15167, chromePath: "C:/Chrome/chrome.exe" },
|
|
208
|
-
claude: { ...baseConfig.claude, model: "claude-sonnet", apiKey: "sk-test", maxTurn: 8 },
|
|
209
|
-
cursor: { ...baseConfig.cursor, path: "C:/cursor-agent.cmd", model: "cursor-model" },
|
|
210
|
-
codex: {
|
|
211
|
-
...baseConfig.codex,
|
|
212
|
-
path: "C:/codex.cmd",
|
|
213
|
-
model: "gpt-5.3-codex",
|
|
214
|
-
effort: "high",
|
|
215
|
-
fastMode: true,
|
|
216
|
-
},
|
|
217
|
-
}),
|
|
218
|
-
).toEqual([]);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it("requires restart for port, Feishu credentials, platform type, and platform lifecycle", () => {
|
|
222
|
-
expect(
|
|
223
|
-
getRestartRequiredReasons(baseConfig, {
|
|
224
|
-
...baseConfig,
|
|
225
|
-
feishu: { appId: "cli_new", appSecret: "secret_new" },
|
|
226
|
-
platforms: {
|
|
227
|
-
feishu: { enabled: false, platformType: "lark" },
|
|
228
|
-
ilink: { enabled: false, reuseTokenOnStart: false },
|
|
229
|
-
},
|
|
230
|
-
port: 18081,
|
|
231
|
-
}),
|
|
232
|
-
).toEqual([
|
|
233
|
-
"port",
|
|
234
|
-
"feishu.appId",
|
|
235
|
-
"feishu.appSecret",
|
|
236
|
-
"platforms.feishu.platformType",
|
|
237
|
-
"platforms.feishu.enabled",
|
|
238
|
-
"platforms.ilink.enabled",
|
|
239
|
-
"platforms.ilink.reuseTokenOnStart",
|
|
240
|
-
]);
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
describe("dashboard edit modal", () => {
|
|
245
|
-
it("keeps the embedded dashboard script syntactically valid", () => {
|
|
246
|
-
const script = PAGE_HTML.match(/<script>([\s\S]*)<\/script>/)?.[1];
|
|
247
|
-
expect(script).toBeTruthy();
|
|
248
|
-
expect(() => new Function(script ?? "")).not.toThrow();
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it("shows the edit modal and overlay when a section edit button is clicked", () => {
|
|
252
|
-
expect(PAGE_HTML).toContain("function editSection(section)");
|
|
253
|
-
expect(PAGE_HTML).toContain("document.getElementById('edit-modal').classList.remove('hidden');");
|
|
254
|
-
expect(PAGE_HTML).toContain("document.getElementById('edit-overlay').classList.remove('hidden');");
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("uses plain alternative model labels for Cursor and Codex", () => {
|
|
258
|
-
expect(PAGE_HTML).toContain("field-CHATCCC_CURSOR_ALTERNATIVE_MODEL");
|
|
259
|
-
expect(PAGE_HTML).toContain("field-CHATCCC_CODEX_ALTERNATIVE_MODEL");
|
|
260
|
-
expect(PAGE_HTML).toContain("备选模型");
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("shows CCC Agent in the wizard and dashboard with model switching fields", () => {
|
|
264
|
-
expect(PAGE_HTML).toContain('id="agent-card-ccc"');
|
|
265
|
-
expect(PAGE_HTML).toContain('id="agent-enable-ccc"');
|
|
266
|
-
expect(PAGE_HTML).toContain('id="agent-default-ccc"');
|
|
267
|
-
expect(PAGE_HTML).toContain('id="field-CHATCCC_CCC_MODEL"');
|
|
268
|
-
expect(PAGE_HTML).toContain('id="field-CHATCCC_CCC_ALTERNATIVE_MODEL"');
|
|
269
|
-
expect(PAGE_HTML).toContain('id="field-CHATCCC_CCC_EFFORT"');
|
|
270
|
-
expect(PAGE_HTML).toContain('id="dash-ccc"');
|
|
271
|
-
expect(PAGE_HTML).toContain("editSection('ccc')");
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it("shows config effect scope hints", () => {
|
|
275
|
-
expect(PAGE_HTML).toContain("生效范围:保存后下一条消息或下个新会话生效");
|
|
276
|
-
expect(PAGE_HTML).toContain("生效范围:飞书开关、App ID、App Secret 或平台类型变更需要重启 ChatCCC");
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("shows the Codex Fast mode switch in both the wizard and dashboard", () => {
|
|
280
|
-
expect(PAGE_HTML).toContain('id="field-CHATCCC_CODEX_FAST_MODE"');
|
|
281
|
-
expect(PAGE_HTML).toContain('id="cfg-CODEX_FAST_MODE"');
|
|
282
|
-
expect(PAGE_HTML).toContain("Fast 模式");
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it("shows the Web UI startup switch in both the wizard and dashboard", () => {
|
|
286
|
-
expect(PAGE_HTML).toContain('id="field-CHATCCC_WEB_UI_OPEN_ON_START"');
|
|
287
|
-
expect(PAGE_HTML).toContain('id="cfg-WEB_UI_OPEN_ON_START"');
|
|
288
|
-
expect(PAGE_HTML).toContain("editSection('webUi')");
|
|
289
|
-
expect(PAGE_HTML).toContain("下次直接启动生效;内部重启始终不打开");
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
// ---------------------------------------------------------------------------
|
|
294
|
-
// chooseStartPath — /api/start 的路径选择
|
|
295
|
-
// 关键护栏:
|
|
296
|
-
// - setup 模式(hasInplaceActivateHook=true)下 isServiceRunning 永远为 true
|
|
297
|
-
// (setup 进程自己占着 PID 文件),必须无条件走 inplace;否则用户点
|
|
298
|
-
// "保存并启动"将永远拿到 "Service is already running"。
|
|
299
|
-
// - dashboard 模式 + service 已运行(通常就是当前进程自己)→ "reload":
|
|
300
|
-
// 用户点"保存并启动"想让新 config 生效,但服务正在跑——不真重启,仅
|
|
301
|
-
// 调用 reloadConfigFromDisk() 刷新进程内 export let 常量。绝不能再
|
|
302
|
-
// 返回"already running"挡用户路。
|
|
303
|
-
// - dashboard 模式 + service 未运行 → spawn 一个新的(旧 service 退出后场景)。
|
|
304
|
-
// ---------------------------------------------------------------------------
|
|
305
|
-
|
|
306
|
-
describe("chooseStartPath", () => {
|
|
307
|
-
it("setup 模式(注入 inplace hook)→ inplace(不管 PID 文件状态)", () => {
|
|
308
|
-
expect(
|
|
309
|
-
chooseStartPath({
|
|
310
|
-
hasInplaceActivateHook: true,
|
|
311
|
-
isServiceRunning: true,
|
|
312
|
-
}),
|
|
313
|
-
).toBe("inplace");
|
|
314
|
-
expect(
|
|
315
|
-
chooseStartPath({
|
|
316
|
-
hasInplaceActivateHook: true,
|
|
317
|
-
isServiceRunning: false,
|
|
318
|
-
}),
|
|
319
|
-
).toBe("inplace");
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("dashboard 模式 + service 已运行 → reload(仅刷新 config,不真重启)", () => {
|
|
323
|
-
expect(
|
|
324
|
-
chooseStartPath({
|
|
325
|
-
hasInplaceActivateHook: false,
|
|
326
|
-
isServiceRunning: true,
|
|
327
|
-
}),
|
|
328
|
-
).toBe("reload");
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("dashboard 模式 + service 未运行 → spawn", () => {
|
|
332
|
-
expect(
|
|
333
|
-
chooseStartPath({
|
|
334
|
-
hasInplaceActivateHook: false,
|
|
335
|
-
isServiceRunning: false,
|
|
336
|
-
}),
|
|
337
|
-
).toBe("spawn");
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
// ---------------------------------------------------------------------------
|
|
342
|
-
// Claude Code 引擎(Agent SDK)按需安装路由
|
|
343
|
-
// 护栏:/api/claude-sdk/status 与 /api/claude-sdk/install 必须可路由,且
|
|
344
|
-
// install 在“正在安装”时返回 alreadyRunning 而不是再起一个任务。
|
|
345
|
-
// ---------------------------------------------------------------------------
|
|
346
|
-
|
|
347
|
-
describe("Claude SDK install routes", () => {
|
|
348
|
-
beforeEach(() => {
|
|
349
|
-
installClaudeSdkMock.mockReset();
|
|
350
|
-
installClaudeSdkMock.mockResolvedValue(undefined);
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
afterEach(() => {
|
|
354
|
-
installClaudeSdkMock.mockReset();
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it("GET /api/claude-sdk/status 返回安装状态与进度", async () => {
|
|
358
|
-
const server = createServer(createUiRouter());
|
|
359
|
-
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
360
|
-
const port = (server.address() as AddressInfo).port;
|
|
361
|
-
try {
|
|
362
|
-
const response = await fetch(`http://127.0.0.1:${port}/api/claude-sdk/status`);
|
|
363
|
-
expect(response.status).toBe(200);
|
|
364
|
-
const body = await response.json();
|
|
365
|
-
expect(typeof body.installed).toBe("boolean");
|
|
366
|
-
expect(typeof body.running).toBe("boolean");
|
|
367
|
-
// 契约护栏:前端轮询读顶层 phase/message(若只嵌套在 progress 里,
|
|
368
|
-
// 前端 s.phase 恒为 undefined,进度条永不渲染——历史回归点)
|
|
369
|
-
expect(body.progress).toBeDefined();
|
|
370
|
-
expect(body.progress.phase).toBeDefined();
|
|
371
|
-
expect(body.phase).toBeDefined();
|
|
372
|
-
expect(typeof body.message).toBe("string");
|
|
373
|
-
expect(typeof body.percent).toBe("number");
|
|
374
|
-
} finally {
|
|
375
|
-
await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
it("POST /api/claude-sdk/install 启动后台安装(不真实下载)", async () => {
|
|
380
|
-
const server = createServer(createUiRouter());
|
|
381
|
-
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
382
|
-
const port = (server.address() as AddressInfo).port;
|
|
383
|
-
try {
|
|
384
|
-
const response = await fetch(`http://127.0.0.1:${port}/api/claude-sdk/install`, { method: "POST" });
|
|
385
|
-
expect(response.status).toBe(200);
|
|
386
|
-
const body = await response.json();
|
|
387
|
-
expect(body.ok).toBe(true);
|
|
388
|
-
expect(installClaudeSdkMock).toHaveBeenCalledTimes(1);
|
|
389
|
-
} finally {
|
|
390
|
-
await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
it("设置页 HTML 包含 Claude 引擎安装 UI(进度条 + 按钮)", () => {
|
|
395
|
-
expect(PAGE_HTML).toContain("claude-engine-install-btn");
|
|
396
|
-
expect(PAGE_HTML).toContain("claude-engine-progress-bar");
|
|
397
|
-
expect(PAGE_HTML).toContain("installClaudeEngine()");
|
|
398
|
-
expect(PAGE_HTML).toContain("claudeEngineRefreshStatus");
|
|
399
|
-
// 开关接入弹窗确认(SDK 必装才能使用)
|
|
400
|
-
expect(PAGE_HTML).toContain("onClaudeToggle(this)");
|
|
401
|
-
// 按钮文案:安装 Claude Code SDK,且不再显示体积提示
|
|
402
|
-
expect(PAGE_HTML).toContain("安装 Claude Code SDK");
|
|
403
|
-
expect(PAGE_HTML).not.toContain("约 220MB");
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it("全新用户(四个 Agent 均未启用)时 wizard 只默认勾选 DeepCCC(ccc)", () => {
|
|
407
|
-
// 护栏:renderStep2() 必须包含「全未启用 → 只勾 ccc」的逻辑片段
|
|
408
|
-
expect(PAGE_HTML).toContain("// 全新用户:四个 Agent 均无启用/配置痕迹时,只默认勾选 DeepCCC(ccc),其余不勾");
|
|
409
|
-
expect(PAGE_HTML).toContain("if (!claudeOn && !cursorOn && !codexOn && !cccOn)");
|
|
410
|
-
expect(PAGE_HTML).toContain("cccOn = true;");
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
it("Claude 开关打开时实时检测 SDK 安装状态(已装不重复安装)", () => {
|
|
414
|
-
// 护栏:onClaudeToggle() 必须实时查询 /api/claude-sdk/status 而非仅依赖缓存
|
|
415
|
-
expect(PAGE_HTML).toContain("// 实时查询后端安装状态");
|
|
416
|
-
expect(PAGE_HTML).toContain("var sdkReady = s.installed === true || s.phase === 'done'");
|
|
417
|
-
// 已安装/安装中直接打开,不触发 installClaudeEngine()
|
|
418
|
-
expect(PAGE_HTML).toContain("// 已安装 / 正在安装 / 正在检测:直接打开开关,不再触发安装");
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it("设置页卡片顺序:CCC 置顶于 Claude 之前", () => {
|
|
422
|
-
const cccIdx = PAGE_HTML.indexOf('id="agent-card-ccc"');
|
|
423
|
-
const claudeIdx = PAGE_HTML.indexOf('id="agent-card-claude"');
|
|
424
|
-
const cursorIdx = PAGE_HTML.indexOf('id="agent-card-cursor"');
|
|
425
|
-
const codexIdx = PAGE_HTML.indexOf('id="agent-card-codex"');
|
|
426
|
-
expect(cccIdx).toBeGreaterThan(-1);
|
|
427
|
-
expect(claudeIdx).toBeGreaterThan(-1);
|
|
428
|
-
expect(cursorIdx).toBeGreaterThan(-1);
|
|
429
|
-
expect(codexIdx).toBeGreaterThan(-1);
|
|
430
|
-
expect(cccIdx).toBeLessThan(claudeIdx);
|
|
431
|
-
expect(claudeIdx).toBeLessThan(cursorIdx);
|
|
432
|
-
expect(cursorIdx).toBeLessThan(codexIdx);
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it("CCC 卡片文案强调 OpenAI 兼容(不限于 DeepSeek)", () => {
|
|
436
|
-
expect(PAGE_HTML).toContain("OpenAI 兼容 API(不限于 DeepSeek)");
|
|
437
|
-
});
|
|
438
|
-
});
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import type { AddressInfo } from "node:net";
|
|
3
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
4
|
+
|
|
5
|
+
// 关键:mock installer 模块,避免 /api/claude-sdk/install 触发真实 npm 下载(220MB)
|
|
6
|
+
const installClaudeSdkMock = vi.hoisted(() => vi.fn());
|
|
7
|
+
vi.mock("../claude-sdk-installer.ts", () => ({
|
|
8
|
+
getClaudeSdkInstalledVersion: () => null,
|
|
9
|
+
getLastInstallProgress: () => ({ phase: "idle", percent: 0, message: "" }),
|
|
10
|
+
installClaudeSdk: installClaudeSdkMock,
|
|
11
|
+
isClaudeSdkInstalled: () => false,
|
|
12
|
+
isInstallRunning: () => false,
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
AGENT_TEAM_PAGE_HTML,
|
|
17
|
+
PAGE_HTML,
|
|
18
|
+
chooseStartPath,
|
|
19
|
+
createUiRouter,
|
|
20
|
+
getRestartRequiredReasons,
|
|
21
|
+
unflattenConfig,
|
|
22
|
+
} from "../web-ui.ts";
|
|
23
|
+
|
|
24
|
+
describe("Agent Team page", () => {
|
|
25
|
+
it("adds a prominent global entry to the ChatCCC page", () => {
|
|
26
|
+
expect(PAGE_HTML).toContain('href="/agent-team"');
|
|
27
|
+
expect(PAGE_HTML).toContain('class="agent-team-entry"');
|
|
28
|
+
expect(PAGE_HTML).toContain("Agent Team");
|
|
29
|
+
expect(PAGE_HTML).toContain("linear-gradient");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("contains only the Agent Team title as page content", () => {
|
|
33
|
+
expect(AGENT_TEAM_PAGE_HTML).toContain("<title>Agent Team</title>");
|
|
34
|
+
expect(AGENT_TEAM_PAGE_HTML).toContain("<h1>Agent Team</h1>");
|
|
35
|
+
expect(AGENT_TEAM_PAGE_HTML).not.toContain("dashboard-view");
|
|
36
|
+
expect(AGENT_TEAM_PAGE_HTML).not.toContain("wizard-view");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("serves the Agent Team page from its own route", async () => {
|
|
40
|
+
const server = createServer(createUiRouter());
|
|
41
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
42
|
+
const port = (server.address() as AddressInfo).port;
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch(`http://127.0.0.1:${port}/agent-team`);
|
|
45
|
+
expect(response.status).toBe(200);
|
|
46
|
+
expect(await response.text()).toBe(AGENT_TEAM_PAGE_HTML);
|
|
47
|
+
} finally {
|
|
48
|
+
await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("unflattenConfig", () => {
|
|
54
|
+
it("maps Claude subagent model into claude.subagentModel", () => {
|
|
55
|
+
expect(
|
|
56
|
+
unflattenConfig({
|
|
57
|
+
CHATCCC_ANTHROPIC_MODEL: "claude-sonnet-4-6",
|
|
58
|
+
CHATCCC_ANTHROPIC_SUBAGENT_MODEL: "claude-haiku-4-5-20251001",
|
|
59
|
+
}),
|
|
60
|
+
).toEqual({
|
|
61
|
+
claude: {
|
|
62
|
+
model: "claude-sonnet-4-6",
|
|
63
|
+
subagentModel: "claude-haiku-4-5-20251001",
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("maps Claude apiKey and baseUrl into claude config", () => {
|
|
69
|
+
expect(
|
|
70
|
+
unflattenConfig({
|
|
71
|
+
CHATCCC_ANTHROPIC_API_KEY: "sk-test-key",
|
|
72
|
+
CHATCCC_ANTHROPIC_BASE_URL: "https://api.example.com",
|
|
73
|
+
}),
|
|
74
|
+
).toEqual({
|
|
75
|
+
claude: {
|
|
76
|
+
apiKey: "sk-test-key",
|
|
77
|
+
baseUrl: "https://api.example.com",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("maps Cursor and Codex runtime settings into agent config", () => {
|
|
83
|
+
expect(
|
|
84
|
+
unflattenConfig({
|
|
85
|
+
CHATCCC_CURSOR_ALTERNATIVE_MODEL: "gpt-5.5-high",
|
|
86
|
+
CHATCCC_CODEX_ALTERNATIVE_MODEL: "gpt-5.3-codex",
|
|
87
|
+
CHATCCC_CODEX_FAST_MODE: true,
|
|
88
|
+
}),
|
|
89
|
+
).toEqual({
|
|
90
|
+
cursor: {
|
|
91
|
+
alternativeModel: "gpt-5.5-high",
|
|
92
|
+
},
|
|
93
|
+
codex: {
|
|
94
|
+
alternativeModel: "gpt-5.3-codex",
|
|
95
|
+
fastMode: true,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("maps CCC Agent settings into ccc config", () => {
|
|
101
|
+
expect(
|
|
102
|
+
unflattenConfig({
|
|
103
|
+
CHATCCC_CCC_ENABLED: true,
|
|
104
|
+
CHATCCC_CCC_DEFAULT_AGENT: true,
|
|
105
|
+
CHATCCC_CCC_API_KEY: "sk-test-ccc",
|
|
106
|
+
CHATCCC_CCC_BASE_URL: "https://api.deepseek.com/v1",
|
|
107
|
+
CHATCCC_CCC_MODEL: "deepseek-v4-flash",
|
|
108
|
+
CHATCCC_CCC_ALTERNATIVE_MODEL: "deepseek-v4-pro",
|
|
109
|
+
CHATCCC_CCC_EFFORT: "max",
|
|
110
|
+
CHATCCC_CCC_PROVIDER: "anthropic",
|
|
111
|
+
}),
|
|
112
|
+
).toEqual({
|
|
113
|
+
ccc: {
|
|
114
|
+
enabled: true,
|
|
115
|
+
defaultAgent: true,
|
|
116
|
+
DEEPSEEK_API_KEY: "sk-test-ccc",
|
|
117
|
+
DEEPSEEK_BASE_URL: "https://api.deepseek.com/v1",
|
|
118
|
+
model: "deepseek-v4-flash",
|
|
119
|
+
alternativeModel: "deepseek-v4-pro",
|
|
120
|
+
effort: "max",
|
|
121
|
+
provider: "anthropic",
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("maps Chrome CDP guard fields into chromeDevtools config", () => {
|
|
127
|
+
expect(
|
|
128
|
+
unflattenConfig({
|
|
129
|
+
CHATCCC_CHROME_DEVTOOLS_ENABLED: true,
|
|
130
|
+
CHATCCC_CHROME_DEVTOOLS_PORT: "15166",
|
|
131
|
+
CHATCCC_CHROME_DEVTOOLS_PATH: "C:/Program Files/Google/Chrome/Application/chrome.exe",
|
|
132
|
+
}),
|
|
133
|
+
).toEqual({
|
|
134
|
+
chromeDevtools: {
|
|
135
|
+
enabled: true,
|
|
136
|
+
port: 15166,
|
|
137
|
+
chromePath: "C:/Program Files/Google/Chrome/Application/chrome.exe",
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("maps the Web UI startup preference into webUi config", () => {
|
|
143
|
+
expect(
|
|
144
|
+
unflattenConfig({
|
|
145
|
+
CHATCCC_WEB_UI_OPEN_ON_START: false,
|
|
146
|
+
}),
|
|
147
|
+
).toEqual({
|
|
148
|
+
webUi: {
|
|
149
|
+
openOnStart: false,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("getRestartRequiredReasons", () => {
|
|
156
|
+
const baseConfig = {
|
|
157
|
+
feishu: { appId: "cli_old", appSecret: "secret_old" },
|
|
158
|
+
platforms: {
|
|
159
|
+
feishu: { enabled: true, platformType: "feishu" },
|
|
160
|
+
ilink: { enabled: true, reuseTokenOnStart: true },
|
|
161
|
+
},
|
|
162
|
+
webUi: { openOnStart: true },
|
|
163
|
+
chromeDevtools: { enabled: false, port: 15166, chromePath: "" },
|
|
164
|
+
port: 18080,
|
|
165
|
+
claude: {
|
|
166
|
+
enabled: true,
|
|
167
|
+
defaultAgent: true,
|
|
168
|
+
model: "",
|
|
169
|
+
subagentModel: "",
|
|
170
|
+
effort: "",
|
|
171
|
+
apiKey: "",
|
|
172
|
+
baseUrl: "",
|
|
173
|
+
maxTurn: 0,
|
|
174
|
+
},
|
|
175
|
+
cursor: {
|
|
176
|
+
enabled: true,
|
|
177
|
+
defaultAgent: false,
|
|
178
|
+
path: "",
|
|
179
|
+
model: "",
|
|
180
|
+
alternativeModel: "",
|
|
181
|
+
avatarBatteryMode: "apiPercent",
|
|
182
|
+
onDemandMonthlyBudget: 1000,
|
|
183
|
+
},
|
|
184
|
+
codex: {
|
|
185
|
+
enabled: true,
|
|
186
|
+
defaultAgent: false,
|
|
187
|
+
path: "",
|
|
188
|
+
model: "",
|
|
189
|
+
alternativeModel: "",
|
|
190
|
+
effort: "",
|
|
191
|
+
fastMode: false,
|
|
192
|
+
},
|
|
193
|
+
ccc: {
|
|
194
|
+
enabled: true,
|
|
195
|
+
defaultAgent: false,
|
|
196
|
+
DEEPSEEK_API_KEY: "sk-test-ccc",
|
|
197
|
+
DEEPSEEK_BASE_URL: "https://api.deepseek.com/v1",
|
|
198
|
+
model: "deepseek-v4-pro",
|
|
199
|
+
alternativeModel: "",
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
it("does not require restart for agent and Chrome runtime settings", () => {
|
|
204
|
+
expect(
|
|
205
|
+
getRestartRequiredReasons(baseConfig, {
|
|
206
|
+
...baseConfig,
|
|
207
|
+
chromeDevtools: { enabled: true, port: 15167, chromePath: "C:/Chrome/chrome.exe" },
|
|
208
|
+
claude: { ...baseConfig.claude, model: "claude-sonnet", apiKey: "sk-test", maxTurn: 8 },
|
|
209
|
+
cursor: { ...baseConfig.cursor, path: "C:/cursor-agent.cmd", model: "cursor-model" },
|
|
210
|
+
codex: {
|
|
211
|
+
...baseConfig.codex,
|
|
212
|
+
path: "C:/codex.cmd",
|
|
213
|
+
model: "gpt-5.3-codex",
|
|
214
|
+
effort: "high",
|
|
215
|
+
fastMode: true,
|
|
216
|
+
},
|
|
217
|
+
}),
|
|
218
|
+
).toEqual([]);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("requires restart for port, Feishu credentials, platform type, and platform lifecycle", () => {
|
|
222
|
+
expect(
|
|
223
|
+
getRestartRequiredReasons(baseConfig, {
|
|
224
|
+
...baseConfig,
|
|
225
|
+
feishu: { appId: "cli_new", appSecret: "secret_new" },
|
|
226
|
+
platforms: {
|
|
227
|
+
feishu: { enabled: false, platformType: "lark" },
|
|
228
|
+
ilink: { enabled: false, reuseTokenOnStart: false },
|
|
229
|
+
},
|
|
230
|
+
port: 18081,
|
|
231
|
+
}),
|
|
232
|
+
).toEqual([
|
|
233
|
+
"port",
|
|
234
|
+
"feishu.appId",
|
|
235
|
+
"feishu.appSecret",
|
|
236
|
+
"platforms.feishu.platformType",
|
|
237
|
+
"platforms.feishu.enabled",
|
|
238
|
+
"platforms.ilink.enabled",
|
|
239
|
+
"platforms.ilink.reuseTokenOnStart",
|
|
240
|
+
]);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("dashboard edit modal", () => {
|
|
245
|
+
it("keeps the embedded dashboard script syntactically valid", () => {
|
|
246
|
+
const script = PAGE_HTML.match(/<script>([\s\S]*)<\/script>/)?.[1];
|
|
247
|
+
expect(script).toBeTruthy();
|
|
248
|
+
expect(() => new Function(script ?? "")).not.toThrow();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("shows the edit modal and overlay when a section edit button is clicked", () => {
|
|
252
|
+
expect(PAGE_HTML).toContain("function editSection(section)");
|
|
253
|
+
expect(PAGE_HTML).toContain("document.getElementById('edit-modal').classList.remove('hidden');");
|
|
254
|
+
expect(PAGE_HTML).toContain("document.getElementById('edit-overlay').classList.remove('hidden');");
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("uses plain alternative model labels for Cursor and Codex", () => {
|
|
258
|
+
expect(PAGE_HTML).toContain("field-CHATCCC_CURSOR_ALTERNATIVE_MODEL");
|
|
259
|
+
expect(PAGE_HTML).toContain("field-CHATCCC_CODEX_ALTERNATIVE_MODEL");
|
|
260
|
+
expect(PAGE_HTML).toContain("备选模型");
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("shows CCC Agent in the wizard and dashboard with model switching fields", () => {
|
|
264
|
+
expect(PAGE_HTML).toContain('id="agent-card-ccc"');
|
|
265
|
+
expect(PAGE_HTML).toContain('id="agent-enable-ccc"');
|
|
266
|
+
expect(PAGE_HTML).toContain('id="agent-default-ccc"');
|
|
267
|
+
expect(PAGE_HTML).toContain('id="field-CHATCCC_CCC_MODEL"');
|
|
268
|
+
expect(PAGE_HTML).toContain('id="field-CHATCCC_CCC_ALTERNATIVE_MODEL"');
|
|
269
|
+
expect(PAGE_HTML).toContain('id="field-CHATCCC_CCC_EFFORT"');
|
|
270
|
+
expect(PAGE_HTML).toContain('id="dash-ccc"');
|
|
271
|
+
expect(PAGE_HTML).toContain("editSection('ccc')");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("shows config effect scope hints", () => {
|
|
275
|
+
expect(PAGE_HTML).toContain("生效范围:保存后下一条消息或下个新会话生效");
|
|
276
|
+
expect(PAGE_HTML).toContain("生效范围:飞书开关、App ID、App Secret 或平台类型变更需要重启 ChatCCC");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("shows the Codex Fast mode switch in both the wizard and dashboard", () => {
|
|
280
|
+
expect(PAGE_HTML).toContain('id="field-CHATCCC_CODEX_FAST_MODE"');
|
|
281
|
+
expect(PAGE_HTML).toContain('id="cfg-CODEX_FAST_MODE"');
|
|
282
|
+
expect(PAGE_HTML).toContain("Fast 模式");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("shows the Web UI startup switch in both the wizard and dashboard", () => {
|
|
286
|
+
expect(PAGE_HTML).toContain('id="field-CHATCCC_WEB_UI_OPEN_ON_START"');
|
|
287
|
+
expect(PAGE_HTML).toContain('id="cfg-WEB_UI_OPEN_ON_START"');
|
|
288
|
+
expect(PAGE_HTML).toContain("editSection('webUi')");
|
|
289
|
+
expect(PAGE_HTML).toContain("下次直接启动生效;内部重启始终不打开");
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
// chooseStartPath — /api/start 的路径选择
|
|
295
|
+
// 关键护栏:
|
|
296
|
+
// - setup 模式(hasInplaceActivateHook=true)下 isServiceRunning 永远为 true
|
|
297
|
+
// (setup 进程自己占着 PID 文件),必须无条件走 inplace;否则用户点
|
|
298
|
+
// "保存并启动"将永远拿到 "Service is already running"。
|
|
299
|
+
// - dashboard 模式 + service 已运行(通常就是当前进程自己)→ "reload":
|
|
300
|
+
// 用户点"保存并启动"想让新 config 生效,但服务正在跑——不真重启,仅
|
|
301
|
+
// 调用 reloadConfigFromDisk() 刷新进程内 export let 常量。绝不能再
|
|
302
|
+
// 返回"already running"挡用户路。
|
|
303
|
+
// - dashboard 模式 + service 未运行 → spawn 一个新的(旧 service 退出后场景)。
|
|
304
|
+
// ---------------------------------------------------------------------------
|
|
305
|
+
|
|
306
|
+
describe("chooseStartPath", () => {
|
|
307
|
+
it("setup 模式(注入 inplace hook)→ inplace(不管 PID 文件状态)", () => {
|
|
308
|
+
expect(
|
|
309
|
+
chooseStartPath({
|
|
310
|
+
hasInplaceActivateHook: true,
|
|
311
|
+
isServiceRunning: true,
|
|
312
|
+
}),
|
|
313
|
+
).toBe("inplace");
|
|
314
|
+
expect(
|
|
315
|
+
chooseStartPath({
|
|
316
|
+
hasInplaceActivateHook: true,
|
|
317
|
+
isServiceRunning: false,
|
|
318
|
+
}),
|
|
319
|
+
).toBe("inplace");
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("dashboard 模式 + service 已运行 → reload(仅刷新 config,不真重启)", () => {
|
|
323
|
+
expect(
|
|
324
|
+
chooseStartPath({
|
|
325
|
+
hasInplaceActivateHook: false,
|
|
326
|
+
isServiceRunning: true,
|
|
327
|
+
}),
|
|
328
|
+
).toBe("reload");
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
it("dashboard 模式 + service 未运行 → spawn", () => {
|
|
332
|
+
expect(
|
|
333
|
+
chooseStartPath({
|
|
334
|
+
hasInplaceActivateHook: false,
|
|
335
|
+
isServiceRunning: false,
|
|
336
|
+
}),
|
|
337
|
+
).toBe("spawn");
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// ---------------------------------------------------------------------------
|
|
342
|
+
// Claude Code 引擎(Agent SDK)按需安装路由
|
|
343
|
+
// 护栏:/api/claude-sdk/status 与 /api/claude-sdk/install 必须可路由,且
|
|
344
|
+
// install 在“正在安装”时返回 alreadyRunning 而不是再起一个任务。
|
|
345
|
+
// ---------------------------------------------------------------------------
|
|
346
|
+
|
|
347
|
+
describe("Claude SDK install routes", () => {
|
|
348
|
+
beforeEach(() => {
|
|
349
|
+
installClaudeSdkMock.mockReset();
|
|
350
|
+
installClaudeSdkMock.mockResolvedValue(undefined);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
afterEach(() => {
|
|
354
|
+
installClaudeSdkMock.mockReset();
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("GET /api/claude-sdk/status 返回安装状态与进度", async () => {
|
|
358
|
+
const server = createServer(createUiRouter());
|
|
359
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
360
|
+
const port = (server.address() as AddressInfo).port;
|
|
361
|
+
try {
|
|
362
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/claude-sdk/status`);
|
|
363
|
+
expect(response.status).toBe(200);
|
|
364
|
+
const body = await response.json();
|
|
365
|
+
expect(typeof body.installed).toBe("boolean");
|
|
366
|
+
expect(typeof body.running).toBe("boolean");
|
|
367
|
+
// 契约护栏:前端轮询读顶层 phase/message(若只嵌套在 progress 里,
|
|
368
|
+
// 前端 s.phase 恒为 undefined,进度条永不渲染——历史回归点)
|
|
369
|
+
expect(body.progress).toBeDefined();
|
|
370
|
+
expect(body.progress.phase).toBeDefined();
|
|
371
|
+
expect(body.phase).toBeDefined();
|
|
372
|
+
expect(typeof body.message).toBe("string");
|
|
373
|
+
expect(typeof body.percent).toBe("number");
|
|
374
|
+
} finally {
|
|
375
|
+
await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("POST /api/claude-sdk/install 启动后台安装(不真实下载)", async () => {
|
|
380
|
+
const server = createServer(createUiRouter());
|
|
381
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
382
|
+
const port = (server.address() as AddressInfo).port;
|
|
383
|
+
try {
|
|
384
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/claude-sdk/install`, { method: "POST" });
|
|
385
|
+
expect(response.status).toBe(200);
|
|
386
|
+
const body = await response.json();
|
|
387
|
+
expect(body.ok).toBe(true);
|
|
388
|
+
expect(installClaudeSdkMock).toHaveBeenCalledTimes(1);
|
|
389
|
+
} finally {
|
|
390
|
+
await new Promise<void>((resolve, reject) => server.close((err) => err ? reject(err) : resolve()));
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("设置页 HTML 包含 Claude 引擎安装 UI(进度条 + 按钮)", () => {
|
|
395
|
+
expect(PAGE_HTML).toContain("claude-engine-install-btn");
|
|
396
|
+
expect(PAGE_HTML).toContain("claude-engine-progress-bar");
|
|
397
|
+
expect(PAGE_HTML).toContain("installClaudeEngine()");
|
|
398
|
+
expect(PAGE_HTML).toContain("claudeEngineRefreshStatus");
|
|
399
|
+
// 开关接入弹窗确认(SDK 必装才能使用)
|
|
400
|
+
expect(PAGE_HTML).toContain("onClaudeToggle(this)");
|
|
401
|
+
// 按钮文案:安装 Claude Code SDK,且不再显示体积提示
|
|
402
|
+
expect(PAGE_HTML).toContain("安装 Claude Code SDK");
|
|
403
|
+
expect(PAGE_HTML).not.toContain("约 220MB");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("全新用户(四个 Agent 均未启用)时 wizard 只默认勾选 DeepCCC(ccc)", () => {
|
|
407
|
+
// 护栏:renderStep2() 必须包含「全未启用 → 只勾 ccc」的逻辑片段
|
|
408
|
+
expect(PAGE_HTML).toContain("// 全新用户:四个 Agent 均无启用/配置痕迹时,只默认勾选 DeepCCC(ccc),其余不勾");
|
|
409
|
+
expect(PAGE_HTML).toContain("if (!claudeOn && !cursorOn && !codexOn && !cccOn)");
|
|
410
|
+
expect(PAGE_HTML).toContain("cccOn = true;");
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it("Claude 开关打开时实时检测 SDK 安装状态(已装不重复安装)", () => {
|
|
414
|
+
// 护栏:onClaudeToggle() 必须实时查询 /api/claude-sdk/status 而非仅依赖缓存
|
|
415
|
+
expect(PAGE_HTML).toContain("// 实时查询后端安装状态");
|
|
416
|
+
expect(PAGE_HTML).toContain("var sdkReady = s.installed === true || s.phase === 'done'");
|
|
417
|
+
// 已安装/安装中直接打开,不触发 installClaudeEngine()
|
|
418
|
+
expect(PAGE_HTML).toContain("// 已安装 / 正在安装 / 正在检测:直接打开开关,不再触发安装");
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
it("设置页卡片顺序:CCC 置顶于 Claude 之前", () => {
|
|
422
|
+
const cccIdx = PAGE_HTML.indexOf('id="agent-card-ccc"');
|
|
423
|
+
const claudeIdx = PAGE_HTML.indexOf('id="agent-card-claude"');
|
|
424
|
+
const cursorIdx = PAGE_HTML.indexOf('id="agent-card-cursor"');
|
|
425
|
+
const codexIdx = PAGE_HTML.indexOf('id="agent-card-codex"');
|
|
426
|
+
expect(cccIdx).toBeGreaterThan(-1);
|
|
427
|
+
expect(claudeIdx).toBeGreaterThan(-1);
|
|
428
|
+
expect(cursorIdx).toBeGreaterThan(-1);
|
|
429
|
+
expect(codexIdx).toBeGreaterThan(-1);
|
|
430
|
+
expect(cccIdx).toBeLessThan(claudeIdx);
|
|
431
|
+
expect(claudeIdx).toBeLessThan(cursorIdx);
|
|
432
|
+
expect(cursorIdx).toBeLessThan(codexIdx);
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it("CCC 卡片文案强调 OpenAI 兼容(不限于 DeepSeek)", () => {
|
|
436
|
+
expect(PAGE_HTML).toContain("OpenAI 兼容 API(不限于 DeepSeek)");
|
|
437
|
+
});
|
|
438
|
+
});
|