@lynn123411/dsh-kimi-cu 0.3.8 → 0.3.9

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,48 +1,29 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * 包内自检:这个 bundle 装上之后,patch 里那三行真的各就各位,平台分流与技能目录都对。
4
- *
5
- * 三层断言,越往下越贴近真实装载:
6
- * 1. 清单面:files 点名的都在、bundle patch 指得到、exports 与 main 都在、dsh.client 声明了
7
- * web 与四个契约包、两个语言的标题与说明齐备、两份技能的 frontmatter 合规。
8
- * 2. 文本面:patch 只插三行、id 与内核包名一致、两条技能行各带自己的平台守卫与目录。这一层不需要内核,CI 上照跑。
9
- * 3. 契约面(本机装了内核才有):用内核 Include 的 parseEntryYaml 读 patch,再把两条技能行的 config
10
- * 交给 skill-filesystem 的 Config schema 校验。
11
- *
12
- * 随包技能能不能被真发现与真装载不在这里:那是 tools/probes/preset-skills.mjs 的事,check 里
13
- * 对两个技能根各跑一次。
14
- *
15
- * 跑法:pnpm check / node scripts/check-bundle.mjs
16
- * 退出码:0 通过(含明说跳过),1 不通过。
17
- */
18
2
  import assert from 'node:assert/strict';
19
3
  import { existsSync, readFileSync, readdirSync } from 'node:fs';
20
4
  import { dirname, join, resolve } from 'node:path';
21
5
  import { pathToFileURL } from 'node:url';
22
6
 
7
+ import { parseEntryYaml, stringifyEntryYaml } from '@deepseek-ai/cordis-plugin-include';
8
+
23
9
  import { currentKernel } from '../../../tools/lib/repo.mjs';
24
10
  import { resolveInstall } from '../src/server/resolve.ts';
25
11
 
26
12
  const PACKAGE_NAME = '@lynn123411/dsh-kimi-cu';
27
- const MACOS_BINARY = '/Applications/KimiCU.app/Contents/MacOS/kimi-cu';
28
- const MACOS_GUARD = "process.platform !== 'darwin'";
29
- const WINDOWS_GUARD = "process.platform !== 'win32'";
30
- const ROW_IDS = ['dsh-kimi-cu', 'skill-kimi-cu-macos', 'skill-kimi-cu-windows'];
31
- const SKILL_DIRS = { 'skill-kimi-cu-macos': 'macos', 'skill-kimi-cu-windows': 'windows' };
13
+ const SKILL_ROWS = {
14
+ 'skill-kimi-cu-macos': { dir: 'macos', platform: 'darwin' },
15
+ 'skill-kimi-cu-windows': { dir: 'windows', platform: 'win32' },
16
+ };
17
+ const ROW_IDS = ['dsh-kimi-cu', ...Object.keys(SKILL_ROWS)];
32
18
 
33
19
  const packageDir = resolve(import.meta.dirname, '..');
20
+ const baseUrl = pathToFileURL(join(packageDir, 'index.js')).href;
34
21
  const manifest = JSON.parse(readFileSync(join(packageDir, 'package.json'), 'utf8'));
35
22
 
36
23
  let passed = 0;
37
24
  let total = 0;
38
25
  const skipped = [];
39
26
 
40
- /**
41
- * 跑一条断言;同步与异步的断言共用一条路径(await 一个同步返回值是空操作)。
42
- * @param label - 这条断言在说什么。
43
- * @param fn - 断言本体,靠 node:assert 抛错。
44
- * @returns {Promise<void>}
45
- */
46
27
  async function test(label, fn) {
47
28
  total += 1;
48
29
  try {
@@ -55,18 +36,11 @@ async function test(label, fn) {
55
36
  console.log(' ok ' + label);
56
37
  }
57
38
 
58
- /**
59
- * 明说跳过一条要内核才能跑的断言——「没跑」不能被读成「通过」。
60
- * @param label - 跳过的是哪条。
61
- * @param why - 为什么跑不了。
62
- * @returns {void}
63
- */
64
39
  function skip(label, why) {
65
40
  skipped.push({ label, why });
66
41
  console.log(' skip ' + label + '(' + why + ')');
67
42
  }
68
43
 
69
- // ── 1. 清单面 ─────────────────────────────────────────────────────────────────
70
44
  await test('bundle patch 指得到,files 点名的条目都在', () => {
71
45
  const declared = manifest.dsh?.bundle?.patch;
72
46
  assert.equal(typeof declared, 'string', 'package.json 缺 dsh.bundle.patch');
@@ -121,18 +95,71 @@ await test('两份技能都在,frontmatter 的 name 与目录名一致且带
121
95
  }
122
96
  });
123
97
 
124
- // ── 2. 文本面 ─────────────────────────────────────────────────────────────────
125
- await test('patch 只插三行,id 就是约定的那三个', () => {
126
- const ids = [...patchText.matchAll(/^\s*-\s*id:\s*(\S+)\s*$/gm)].map((match) => match[1]);
127
- assert.deepEqual([...ids].sort(), [...ROW_IDS].sort(), 'patch 里该有的行只有这三条,多一条就说明装配形状变了');
128
- assert.equal(patchText.includes('dsh-mcp-client'), false, 'MCP 连接改由宿主半边注册,patch 里不该再有静态行');
129
- assert.match(patchText, /name: '@deepseek-ai\/dsh-skill-filesystem'/, '技能行要挂内核的 skill-filesystem');
98
+ function validatePatch(patches) {
99
+ assert.ok(Array.isArray(patches), 'bundle patch 要声明 YAML 列表');
100
+ const rows = patches.flatMap((patch) => {
101
+ assert.deepEqual(Object.keys(patch), ['insert'], 'bundle patch 只插入配置行');
102
+ assert.ok(Array.isArray(patch.insert), 'insert 要声明配置行列表');
103
+ return patch.insert;
104
+ });
105
+ assert.deepEqual(rows.map(({ id }) => id).sort(), [...ROW_IDS].sort(), 'patch 只插入约定的三条配置行');
106
+
107
+ const rootRow = rows.find(({ id }) => id === 'dsh-kimi-cu');
108
+ assert.equal(rootRow.name, PACKAGE_NAME, '根层行要挂本包');
109
+ assert.equal(rootRow.disabled, undefined, '根层行没有平台守卫');
110
+
111
+ for (const [id, { dir, platform }] of Object.entries(SKILL_ROWS)) {
112
+ const row = rows.find((entry) => entry.id === id);
113
+ assert.equal(row.name, '@deepseek-ai/dsh-skill-filesystem', id + ' 要挂内核的 skill-filesystem');
114
+ const guard = row.disabled?.__jsExpr;
115
+ assert.equal(typeof guard, 'string', id + ' 的平台守卫要用 !!js');
116
+ for (const platformUnderTest of ['darwin', 'win32', 'linux']) {
117
+ assert.equal(evaluateExpression(guard, baseUrl, { platform: platformUnderTest }), platformUnderTest !== platform,
118
+ id + ' 的平台守卫对 ' + platformUnderTest + ' 判定有误');
119
+ }
120
+
121
+ const config = row.config;
122
+ assert.equal(config?.providerName, 'kimi-cu', id + ' 要用独立的 providerName');
123
+ assert.equal(config.includeDefaultRoots, false, id + ' 不该重复扫项目与用户技能目录');
124
+ assert.ok(Array.isArray(config.customSkillDirs), id + ' 要声明技能目录列表');
125
+ assert.equal(config.customSkillDirs.length, 1, id + ' 只扫对应平台的技能目录');
126
+ const expression = config.customSkillDirs[0]?.__jsExpr;
127
+ assert.equal(typeof expression, 'string', id + ' 的技能目录要用 !!js');
128
+ assert.equal(evaluateExpression(expression, baseUrl), join(packageDir, 'skills', dir), id + ' 的表达式要落回 skills/' + dir);
129
+ }
130
+ }
131
+
132
+ const patchEntries = parseEntryYaml(patchText);
133
+
134
+ await test('用 Include 方言检查 patch 的三条配置行、平台守卫与技能配置', () => {
135
+ validatePatch(patchEntries);
130
136
  });
131
137
 
132
- await test('两条平台行各带自己的守卫,根层行没有守卫', () => {
133
- const guards = [...patchText.matchAll(/^\s*disabled:\s*(.+)$/gm)].map((match) => match[1].trim());
134
- assert.equal(guards.length, 2, '只有两条平台行需要 disabled 守卫');
135
- assert.deepEqual([...guards].sort(), ['!!js ' + MACOS_GUARD, '!!js ' + WINDOWS_GUARD].sort());
138
+ await test('patch 可以改用引号和缩进表达同一份配置', () => {
139
+ const canonical = stringifyEntryYaml(patchEntries, { lineWidth: 0 });
140
+ const alternate = canonical
141
+ .replace(/^ +/gm, ' $&')
142
+ .replace(/^( +(?:- )?id: )([\w-]+)$/gm, '$1"$2"');
143
+ assert.match(alternate, /^ +(?:- )?id: "dsh-kimi-cu"$/m);
144
+ const reformatted = parseEntryYaml(alternate);
145
+ assert.deepEqual(reformatted, patchEntries);
146
+ validatePatch(reformatted);
147
+ });
148
+
149
+ await test('patch 会拒绝错误守卫、错误包名和额外配置行', () => {
150
+ const sourceRows = patchEntries.flatMap(({ insert }) => insert);
151
+ const incorrectGuard = structuredClone(sourceRows);
152
+ incorrectGuard.find(({ id }) => id === 'skill-kimi-cu-macos').disabled = { __jsExpr: "process.platform !== 'win32'" };
153
+ const incorrectName = structuredClone(sourceRows);
154
+ incorrectName.find(({ id }) => id === 'skill-kimi-cu-windows').name = '@deepseek-ai/dsh-mcp-client';
155
+ const cases = [
156
+ [incorrectGuard, /平台守卫对 darwin 判定有误/],
157
+ [incorrectName, /要挂内核的 skill-filesystem/],
158
+ [[...sourceRows, { id: 'extra', name: PACKAGE_NAME }], /只插入约定的三条配置行/],
159
+ ];
160
+ for (const [rows, expected] of cases) {
161
+ assert.throws(() => validatePatch(parseEntryYaml(stringifyEntryYaml([{ insert: rows }]))), expected);
162
+ }
136
163
  });
137
164
 
138
165
  await test('MCP 连接由宿主半边注册给 mcpManager,命令取自探测器', () => {
@@ -146,24 +173,6 @@ await test('MCP 连接由宿主半边注册给 mcpManager,命令取自探测
146
173
  assert.ok(timeout >= 120000, '工具调用上限要覆盖长任务,现为 ' + timeout);
147
174
  });
148
175
 
149
- /**
150
- * 取某一行在 patch 文本里的那一段(到下一行 id 或文件末尾)。
151
- * @param id - 行 id。
152
- * @returns 该行的文本。
153
- */
154
- function rowBlock(id) {
155
- const start = patchText.indexOf('id: ' + id);
156
- assert.ok(start !== -1, 'patch 里找不到 ' + id + ' 行');
157
- const nextId = ROW_IDS.map((other) => patchText.indexOf('id: ' + other, start + 1)).filter((at) => at > start);
158
- return patchText.slice(start, nextId.length === 0 ? undefined : Math.min(...nextId));
159
- }
160
-
161
- await test('根层行挂本包,不带平台守卫', () => {
162
- const block = rowBlock('dsh-kimi-cu');
163
- assert.ok(block.includes("name: '" + PACKAGE_NAME + "'"), '根层行要挂本包');
164
- assert.doesNotMatch(block, /disabled:/, '根层行在别的平台上也要加载,卡片负责说明不支持');
165
- });
166
-
167
176
  await test('探测器给出的 MCP 命令就是各平台的真实路径', () => {
168
177
  const mac = resolveInstall({ platform: 'darwin', env: {}, exists: () => true });
169
178
  assert.equal(mac.mcp.command, '/Applications/KimiCU.app/Contents/Resources/kimi-cu-mcp', 'macOS 要使用官方启动脚本');
@@ -179,23 +188,6 @@ await test('探测器给出的 MCP 命令就是各平台的真实路径', () =>
179
188
  assert.equal(other.mcp, null, '不受支持的平台上探测器给 null,宿主半边就不注册');
180
189
  });
181
190
 
182
- await test('两条技能行另取 providerName、关掉默认目录,各扫自己的目录', () => {
183
- for (const [id, dir] of Object.entries(SKILL_DIRS)) {
184
- const block = rowBlock(id);
185
- assert.ok(block.includes('providerName: kimi-cu'), id + ' 不另取名就会与内核那条默认技能行同名');
186
- assert.ok(block.includes('includeDefaultRoots: false'), id + ' 不该重复扫项目与用户技能目录');
187
- assert.ok(block.includes("'skills', '" + dir + "'"), id + ' 要扫 skills/' + dir);
188
- assert.ok(block.includes("createRequire(baseUrl).resolve('" + PACKAGE_NAME + "/package.json')"), id + ' 的技能目录要按包名解析');
189
- }
190
- });
191
-
192
- // ── 3. 契约面(要本机已装内核) ────────────────────────────────────────────────
193
- /**
194
- * 在内核安装树的包仓里找某个包的真实目录。
195
- * @param kernel - 内核安装树。
196
- * @param name - 包名,例如 @deepseek-ai/dsh-mcp-client。
197
- * @returns 包目录;没装就是 undefined。
198
- */
199
191
  function kernelPackageDir(kernel, name) {
200
192
  const store = join(kernel.dir, 'node_modules/.pnpm');
201
193
  if (!existsSync(store)) return undefined;
@@ -207,13 +199,6 @@ function kernelPackageDir(kernel, name) {
207
199
  return undefined;
208
200
  }
209
201
 
210
- /**
211
- * 照 Loader 的方式求值一条 !!js 表达式:作用域里有 baseUrl 与 process。
212
- * @param expression - 表达式原文。
213
- * @param baseUrl - 装载该行的目录(file URL)。
214
- * @param processScope - process 替身;默认真 process。
215
- * @returns 求值结果。
216
- */
217
202
  function evaluateExpression(expression, baseUrl, processScope = process) {
218
203
  const evaluate = new Function('scope', 'expression', 'with (scope) { return eval(expression) }');
219
204
  return evaluate({ baseUrl, process: processScope }, expression);
@@ -224,10 +209,6 @@ const contractLabels = [
224
209
  '两条技能行的 config 通过内核 skill-filesystem 的真 Config schema,表达式落回对应目录',
225
210
  ];
226
211
 
227
- /**
228
- * 本机内核,取不到就 undefined。
229
- * @returns 内核安装树或 undefined。
230
- */
231
212
  function localKernel() {
232
213
  try {
233
214
  return currentKernel();
@@ -237,11 +218,6 @@ function localKernel() {
237
218
  }
238
219
  }
239
220
 
240
- /**
241
- * 内核里这两个包齐了才能验契约面;缺哪样就说哪样。
242
- * @param kernel - 内核安装树。
243
- * @returns 两个包目录或 undefined。
244
- */
245
221
  function contractDirs(kernel) {
246
222
  const dirs = {
247
223
  include: kernelPackageDir(kernel, '@deepseek-ai/cordis-plugin-include'),
@@ -255,37 +231,21 @@ function contractDirs(kernel) {
255
231
  return dirs;
256
232
  }
257
233
 
258
- /**
259
- * 用内核装载时那份 YAML 方言读 patch,并按 id 摊平成一张表。
260
- * @param includeDir - 内核 cordis-plugin-include 的目录。
261
- * @returns id 到行的映射。
262
- */
263
- async function parseRows(includeDir) {
264
- const { parseEntryYaml } = await import(pathToFileURL(join(includeDir, 'lib/index.js')).href);
265
- const entries = parseEntryYaml(patchText);
266
- const rows = new Map();
267
- for (const patch of entries) for (const row of patch.insert ?? []) rows.set(row.id, row);
268
- return rows;
269
- }
270
-
271
234
  const kernel = localKernel();
272
235
  const dirs = kernel === undefined ? undefined : contractDirs(kernel);
273
236
 
274
237
  if (kernel !== undefined && dirs !== undefined) {
275
- const rows = await parseRows(dirs.include);
276
-
277
- await test('patch 能被内核 ' + kernel.version + ' 装载时用的 YAML 方言读懂,三行都在', () => {
278
- assert.deepEqual([...rows.keys()].sort(), [...ROW_IDS].sort(), '解析出来该只有这三行');
238
+ await test('开发依赖与本机内核 ' + kernel.version + ' 对 patch 的解析结果一致', async () => {
239
+ const { parseEntryYaml: parseInstalledYaml } = await import(pathToFileURL(join(dirs.include, 'lib/index.js')).href);
240
+ assert.deepEqual(parseInstalledYaml(patchText), patchEntries);
279
241
  });
280
242
 
281
243
  await test('两条技能行的 config 通过内核 skill-filesystem 的真 Config schema,表达式落回对应目录', async () => {
282
244
  const { Config } = await import(pathToFileURL(join(dirs.skills, 'lib/index.js')).href);
283
- for (const [id, dir] of Object.entries(SKILL_DIRS)) {
284
- const row = rows.get(id);
285
- const expression = row.config.customSkillDirs?.[0]?.__jsExpr;
286
- assert.equal(typeof expression, 'string', id + ' 的 customSkillDirs 要由 !!js 算成绝对路径');
287
- const fromPackage = evaluateExpression(expression, pathToFileURL(join(packageDir, 'index.js')).href);
288
- assert.equal(resolve(fromPackage), resolve(join(packageDir, 'skills', dir)), id + ' 的表达式要落回 skills/' + dir);
245
+ const rows = patchEntries.flatMap(({ insert }) => insert);
246
+ for (const [id, { dir }] of Object.entries(SKILL_ROWS)) {
247
+ const row = rows.find((entry) => entry.id === id);
248
+ const fromPackage = evaluateExpression(row.config.customSkillDirs[0].__jsExpr, baseUrl);
289
249
  const resolved = Config({ ...row.config, customSkillDirs: [fromPackage] });
290
250
  assert.equal(resolved.providerName, 'kimi-cu');
291
251
  assert.equal(resolved.includeDefaultRoots, false);
@@ -1,23 +1,13 @@
1
- /**
2
- * 按 Web shell 的方式装载 lib/client.js:window.__ModuleLoader__ 桩件 + 平台模块表。
3
- * 两个客户端自检共用这一份,模块表只写一遍。
4
- */
5
1
  import { createRequire } from 'node:module';
6
2
  import { join } from 'node:path';
7
3
 
8
4
  const require = createRequire(import.meta.url);
9
5
 
10
- /** ui-primitives 的薄桩:只顶掉 bundle 真的 require 的那几个名字。 */
11
6
  const primitives = {
12
7
  Button: () => null,
13
8
  Tag: () => null,
14
9
  };
15
10
 
16
- /**
17
- * 装载浏览器 bundle。
18
- * @param root - 包根目录。
19
- * @returns bundle 的导出与它 require 过的模块 id。
20
- */
21
11
  export async function loadClientBundle(root) {
22
12
  let exported;
23
13
  const requires = [];
@@ -1,10 +1,3 @@
1
- /**
2
- * 浏览器半边自检:按 Web shell 的方式装载 lib/client.js,喂假 cordis 服务,断言
3
- * 字典与插件页状态卡注册。**未声明的服务读取必须抛**——漏声明不会报错,只会让插件
4
- * 在页面里消失(docs/rules/client-wiring.md),守卫自身要有反例断言证明它还能抛。
5
- *
6
- * 跑法:pnpm test / node scripts/smoke-client.mjs
7
- */
8
1
  import { fileURLToPath } from 'node:url';
9
2
  import { JSDOM } from 'jsdom';
10
3
  import { dirname, join, resolve } from 'node:path';
@@ -30,7 +23,6 @@ const registrations = [];
30
23
  const errors = [];
31
24
  const effects = [];
32
25
 
33
- /** cordis 忠实的上下文:读未声明的服务抛 cannot get property "x" without inject。 */
34
26
  function makeCtx(label, declared = []) {
35
27
  const table = {
36
28
  locale: {
@@ -1,15 +1,10 @@
1
- /**
2
- * 宿主半边自检:真 cordis Context + 真 ToolRuntime,断言 kimi_cu_status 注册得上、
3
- * 返回的状态形状对、patch 的五条行各就各位。
4
- *
5
- * 跑法:pnpm test / node scripts/smoke-host.mjs
6
- */
7
1
  import assert from 'node:assert/strict';
8
2
  import { readFileSync } from 'node:fs';
9
3
  import { dirname, join, resolve } from 'node:path';
10
4
  import { fileURLToPath } from 'node:url';
11
5
 
12
6
  import { Context } from '@deepseek-ai/cordis';
7
+ import { parseEntryYaml } from '@deepseek-ai/cordis-plugin-include';
13
8
  import SystemPrompt from '@deepseek-ai/dsh-system-prompt';
14
9
  import ToolRuntime from '@deepseek-ai/dsh-tools';
15
10
  import { NativeToolRegistry } from '@deepseek-ai/dsh-tools/pipeline';
@@ -35,7 +30,6 @@ async function test(label, fn) {
35
30
  }
36
31
  }
37
32
 
38
- /** 起一个真内核上下文:工具表 + 它写工具 schema 用的提示词服务。 */
39
33
  function host() {
40
34
  const ctx = new Context();
41
35
  new SystemPrompt(ctx, {});
@@ -92,18 +86,13 @@ await test('更新路由路径固定', () => {
92
86
  });
93
87
 
94
88
  await test('patch 有三行,根层行 id 与包名对得上', () => {
95
- const patch = readFileSync(join(root, 'cordis.patch.yml'), 'utf8')
96
- .split('\n')
97
- .map((line) => line.replace(/(^|\s)#.*$/, ''))
98
- .filter((line) => line.trim() !== '')
99
- .join('\n');
100
- const rows = [...patch.matchAll(/-\s*id:\s*(\S+)\s*\n\s*name:\s*'([^']+)'/g)].map((match) => [match[1], match[2]]);
101
- assert.equal(rows.length, 3, 'patch 应当有三条装配行:本包自己与两份技能 provider');
102
- assert.deepEqual(rows[0], ['dsh-kimi-cu', pkgName]);
103
- assert.deepEqual(rows[1], ['skill-kimi-cu-macos', '@deepseek-ai/dsh-skill-filesystem']);
104
- assert.deepEqual(rows[2], ['skill-kimi-cu-windows', '@deepseek-ai/dsh-skill-filesystem']);
105
- // MCP 连接由宿主半边注册,patch 里不该再有 mcp-client 行。
106
- assert.equal(patch.includes('dsh-mcp-client'), false, 'MCP 连接已交给 mcpManager,patch 里不该再出现静态行');
89
+ const patches = parseEntryYaml(readFileSync(join(root, 'cordis.patch.yml'), 'utf8'));
90
+ const rows = patches.flatMap((patch) => patch.insert ?? []);
91
+ assert.deepEqual(rows.map(({ id, name }) => [id, name]), [
92
+ [plugin.name, pkgName],
93
+ ['skill-kimi-cu-macos', '@deepseek-ai/dsh-skill-filesystem'],
94
+ ['skill-kimi-cu-windows', '@deepseek-ai/dsh-skill-filesystem'],
95
+ ]);
107
96
  });
108
97
 
109
98
  console.log('\nsmoke-host: ' + passed + '/' + total + ' 条断言通过');
@@ -1,18 +1,3 @@
1
- /**
2
- * 状态卡渲染自检:用真 React 把卡片画进 jsdom。
3
- *
4
- * 1. 未安装:命令、复制按钮、步骤都在;
5
- * 2. 本机检查通过:版本与恢复提示在,安装命令不再出现;
6
- * 3. 已安装但本机检查未通过:失败项与修复提示在;
7
- * 4. 平台不支持 / 读取失败:各自给出明确说明;
8
- * 5. 复制把命令写进剪贴板,重新检测请求带 refresh=1 并展示完整检查明细;
9
- * 6. 路径配置、检测错误和无法确认的权限分别给出对应状态与提示。
10
- *
11
- * ui-primitives 是替身:真组件是浏览器里的 ESM、带 .css 导入,Node 里跑不起来。
12
- * 替身只把 children 与 onClick 原样渲染,所以这里验的是本插件自己的视图结构。
13
- *
14
- * 跑法:node scripts/test-card.mjs
15
- */
16
1
  import assert from 'node:assert/strict';
17
2
  import { dirname, join, resolve } from 'node:path';
18
3
  import { fileURLToPath } from 'node:url';
@@ -61,7 +46,6 @@ exported.apply(ctx);
61
46
  const card = registrations.find((entry) => entry.options.name === 'plugins.bundle.config').component;
62
47
  const t = (key) => zh[key] ?? key;
63
48
 
64
- /** 默认的更新检查结果:已是最新。 */
65
49
  const DEFAULT_UPDATE = { current: '0.7.5', latest: '0.7.5', hasUpdate: false, error: null, checkedAt: 1 };
66
50
 
67
51
  let fetchUrl = '';
@@ -161,12 +145,6 @@ async function test(label, fn) {
161
145
  }
162
146
  }
163
147
 
164
- /**
165
- * 把卡片画进一个新容器。
166
- * @param status - 这一次 fetch 返回的状态。
167
- * @param options - httpStatus 覆盖响应码。
168
- * @returns 容器与 react root。
169
- */
170
148
  async function mount(status, options = {}) {
171
149
  fetchBody = status;
172
150
  fetchCode = options.httpStatus ?? 200;
@@ -187,7 +165,6 @@ async function mount(status, options = {}) {
187
165
  return { container, reactRoot };
188
166
  }
189
167
 
190
- /** 让挂起的 promise 链跑完一轮。 */
191
168
  async function flush() {
192
169
  await act(async () => {
193
170
  await new Promise((done) => setTimeout(done, 0));
@@ -195,12 +172,6 @@ async function flush() {
195
172
  });
196
173
  }
197
174
 
198
- /**
199
- * 按文字找按钮。
200
- * @param container - 容器。
201
- * @param text - 文字片段。
202
- * @returns 按钮或 undefined。
203
- */
204
175
  function buttonByText(container, text) {
205
176
  return [...container.querySelectorAll('button')].find((button) => (button.textContent ?? '').includes(text));
206
177
  }
@@ -1,12 +1,3 @@
1
- /**
2
- * 桌面操作独占槽位的自检:本插件要和官方 CUA、Cua Driver 一样经 `computerUse.register()`
3
- * 占位,占不到就不把 `mcp__kimi-cu__*` 工具交出去。
4
- *
5
- * 用真 cordis Context 与真 `ctx.inject`,只把两个服务换成可观察的替身:
6
- * `computerUse` 照抄宿主的独占语义(第二个注册直接抛错),`mcpManager` 记录每次注册。
7
- *
8
- * 跑法:pnpm test / node scripts/test-exclusivity.mjs
9
- */
10
1
  import assert from 'node:assert/strict';
11
2
 
12
3
  import { Context, Service } from '@deepseek-ai/cordis';
@@ -31,12 +22,6 @@ async function test(label, fn) {
31
22
  }
32
23
  }
33
24
 
34
- /**
35
- * 探测器替身:与平台无关,直接给出「已安装且 MCP 命令可用」的状态。
36
- *
37
- * 真探测器在 Linux 上必然给 `mcp: null`(不受支持的平台),注册那条链就跑不到,
38
- * 而这里要验的是独占槽位与注册的先后关系,不是平台分流。
39
- */
40
25
  const fakeDetect = async () => ({
41
26
  platform: 'darwin',
42
27
  supported: true,
@@ -50,16 +35,10 @@ const fakeDetect = async () => ({
50
35
  checkedAt: 0,
51
36
  });
52
37
 
53
- /** 等若干个微任务,让注入回调里那条同步链跑完。 */
54
38
  async function settle() {
55
39
  for (let i = 0; i < 8; i += 1) await Promise.resolve();
56
40
  }
57
41
 
58
- /**
59
- * 等一个条件成立。探测要真的跑一次 `doctor`,是外部进程,不能只等微任务。
60
- * @param {() => boolean} predicate - 条件。
61
- * @param {string} what - 超时时的说明。
62
- */
63
42
  async function waitFor(predicate, what) {
64
43
  const deadline = Date.now() + 20_000;
65
44
  while (Date.now() < deadline) {
@@ -69,7 +48,6 @@ async function waitFor(predicate, what) {
69
48
  throw new Error('等不到:' + what);
70
49
  }
71
50
 
72
- /** 宿主的桌面操作独占登记,语义照抄:占住之后第二个注册抛错并报出已占位的名字。 */
73
51
  class FakeComputerUse extends Service {
74
52
  constructor(ctx) {
75
53
  super(ctx, 'computerUse');
@@ -93,7 +71,6 @@ class FakeComputerUse extends Service {
93
71
  }
94
72
  }
95
73
 
96
- /** MCP 管理器替身:只记录注册过的服务器与撤销次数。 */
97
74
  class FakeMcpManager extends Service {
98
75
  constructor(ctx) {
99
76
  super(ctx, 'mcpManager');
@@ -138,7 +115,6 @@ class FakeMcpManager extends Service {
138
115
  }
139
116
  }
140
117
 
141
- /** 起一个只带工具表的上下文:工具表要提示词服务来写 schema。 */
142
118
  function host() {
143
119
  const ctx = new Context();
144
120
  new SystemPrompt(ctx, {});
@@ -1,11 +1,3 @@
1
- /**
2
- * 检测核心自检:平台解析、安装计划、`doctor` 解析与状态缓存。
3
- *
4
- * 路径与权限输入使用替身,另用 Node 子进程覆盖 doctor 的退出状态。
5
- * 期望值来自官方 `INSTALL.md` 与实测输出,不是照抄实现。
6
- *
7
- * 跑法:node scripts/test-status.mjs
8
- */
9
1
  import assert from 'node:assert/strict';
10
2
 
11
3
  import {
@@ -269,7 +261,6 @@ await test('Info.plist 里能读出 CFBundleShortVersionString', () => {
269
261
  assert.equal(parseMacosVersion('not a plist'), null);
270
262
  });
271
263
 
272
- /** 一个可推进的时钟与可计数的 doctor。 */
273
264
  function detectorHarness(overrides = {}) {
274
265
  let clock = 1_000;
275
266
  let doctorCalls = 0;
@@ -1,11 +1,3 @@
1
- /**
2
- * 更新链路自检:清单解析、版本比较、阶段映射、失败分类,以及更新器的行为。
3
- *
4
- * 纯函数部分用固定输入验;更新器用替身验「已是最新不执行」「清单读不到时 macOS 照跑、
5
- * Windows 报错」「单飞锁」「超时不 kill」「版本变了才重连」。
6
- *
7
- * 跑法:node scripts/test-update.mjs
8
- */
9
1
  import assert from 'node:assert/strict';
10
2
  import { dirname, join, resolve } from 'node:path';
11
3
  import { fileURLToPath } from 'node:url';
@@ -103,7 +95,6 @@ await test('classifyFailure 把已知失败分到五类', () => {
103
95
  assert.equal(classifyFailure('something else entirely', false), 'unknown');
104
96
  });
105
97
 
106
- /** 造一个更新器替身环境:记录每次读清单与每次 upgrade 的入参。 */
107
98
  function harness(overrides = {}) {
108
99
  const calls = { fetch: [], upgrade: [], reconnect: 0 };
109
100
  const base = {
@@ -133,7 +124,6 @@ function harness(overrides = {}) {
133
124
  return { updater: createUpdater(deps), calls };
134
125
  }
135
126
 
136
- /** 收集一次 run 的全部事件。 */
137
127
  async function collect(updater) {
138
128
  const events = [];
139
129
  await updater.run((event) => events.push(event));
@@ -286,6 +276,17 @@ await test('classifyFailure 跳过进度行,只看错误行', () => {
286
276
  );
287
277
  });
288
278
 
279
+ await test('classifyFailure 只收到进度或成功行时归 unknown,超时优先', () => {
280
+ const progress = '==> 校验代码签名与 Apple 公证 …';
281
+ const success = '✓ 签名 + 公证校验通过。';
282
+ const signatureError = '✗ 代码签名校验失败。';
283
+ assert.equal(classifyFailure(progress, false), 'unknown');
284
+ assert.equal(classifyFailure(success, false), 'unknown');
285
+ assert.equal(classifyFailure(`${progress}\n${success}`, false), 'unknown');
286
+ assert.equal(classifyFailure(signatureError, false), 'verify');
287
+ assert.equal(classifyFailure(signatureError, true), 'timeout');
288
+ });
289
+
289
290
  await test('run:超时后锁留到子进程真的退出', async () => {
290
291
  let exit;
291
292
  const whenExited = new Promise((done) => { exit = done; });