@lynn123411/dsh-kimi-cu 0.3.6 → 0.3.8

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.
@@ -1,11 +1,12 @@
1
1
  /**
2
- * 状态卡渲染自检:用真 react 把卡片画进 jsdom,锁住四种状态与两个动作。
2
+ * 状态卡渲染自检:用真 React 把卡片画进 jsdom。
3
3
  *
4
4
  * 1. 未安装:命令、复制按钮、步骤都在;
5
5
  * 2. 本机检查通过:版本与恢复提示在,安装命令不再出现;
6
6
  * 3. 已安装但本机检查未通过:失败项与修复提示在;
7
7
  * 4. 平台不支持 / 读取失败:各自给出明确说明;
8
- * 5. 复制把命令写进剪贴板,重新检测请求带 refresh=1。
8
+ * 5. 复制把命令写进剪贴板,重新检测请求带 refresh=1 并展示完整检查明细;
9
+ * 6. 路径配置、检测错误和无法确认的权限分别给出对应状态与提示。
9
10
  *
10
11
  * ui-primitives 是替身:真组件是浏览器里的 ESM、带 .css 导入,Node 里跑不起来。
11
12
  * 替身只把 children 与 onClick 原样渲染,所以这里验的是本插件自己的视图结构。
@@ -108,8 +109,9 @@ const BASE = {
108
109
  installed: false,
109
110
  path: null,
110
111
  version: null,
111
- doctor: { ran: false, ok: false, checks: [], raw: '' },
112
- mcp: { command: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', args: ['mcp', '-s', 'user'] },
112
+ doctor: { ran: false, ok: false, outcome: 'not-run', checks: [], diagnosticChecks: [], raw: '' },
113
+ mcp: null,
114
+ mcpStatus: null,
113
115
  install: {
114
116
  command: 'curl -fsSL https://cdn.kimi.com/kimi-computer-use/latest/setup_macos.sh | bash',
115
117
  steps: ['install', 'grant-permissions', 'recheck'],
@@ -120,6 +122,31 @@ const BASE = {
120
122
  checkedAt: 1,
121
123
  };
122
124
 
125
+ const DOCTOR_PASSED = {
126
+ ran: true,
127
+ ok: true,
128
+ outcome: 'passed',
129
+ checks: [{ id: 'accessibility', label: 'Accessibility (AX)', ok: true }],
130
+ diagnosticChecks: [],
131
+ raw: '',
132
+ };
133
+
134
+ const INSTALLED = {
135
+ ...BASE,
136
+ installed: true,
137
+ path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
138
+ version: '0.7.5',
139
+ doctor: DOCTOR_PASSED,
140
+ mcp: { command: '/Applications/KimiCU.app/Contents/Resources/kimi-cu-mcp', args: ['mcp', '-s', 'user'] },
141
+ mcpStatus: { state: 'connected' },
142
+ };
143
+
144
+ const WINDOWS = {
145
+ ...BASE,
146
+ platform: 'win32',
147
+ install: { ...BASE.install, command: 'powershell.exe -File setup_windows.ps1', steps: ['install', 'recheck'] },
148
+ };
149
+
123
150
  let passed = 0;
124
151
  let total = 0;
125
152
  async function test(label, fn) {
@@ -178,6 +205,27 @@ function buttonByText(container, text) {
178
205
  return [...container.querySelectorAll('button')].find((button) => (button.textContent ?? '').includes(text));
179
206
  }
180
207
 
208
+ async function recheck(container) {
209
+ const button = buttonByText(container, '重新检测');
210
+ assert.ok(button !== undefined);
211
+ await act(async () => { button.click(); });
212
+ await flush();
213
+ }
214
+
215
+ function checkResult(container, label) {
216
+ const term = [...container.querySelectorAll('dt')].find((node) => node.textContent === label);
217
+ if (term !== undefined) {
218
+ assert.equal(term.nextElementSibling?.tagName, 'DD');
219
+ return [...term.nextElementSibling.childNodes]
220
+ .filter((node) => node.getAttribute?.('aria-hidden') !== 'true')
221
+ .map((node) => node.textContent).join('');
222
+ }
223
+ const item = [...container.querySelectorAll('.dsh-kimi-cu-check-list li')]
224
+ .find((node) => !node.closest('details:not([open])') && node.querySelector('.dsh-kimi-cu-check-name')?.textContent === label);
225
+ assert.ok(item, `应显示检查项「${label}」`);
226
+ return item.querySelector('[role="img"]')?.getAttribute('aria-label');
227
+ }
228
+
181
229
  await test('未安装:显示安装命令、复制按钮与步骤', async () => {
182
230
  const { container } = await mount(BASE);
183
231
  const text = container.textContent ?? '';
@@ -189,38 +237,34 @@ await test('未安装:显示安装命令、复制按钮与步骤', async () =>
189
237
  });
190
238
 
191
239
  await test('本机检查通过:显示版本与恢复提示,不再展示安装命令', async () => {
192
- const { container } = await mount({
193
- ...BASE,
194
- installed: true,
195
- path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
196
- version: '0.6.8',
197
- mcpStatus: { state: 'connected' },
198
- doctor: { ran: true, ok: true, checks: [{ id: 'accessibility', label: 'Accessibility (AX)', ok: true }], raw: '' },
199
- });
240
+ const { container } = await mount(INSTALLED);
200
241
  const text = container.textContent ?? '';
201
242
  assert.match(text, /本机检查通过/);
202
- assert.match(text, /0\.6\.8/);
243
+ assert.match(text, /0\.7\.5/);
203
244
  assert.match(text, /如果模型看不到/);
204
- assert.doesNotMatch(text, /setup_macos\.sh/);
245
+ assert.doesNotMatch(text, /setup_macos\.sh|MCP 启动入口|辅助功能/);
205
246
  });
206
247
 
207
248
  await test('已安装但本机检查未通过:列出失败项与修复提示', async () => {
208
249
  const { container } = await mount({
209
- ...BASE,
210
- installed: true,
211
- path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
212
- version: '0.6.8',
250
+ ...INSTALLED,
251
+ mcpStatus: null,
213
252
  doctor: {
214
- ran: true,
253
+ ...DOCTOR_PASSED,
215
254
  ok: false,
216
- checks: [{ id: 'screen-recording', label: 'Screen Recording', ok: false }],
217
- raw: '',
255
+ outcome: 'failed',
256
+ checks: [...DOCTOR_PASSED.checks, { id: 'screen-recording', label: 'Screen Recording', ok: false }],
218
257
  },
219
258
  });
220
259
  const text = container.textContent ?? '';
221
260
  assert.match(text, /已安装 KimiCU,但本机检查未通过/);
222
- assert.match(text, /屏幕录制/);
223
- assert.match(text, /打开系统设置/);
261
+ assert.equal(checkResult(container, '诊断结果'), '未通过');
262
+ assert.equal(checkResult(container, '屏幕录制'), '未通过');
263
+ assert.match(text, /打开系统设置.*为 KimiCU 开启屏幕录制/);
264
+ assert.doesNotMatch(text, /辅助功能/);
265
+ await recheck(container);
266
+ assert.equal(checkResult(container, '辅助功能'), '通过');
267
+ assert.equal(checkResult(container, '屏幕录制'), '未通过');
224
268
  });
225
269
 
226
270
  await test('平台不支持:只说明不支持,不展示安装命令', async () => {
@@ -255,32 +299,100 @@ await test('复制按钮把安装命令写进剪贴板', async () => {
255
299
  assert.equal(copied, BASE.install.command);
256
300
  });
257
301
 
258
- await test('覆盖路径缺失:显示 override-missing 附注', async () => {
259
- const { container } = await mount({ ...BASE, notes: ['override-missing'] });
302
+ await test('已找到 Windows 安装但覆盖路径缺失:保留安装状态并优先修配置', async () => {
303
+ const { container } = await mount({
304
+ ...WINDOWS,
305
+ installed: true,
306
+ path: String.raw`C:\Users\test\AppData\Local\Kimi Computer Use\kimi-cu.exe`,
307
+ doctor: { ...DOCTOR_PASSED, checks: [{ id: 'mcp', label: 'MCP', ok: true }] },
308
+ notes: ['mcp-command-missing', 'override-missing'],
309
+ });
260
310
  const text = container.textContent ?? '';
261
311
  assert.match(text, /KIMI_CU_WINDOWS_EXE 指向的文件不存在/);
312
+ assert.doesNotMatch(text, /未检测到 KimiCU|setup_windows\.ps1|重新安装/);
313
+ await recheck(container);
314
+ assert.equal(checkResult(container, '安装状态'), '已安装');
315
+ assert.equal(checkResult(container, 'MCP 启动入口'), '未找到');
262
316
  });
263
317
 
264
- await test('MCP 命令缺失:即使 doctor 全绿也显示本机检查未通过', async () => {
318
+ await test('LOCALAPPDATA 缺失时无法确认安装和启动入口,显示路径修复方法', async () => {
319
+ const { container } = await mount({ ...WINDOWS, notes: ['localappdata-missing'] });
320
+ await recheck(container);
321
+ assert.match(container.textContent, /未设置 LOCALAPPDATA/);
322
+ assert.doesNotMatch(container.textContent, /未检测到 KimiCU|setup_windows\.ps1/);
323
+ assert.equal(checkResult(container, '安装状态'), '无法确认');
324
+ assert.equal(checkResult(container, 'MCP 启动入口'), '无法确认');
325
+ assert.equal(checkResult(container, '诊断结果'), '未运行');
326
+ });
327
+
328
+ await test('探测错误:显示原因,安装和启动入口为未知', async () => {
265
329
  const { container } = await mount({
266
330
  ...BASE,
331
+ notes: ['detection-failed'],
332
+ doctor: { ...BASE.doctor, error: 'file probe failed' },
333
+ });
334
+ await recheck(container);
335
+ assert.match(container.textContent, /KimiCU 检测失败/);
336
+ assert.match(container.textContent, /file probe failed/);
337
+ assert.doesNotMatch(container.textContent, /未检测到 KimiCU|setup_macos\.sh/);
338
+ assert.equal(checkResult(container, '安装状态'), '无法确认');
339
+ assert.equal(checkResult(container, 'MCP 启动入口'), '无法确认');
340
+ });
341
+
342
+ await test('MCP 命令缺失:即使 doctor 全绿也显示本机检查未通过', async () => {
343
+ const { container } = await mount({
344
+ ...WINDOWS,
267
345
  installed: true,
268
- path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
346
+ path: String.raw`C:\Users\test\AppData\Local\KimiCU\kimi-cu.exe`,
269
347
  version: '0.3.13',
270
- doctor: { ran: true, ok: true, checks: [], raw: '' },
348
+ doctor: { ...DOCTOR_PASSED, checks: [{ id: 'mcp', label: 'MCP', ok: true }] },
271
349
  notes: ['legacy-install', 'mcp-command-missing'],
272
350
  });
273
351
  const text = container.textContent ?? '';
274
352
  assert.match(text, /已安装 KimiCU,但本机检查未通过/);
353
+ assert.match(text, /检测到旧版 KimiCU 安装目录/);
275
354
  assert.match(text, /MCP 启动文件不存在/);
355
+ await recheck(container);
356
+ assert.equal(checkResult(container, 'MCP 启动入口'), '未找到');
357
+ assert.equal(checkResult(container, '诊断结果'), '通过');
358
+ assert.equal(checkResult(container, '连接'), 'MCP 未连接');
359
+ });
360
+
361
+ await test('macOS 启动文件缺失且权限通过时,保留修复指引', async () => {
362
+ const { container } = await mount({
363
+ ...INSTALLED,
364
+ mcp: null,
365
+ mcpStatus: null,
366
+ notes: ['mcp-command-missing'],
367
+ });
368
+ assert.match(container.textContent, /MCP 启动文件不存在/);
369
+ assert.doesNotMatch(container.textContent, /开启辅助功能|屏幕录制/);
370
+ });
371
+
372
+ await test('Windows doctor 的 mcp=false 只标记该项失败', async () => {
373
+ const path = String.raw`C:\Users\test\AppData\Local\Kimi Computer Use\kimi-cu.exe`;
374
+ const { container } = await mount({
375
+ ...WINDOWS,
376
+ installed: true,
377
+ path,
378
+ mcp: { command: path, args: ['mcp'] },
379
+ doctor: { ...DOCTOR_PASSED, ok: false, outcome: 'failed', checks: [{ id: 'mcp', label: 'MCP', ok: false }] },
380
+ });
381
+ await recheck(container);
382
+ assert.equal(checkResult(container, 'MCP 服务'), '未通过');
383
+ assert.equal(checkResult(container, 'MCP 启动入口'), '已找到');
384
+ assert.doesNotMatch(container.textContent, /权限|管理员/);
276
385
  });
277
386
 
278
387
  await test('MCP 连接失败时显示原因,即使本机检查通过', async () => {
279
- const { container } = await mount({ ...BASE, installed: true, path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', doctor: { ran: true, ok: true, checks: [], raw: '' }, mcpStatus: { state: 'failed', lastError: 'launcher failed' } });
388
+ const { container } = await mount({ ...INSTALLED, mcpStatus: { state: 'failed', lastError: 'launcher failed' } });
280
389
  const text = container.textContent ?? '';
281
390
  assert.match(text, /MCP 连接失败/);
282
391
  assert.match(text, /launcher failed/);
283
392
  assert.match(text, /MCP 尚未就绪/);
393
+ await recheck(container);
394
+ assert.equal(checkResult(container, '连接'), 'MCP 连接失败 · launcher failed');
395
+ assert.equal(container.textContent.match(/launcher failed/g)?.length, 1);
284
396
  });
285
397
 
286
398
  await test('本机检查通过但连接未建立时显示实际状态', async () => {
@@ -290,31 +402,103 @@ await test('本机检查通过但连接未建立时显示实际状态', async ()
290
402
  [{ state: 'reconnecting', lastError: 'launcher failed' }, /正在重新连接 MCP.*launcher failed/],
291
403
  [{ state: 'conflict', lastError: 'cua-driver-mcp' }, /桌面操作已由其他后端占用.*cua-driver-mcp/],
292
404
  ]) {
293
- const { container, reactRoot } = await mount({ ...BASE, installed: true, doctor: { ...BASE.doctor, ran: true, ok: true }, mcpStatus });
405
+ const { container, reactRoot } = await mount({ ...INSTALLED, mcpStatus });
294
406
  assert.match(container.textContent ?? '', hint);
295
407
  assert.doesNotMatch(container.textContent ?? '', /本机检查通过|MCP 连接失败/);
296
408
  await act(async () => { reactRoot.unmount(); });
297
409
  }
298
410
  });
299
411
 
300
- await test('重新检测请求带 refresh=1', async () => {
412
+ await test('重新检测请求带 refresh=1,未安装时也列出各项状态', async () => {
301
413
  const { container } = await mount(BASE);
302
- const button = buttonByText(container, '重新检测');
303
- assert.ok(button !== undefined);
304
- await act(async () => {
305
- button.click();
306
- await new Promise((done) => setTimeout(done, 0));
307
- });
414
+ await recheck(container);
308
415
  assert.match(statusUrl, /refresh=1/);
416
+ assert.equal(checkResult(container, '安装状态'), '未找到');
417
+ assert.equal(checkResult(container, 'MCP 启动入口'), '未找到');
418
+ assert.equal(checkResult(container, '诊断结果'), '未运行');
419
+ assert.equal(checkResult(container, '连接'), 'MCP 未连接');
309
420
  });
310
421
 
311
- const INSTALLED = {
312
- ...BASE,
313
- installed: true,
314
- path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
315
- version: '0.7.5',
316
- doctor: { ran: true, ok: true, checks: [{ id: 'accessibility', label: 'Accessibility (AX)', ok: true }], raw: '' },
317
- };
422
+ await test('重新检测展示通过和仅供排查的检查,连接更新后保留明细', async () => {
423
+ const checked = {
424
+ ...INSTALLED,
425
+ doctor: {
426
+ ...DOCTOR_PASSED,
427
+ checks: [...DOCTOR_PASSED.checks, { id: 'runtime-control', label: 'Runtime control: ready', ok: true }],
428
+ diagnosticChecks: [
429
+ { id: 'accessibility', label: 'Accessibility (AX)', ok: false },
430
+ { id: 'skylight', label: 'SkyLight post-to-pid', ok: null },
431
+ ],
432
+ },
433
+ };
434
+ const { container, reactRoot } = await mount(checked);
435
+ assert.doesNotMatch(container.textContent, /检查明细|辅助功能|仅供排查/);
436
+ fetchBody = { ...checked, mcpStatus: { state: 'connecting' } };
437
+ await recheck(container);
438
+ const service = container.querySelector('section[aria-label="KimiCU 服务"]');
439
+ const diagnostic = container.querySelector('details.dsh-kimi-cu-check-group');
440
+ assert.ok(service);
441
+ assert.ok(diagnostic);
442
+ assert.equal(diagnostic.open, false);
443
+ assert.match(diagnostic.querySelector('summary').textContent, /排查详情/);
444
+ assert.equal(checkResult(container, '安装状态'), '已安装');
445
+ assert.equal(checkResult(container, 'MCP 启动入口'), '已找到');
446
+ assert.equal(diagnostic.querySelector('code').textContent, checked.mcp.command);
447
+ assert.equal(checkResult(container, '诊断结果'), '通过');
448
+ assert.equal(checkResult(service, '辅助功能'), '通过');
449
+ assert.equal(checkResult(service, '运行时控制通道'), '通过');
450
+ assert.equal(service.querySelector('[aria-label="通过"]').textContent, '✅');
451
+ await act(async () => { diagnostic.querySelector('summary').click(); });
452
+ assert.equal(diagnostic.open, true);
453
+ assert.ok(diagnostic.querySelector('section[aria-label="运行检测的进程(仅供排查)"]'));
454
+ assert.equal(checkResult(diagnostic, '辅助功能'), '未通过');
455
+ assert.equal(checkResult(diagnostic, 'SkyLight post-to-pid'), '无法确认');
456
+ assert.equal(diagnostic.querySelector('[aria-label="未通过"]').textContent, '❌');
457
+ assert.equal(diagnostic.querySelector('[aria-label="无法确认"]').textContent, '❔');
458
+ assert.equal(checkResult(container, '连接'), '正在连接 MCP…');
459
+ assert.doesNotMatch(container.textContent, /打开系统设置/);
460
+
461
+ fetchBody = checked;
462
+ await act(async () => { await new Promise((done) => setTimeout(done, 1100)); });
463
+ assert.equal(checkResult(container, '连接'), 'MCP 已连接');
464
+ assert.equal(container.querySelector('details.dsh-kimi-cu-check-group').open, true);
465
+ assert.equal(checkResult(container, '辅助功能'), '通过');
466
+ assert.match(container.textContent, /本机检查通过/);
467
+ await act(async () => { reactRoot.unmount(); });
468
+ });
469
+
470
+ await test('doctor 无法确认权限时展示未知和错误原因', async () => {
471
+ const { container } = await mount({
472
+ ...INSTALLED,
473
+ mcpStatus: null,
474
+ doctor: {
475
+ ...DOCTOR_PASSED,
476
+ ok: false,
477
+ outcome: 'unknown',
478
+ checks: [...DOCTOR_PASSED.checks, { id: 'screen-recording', label: 'Screen Recording', ok: null }],
479
+ error: 'doctor timed out',
480
+ },
481
+ });
482
+ assert.match(container.textContent, /本机检查结果无法确认/);
483
+ assert.match(container.textContent, /doctor timed out/);
484
+ assert.doesNotMatch(container.textContent, /打开系统设置|本机检查未通过|辅助功能/);
485
+ await recheck(container);
486
+ assert.equal(checkResult(container, '诊断结果'), '无法确认');
487
+ assert.equal(checkResult(container, '辅助功能'), '通过');
488
+ assert.equal(checkResult(container, '屏幕录制'), '无法确认');
489
+ });
490
+
491
+ await test('旧宿主缺 outcome 和 diagnosticChecks 时仍能完成重新检测', async () => {
492
+ const { container } = await mount({
493
+ ...INSTALLED,
494
+ doctor: { ran: true, ok: true, checks: DOCTOR_PASSED.checks, raw: '' },
495
+ });
496
+ assert.match(container.textContent, /本机检查通过/);
497
+ await recheck(container);
498
+ assert.equal(checkResult(container, '诊断结果'), '通过');
499
+ assert.equal(checkResult(container, '辅助功能'), '通过');
500
+ assert.equal(checkResult(container, '连接'), 'MCP 已连接');
501
+ });
318
502
 
319
503
  const NEWER = { current: '0.7.5', latest: '0.7.6', hasUpdate: true, error: null, checkedAt: 1 };
320
504
 
@@ -43,7 +43,7 @@ const fakeDetect = async () => ({
43
43
  installed: true,
44
44
  path: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu',
45
45
  version: '0.7.5',
46
- doctor: { ran: true, ok: true, checks: [], raw: '' },
46
+ doctor: { ran: true, ok: true, outcome: 'passed', checks: [], diagnosticChecks: [], raw: '' },
47
47
  mcp: { command: '/Applications/KimiCU.app/Contents/MacOS/kimi-cu', args: ['mcp', '-s', 'user'] },
48
48
  install: null,
49
49
  notes: [],
@@ -214,11 +214,16 @@ await test('缺装、缺启动文件或 doctor 失败均不占槽,重新检测
214
214
  const cu = new FakeComputerUse(ctx);
215
215
  const mcp = new FakeMcpManager(ctx);
216
216
  const ready = await fakeDetect();
217
- let status = { ...ready, installed: false };
217
+ let status = { ...ready, installed: false, mcp: null };
218
218
  plugin.apply(ctx, { detect: async () => status });
219
219
  const tool = ctx.tools.get('kimi_cu_status');
220
220
  const exec = { signal: new AbortController().signal };
221
- for (const unavailable of [status, { ...ready, notes: ['mcp-command-missing'] }, { ...ready, doctor: { ...ready.doctor, ok: false } }]) {
221
+ for (const unavailable of [
222
+ status,
223
+ { ...ready, mcp: null, notes: ['mcp-command-missing'] },
224
+ { ...ready, doctor: { ...ready.doctor, ok: false, outcome: 'failed' } },
225
+ { ...ready, doctor: { ...ready.doctor, ok: false, outcome: 'unknown' } },
226
+ ]) {
222
227
  status = unavailable;
223
228
  await tool.execute({ refresh: true }, exec);
224
229
  assert.equal(cu.providerName, undefined);
@@ -230,6 +235,44 @@ await test('缺装、缺启动文件或 doctor 失败均不占槽,重新检测
230
235
  assert.equal(mcp.calls.length, 1);
231
236
  });
232
237
 
238
+ await test('重检无法确认时保留已连接的工具,明确失败或入口消失才撤回', async () => {
239
+ const ctx = host();
240
+ const cu = new FakeComputerUse(ctx);
241
+ const mcp = new FakeMcpManager(ctx);
242
+ mcp.status = { state: 'connected' };
243
+ const ready = await fakeDetect();
244
+ let status = ready;
245
+ plugin.apply(ctx, { detect: async () => status });
246
+ await waitFor(() => mcp.calls.length === 1, '应当注册 MCP 连接');
247
+ const tool = ctx.tools.get('kimi_cu_status');
248
+ const exec = { signal: new AbortController().signal };
249
+ const unknown = { ...ready.doctor, ok: false, outcome: 'unknown', error: 'timeout' };
250
+
251
+ for (const unconfirmed of [
252
+ { ...ready, doctor: unknown },
253
+ { ...ready, installed: false, mcp: null, doctor: unknown, notes: ['detection-failed'] },
254
+ ]) {
255
+ status = unconfirmed;
256
+ const result = JSON.parse((await tool.execute({ refresh: true }, exec)).status);
257
+ assert.equal(result.doctor.outcome, 'unknown');
258
+ assert.equal(result.mcpStatus.state, 'connected');
259
+ assert.equal(cu.providerName, 'kimi-cu');
260
+ assert.equal(mcp.disposed, 0);
261
+ }
262
+
263
+ for (const blocked of [
264
+ { ...ready, doctor: { ...ready.doctor, ok: false, outcome: 'failed' } },
265
+ { ...ready, mcp: null, notes: ['mcp-command-missing'] },
266
+ ]) {
267
+ status = ready;
268
+ await tool.execute({ refresh: true }, exec);
269
+ status = blocked;
270
+ await tool.execute({ refresh: true }, exec);
271
+ assert.equal(cu.providerName, undefined);
272
+ }
273
+ assert.equal(mcp.disposed, 2);
274
+ });
275
+
233
276
  await test('MCP 注册失败后释放槽,重检能补连', async () => {
234
277
  const ctx = host();
235
278
  const cu = new FakeComputerUse(ctx);
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 检测核心自检:平台解析、安装计划、`doctor` 解析与状态缓存。
3
3
  *
4
- * 这些是纯逻辑,不 spawn 任何进程:真 `doctor` 的调用在 smoke-host 与真机验收里。
4
+ * 路径与权限输入使用替身,另用 Node 子进程覆盖 doctor 的退出状态。
5
5
  * 期望值来自官方 `INSTALL.md` 与实测输出,不是照抄实现。
6
6
  *
7
7
  * 跑法:node scripts/test-status.mjs
@@ -17,7 +17,7 @@ import {
17
17
  WINDOWS_INSTALL_COMMAND,
18
18
  } from '../src/shared/status.ts';
19
19
  import { installPlan, resolveInstall } from '../src/server/resolve.ts';
20
- import { parseDoctor } from '../src/server/doctor.ts';
20
+ import { parseDoctor, runDoctor } from '../src/server/doctor.ts';
21
21
  import { createStatusDetector, parseMacosVersion } from '../src/server/status.ts';
22
22
 
23
23
  let passed = 0;
@@ -82,21 +82,21 @@ await test('macOS:找到二进制和官方启动脚本时使用 CodeAct', () =
82
82
  assert.deepEqual(resolved.notes, []);
83
83
  });
84
84
 
85
- await test('macOS:没找到二进制时 installed 为假,但 MCP 命令仍是约定路径', () => {
85
+ await test('macOS:没找到二进制时未安装,也没有可启动的 MCP 命令', () => {
86
86
  const resolved = resolveInstall({ platform: 'darwin', env: {}, exists: () => false });
87
87
  assert.equal(resolved.installed, false);
88
88
  assert.equal(resolved.path, null);
89
- assert.equal(resolved.mcp.command, MACOS_MCP_LAUNCHER);
89
+ assert.equal(resolved.mcp, null);
90
90
  });
91
91
 
92
92
  await test('macOS:启动脚本缺失时报告未就绪,不回退旧入口', () => {
93
93
  const resolved = resolveInstall({ platform: 'darwin', env: {}, exists: (path) => path === MACOS_BINARY });
94
94
  assert.equal(resolved.installed, true);
95
95
  assert.deepEqual(resolved.notes, ['mcp-command-missing']);
96
- assert.equal(resolved.mcp.command, MACOS_MCP_LAUNCHER);
96
+ assert.equal(resolved.mcp, null);
97
97
  });
98
98
 
99
- await test('Windows:新目录存在时用它,MCP 命令与 patch 表达式一致', () => {
99
+ await test('Windows:新安装目录用同一个文件做诊断和启动 MCP', () => {
100
100
  const resolved = resolveInstall({
101
101
  platform: 'win32',
102
102
  env: { LOCALAPPDATA: LOCAL },
@@ -128,8 +128,8 @@ await test('Windows:只有旧目录时标记 legacy-install 与 mcp-command-mi
128
128
  assert.equal(resolved.installed, true);
129
129
  assert.equal(resolved.path, WIN_LEGACY);
130
130
  assert.deepEqual(resolved.notes, ['legacy-install', 'mcp-command-missing']);
131
- assert.equal(resolved.mcp.command, WIN_PRIMARY);
132
- assert.ok(resolved.install.steps.includes('upgrade'), '旧目录安装要给出升级步骤');
131
+ assert.equal(resolved.mcp, null);
132
+ assert.deepEqual(resolved.install.steps, ['upgrade', 'recheck']);
133
133
  });
134
134
 
135
135
  await test('Windows:两个目录都没有时 installed 为假', () => {
@@ -139,23 +139,28 @@ await test('Windows:两个目录都没有时 installed 为假', () => {
139
139
  assert.deepEqual(resolved.notes, []);
140
140
  });
141
141
 
142
- await test('Windows:KIMI_CU_WINDOWS_EXE 指向不存在的文件时不再回退到默认目录', () => {
142
+ await test('Windows:覆盖路径无效仍能发现默认安装,但阻止 MCP 启动', () => {
143
143
  const missing = 'D:\\missing.exe';
144
144
  const resolved = resolveInstall({
145
145
  platform: 'win32',
146
146
  env: { LOCALAPPDATA: LOCAL, KIMI_CU_WINDOWS_EXE: missing },
147
147
  exists: (path) => path === WIN_PRIMARY,
148
148
  });
149
- assert.equal(resolved.installed, false);
150
- assert.equal(resolved.path, null);
149
+ assert.equal(resolved.installed, true);
150
+ assert.equal(resolved.path, WIN_PRIMARY);
151
151
  assert.deepEqual(resolved.notes, ['override-missing']);
152
- assert.equal(resolved.mcp.command, missing, 'MCP 行启动的是覆盖值,状态必须跟着它');
152
+ assert.equal(resolved.mcp, null);
153
153
  });
154
154
 
155
- await test('Windows:LOCALAPPDATA 缺失时命令与 patch 表达式同一公式', () => {
156
- const resolved = resolveInstall({ platform: 'win32', env: {}, exists: () => false });
155
+ await test('Windows:LOCALAPPDATA 缺失时不尝试当前盘根目录', () => {
156
+ const probed = [];
157
+ const resolved = resolveInstall({ platform: 'win32', env: {}, exists: (path) => { probed.push(path); return true; } });
157
158
  assert.equal(resolved.installed, false);
158
- assert.equal(resolved.mcp.command, '\\Kimi Computer Use\\kimi-cu.exe');
159
+ assert.equal(resolved.mcp, null);
160
+ assert.deepEqual(resolved.notes, ['localappdata-missing']);
161
+ assert.deepEqual(probed, []);
162
+ const custom = 'D:\\tools\\kimi-cu.exe';
163
+ assert.equal(resolveInstall({ platform: 'win32', env: { KIMI_CU_WINDOWS_EXE: custom }, exists: () => true }).mcp.command, custom);
159
164
  });
160
165
 
161
166
  await test('不支持的平台:supported 为假,没有 MCP 命令与安装计划', () => {
@@ -188,11 +193,24 @@ await test('macOS doctor:以服务权限为准,忽略调用进程的权限',
188
193
  ].join('\n');
189
194
  const report = parseDoctor('darwin', raw);
190
195
  assert.equal(report.ok, true);
191
- assert.equal(report.checks.length, 3);
196
+ assert.deepEqual(report.checks.map(({ id }) => id), ['accessibility', 'screen-recording', 'runtime-control']);
197
+ assert.deepEqual(report.diagnosticChecks.map(({ id, ok }) => ({ id, ok })), [{ id: 'screen-recording', ok: false }]);
192
198
  const failed = parseDoctor('darwin', raw.replace('✅ Accessibility (AX)', '❌ Accessibility (AX)'));
193
199
  assert.equal(failed.ok, false);
194
200
  });
195
201
 
202
+ await test('macOS doctor:服务段缺关键项时结论未知,调用进程权限不补位', () => {
203
+ const raw = [
204
+ 'Service (authoritative):', '✅ Runtime control channel: listening',
205
+ 'This process (diagnostic only):', '✅ Accessibility (AX)', '✅ Screen Recording',
206
+ ].join('\n');
207
+ const report = parseDoctor('darwin', raw);
208
+ assert.equal(report.outcome, 'unknown');
209
+ assert.equal(report.ok, false);
210
+ assert.deepEqual(report.checks.filter(({ ok }) => ok === null).map(({ id }) => id), ['accessibility', 'screen-recording']);
211
+ assert.equal(report.diagnosticChecks.length, 2);
212
+ });
213
+
196
214
  await test('macOS doctor:有一项失败时 ok 为假', () => {
197
215
  const parsed = parseDoctor('darwin', MAC_DOCTOR_BAD);
198
216
  assert.equal(parsed.ok, false);
@@ -208,10 +226,37 @@ await test('Windows doctor:mcp=true 时 ok 为真,版本从输出里读', ()
208
226
 
209
227
  await test('Windows doctor:mcp=false 时 ok 为假', () => {
210
228
  const parsed = parseDoctor('win32', WIN_DOCTOR_BAD);
229
+ assert.equal(parsed.outcome, 'failed');
211
230
  assert.equal(parsed.ok, false);
212
231
  assert.equal(parsed.version, '0.3.13');
213
232
  });
214
233
 
234
+ await test('Windows doctor:MCP 字段缺失或冲突时结论未知', () => {
235
+ for (const raw of ['version=0.3.13', 'mcp=true\nmcp=false']) {
236
+ const report = parseDoctor('win32', raw);
237
+ assert.equal(report.outcome, 'unknown');
238
+ assert.equal(report.checks[0].ok, null);
239
+ }
240
+ });
241
+
242
+ await test('doctor:进程非零退出时,全绿输出不能通过,明确失败仍可报告', async () => {
243
+ const previousOptions = process.env.NODE_OPTIONS;
244
+ try {
245
+ for (const [value, expected] of [['true', 'unknown'], ['false', 'failed']]) {
246
+ const child = `console.log(${JSON.stringify('mcp=' + value)}); process.exit(1);`;
247
+ process.env.NODE_OPTIONS = '--import=data:text/javascript,' + encodeURIComponent(child);
248
+ const report = await runDoctor('win32', process.execPath);
249
+ assert.equal(report.outcome, expected);
250
+ assert.equal(report.ok, false);
251
+ assert.equal(report.ran, true);
252
+ assert.match(report.error, /Command failed/);
253
+ }
254
+ } finally {
255
+ if (previousOptions === undefined) delete process.env.NODE_OPTIONS;
256
+ else process.env.NODE_OPTIONS = previousOptions;
257
+ }
258
+ });
259
+
215
260
  await test('Info.plist 里能读出 CFBundleShortVersionString', () => {
216
261
  const plist = [
217
262
  '<?xml version="1.0" encoding="UTF-8"?>',
@@ -235,7 +280,7 @@ function detectorHarness(overrides = {}) {
235
280
  readVersion: () => '0.6.8',
236
281
  runDoctor: async () => {
237
282
  doctorCalls += 1;
238
- return { ran: true, ok: true, checks: [], version: null, raw: '' };
283
+ return { ran: true, ok: true, outcome: 'passed', checks: [], diagnosticChecks: [], version: null, raw: '' };
239
284
  },
240
285
  now: () => clock,
241
286
  ttlMs: 10_000,
@@ -274,20 +319,41 @@ await test('并发调用共用一次探测', async () => {
274
319
  assert.equal(harness.calls(), 1);
275
320
  });
276
321
 
322
+ await test('升级后验收等待并跳过升级前开始的探测', async () => {
323
+ const oldDoctor = Promise.withResolvers();
324
+ const freshDoctor = { ran: true, ok: true, outcome: 'passed', checks: [], diagnosticChecks: [], version: null, raw: '' };
325
+ let version = '0.7.5';
326
+ let calls = 0;
327
+ const { detect } = detectorHarness({
328
+ readVersion: () => version,
329
+ runDoctor: async () => ++calls === 1 ? oldDoctor.promise : freshDoctor,
330
+ });
331
+ const before = detect(true);
332
+ version = '0.7.6';
333
+ const after = detect('after-upgrade');
334
+ assert.equal(calls, 1, '避免同时运行两个 doctor');
335
+ oldDoctor.resolve(freshDoctor);
336
+ assert.equal((await before).version, '0.7.5');
337
+ assert.equal((await after).version, '0.7.6');
338
+ assert.equal((await detect()).version, '0.7.6');
339
+ assert.equal(calls, 2);
340
+ });
341
+
277
342
  await test('doctor 失败时状态仍保留 installed,错误写进 doctor.error', async () => {
278
343
  const harness = detectorHarness({
279
- runDoctor: async () => ({ ran: true, ok: false, checks: [], version: null, raw: '', error: 'timeout' }),
344
+ runDoctor: async () => ({ ran: true, ok: false, outcome: 'unknown', checks: [], diagnosticChecks: [], version: null, raw: '', error: 'timeout' }),
280
345
  });
281
346
  const status = await harness.detect();
282
347
  assert.equal(status.installed, true);
283
348
  assert.equal(status.doctor.ok, false);
349
+ assert.equal(status.doctor.outcome, 'unknown');
284
350
  assert.equal(status.doctor.error, 'timeout');
285
351
  });
286
352
 
287
353
  await test('版本读不出来时回退到 doctor 输出里的版本', async () => {
288
354
  const harness = detectorHarness({
289
355
  readVersion: () => null,
290
- runDoctor: async () => ({ ran: true, ok: true, checks: [], version: '0.3.13', raw: '' }),
356
+ runDoctor: async () => ({ ran: true, ok: true, outcome: 'passed', checks: [], diagnosticChecks: [], version: '0.3.13', raw: '' }),
291
357
  });
292
358
  const status = await harness.detect();
293
359
  assert.equal(status.version, '0.3.13');
@@ -306,12 +372,13 @@ await test('exists 抛错时探测器不 reject,返回 detection-failed 状态
306
372
  env: {},
307
373
  exists: () => { throw new Error('boom'); },
308
374
  readVersion: () => null,
309
- runDoctor: async () => ({ ran: true, ok: true, checks: [], version: null, raw: '' }),
375
+ runDoctor: async () => { throw new Error('should not run'); },
310
376
  now: () => 1,
311
377
  });
312
378
  const status = await detect();
313
379
  assert.equal(status.installed, false);
314
380
  assert.deepEqual(status.notes, ['detection-failed']);
381
+ assert.equal(status.doctor.outcome, 'unknown');
315
382
  assert.match(status.doctor.error, /boom/);
316
383
  });
317
384