dsh-lean-router 0.0.0-stage → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE.md +23 -0
  3. package/README.en.md +73 -0
  4. package/README.md +72 -2
  5. package/cordis.patch.yml +870 -0
  6. package/docs/adr/0001-token-ledger-durable-usage.md +11 -0
  7. package/docs/agents/domain.md +38 -0
  8. package/docs/agents/issue-tracker.md +44 -0
  9. package/docs/agents/release.md +24 -0
  10. package/docs/agents/triage-labels.md +13 -0
  11. package/docs/agents/verification.md +32 -0
  12. package/docs/architecture.en.md +67 -0
  13. package/docs/architecture.md +66 -0
  14. package/docs/changelog.en.md +279 -0
  15. package/docs/changelog.md +282 -0
  16. package/docs/configuration.en.md +57 -0
  17. package/docs/configuration.md +57 -0
  18. package/docs/install.en.md +60 -0
  19. package/docs/install.md +60 -0
  20. package/docs/quickstart.en.md +75 -0
  21. package/docs/quickstart.md +75 -0
  22. package/docs/release-checklist.en.md +82 -0
  23. package/docs/release-checklist.md +131 -0
  24. package/docs//345/244/215/346/240/270-/345/205/263/346/217/222/344/273/266/346/270/205/345/215/225.md +108 -0
  25. package/docs//345/267/245/345/205/267/351/201/256/350/224/275-/346/216/245/347/272/277/350/257/264/346/230/216.md +140 -0
  26. package/docs//350/267/257/347/224/261-/350/256/276/350/256/241/350/257/264/346/230/216.md +104 -0
  27. package/lib/bands.js +149 -0
  28. package/lib/index.js +12 -0
  29. package/lib/lean/compaction.js +119 -0
  30. package/lib/lean/delivery-gate.js +312 -0
  31. package/lib/lean/disabled.js +61 -0
  32. package/lib/lean/history-budget.js +301 -0
  33. package/lib/lean/history-downgrade.js +345 -0
  34. package/lib/lean/index.js +19 -0
  35. package/lib/lean/output-slim.js +271 -0
  36. package/lib/lean/persona-text.js +111 -0
  37. package/lib/lean/plan-mode.js +31 -0
  38. package/lib/lean/pruner.js +75 -0
  39. package/lib/lean/tool-concurrency.js +319 -0
  40. package/lib/lean/usage-ledger.js +442 -0
  41. package/lib/router.js +287 -0
  42. package/lib/token-ledger/index.js +147 -0
  43. package/lib/token-ledger/live.js +193 -0
  44. package/lib/toolface/desc-slim.js +140 -0
  45. package/lib/toolface/discovery.js +297 -0
  46. package/lib/toolface/executor.js +333 -0
  47. package/lib/toolface/index.js +250 -0
  48. package/lib/toolface/pool.js +160 -0
  49. package/lib/toolface/retention.js +187 -0
  50. package/lib/toolface/rules.js +435 -0
  51. package/lib/toolface/scope.js +188 -0
  52. package/lib/toolface/transport.js +335 -0
  53. package/package.json +65 -4
  54. package/presets/base/frag-lean.patch.yml +459 -0
  55. package/presets/base/frag-preset.patch.yml +274 -0
  56. package/presets/base/frag-router.patch.yml +17 -0
  57. package/presets/base/frag-toolface.patch.yml +73 -0
  58. package/presets/base/lean-router.patch.yml +44 -0
  59. package/scripts/build-bundle.mjs +45 -0
  60. package/scripts/doctor.mjs +35 -0
  61. package/scripts/install-profile.mjs +113 -0
  62. package/scripts/install.mjs +20 -0
  63. package/scripts/integrate-preset.mjs +107 -0
  64. package/scripts/release.mjs +146 -0
  65. package/scripts/verify.mjs +8 -0
  66. package/test/build.test.mjs +7 -0
  67. package/test/history-budget.test.mjs +210 -0
  68. package/test/history-downgrade.test.mjs +379 -0
  69. package/test/integration-preset.test.mjs +59 -0
  70. package/test/lean-compaction.test.mjs +47 -0
  71. package/test/lean-concurrency.test.mjs +117 -0
  72. package/test/lean-delivery-gate.test.mjs +75 -0
  73. package/test/lean-frag.test.mjs +132 -0
  74. package/test/lean-modules.test.mjs +112 -0
  75. package/test/lean-pruner.test.mjs +42 -0
  76. package/test/output-slim.test.mjs +212 -0
  77. package/test/package.test.mjs +20 -0
  78. package/test/patch-yaml.test.mjs +45 -0
  79. package/test/plugin-entry.test.mjs +26 -0
  80. package/test/router-bands.test.mjs +98 -0
  81. package/test/router.test.mjs +215 -0
  82. package/test/token-ledger-live.test.mjs +351 -0
  83. package/test/token-ledger.test.mjs +264 -0
  84. package/test/toolface-desc-slim.test.mjs +255 -0
  85. package/test/toolface-executor.test.mjs +302 -0
  86. package/test/toolface-mask.test.mjs +258 -0
  87. package/test/toolface-rules.test.mjs +177 -0
  88. package/test/toolface-runtime.test.mjs +466 -0
  89. package/test/toolface-wiring.test.mjs +272 -0
  90. package/test/usage-ledger-inject.test.mjs +50 -0
  91. package/test/usage-ledger.test.mjs +399 -0
@@ -0,0 +1,75 @@
1
+ // test/lean-delivery-gate.test.mjs —— 加料件:交付门(默认关闭、关闭态零注入、钩子登记、无工作区跳过)
2
+ import test from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+
5
+ const base = new URL('../lib/lean/', import.meta.url);
6
+ const m = await import(new URL('delivery-gate.js', base).href + '?v=' + Date.now());
7
+
8
+ test('默认关闭;DSH_DELIVERY_GATE=0/1 语义(上游 L53-59)', () => {
9
+ const saved = process.env.DSH_DELIVERY_GATE;
10
+ try {
11
+ delete process.env.DSH_DELIVERY_GATE;
12
+ assert.equal(m.__internals.isOff(m.__internals.maybeResolve({})), true, '缺省关闭');
13
+ assert.equal(m.__internals.isOff(m.__internals.maybeResolve({ enabled: true })), false);
14
+ process.env.DSH_DELIVERY_GATE = '0';
15
+ assert.equal(m.__internals.isOff(m.__internals.maybeResolve({ enabled: true })), true, 'env=0 强制关');
16
+ process.env.DSH_DELIVERY_GATE = '1';
17
+ assert.equal(m.__internals.isOff(m.__internals.maybeResolve({})), false, 'env=1 强制开');
18
+ } finally {
19
+ if (saved === undefined) delete process.env.DSH_DELIVERY_GATE; else process.env.DSH_DELIVERY_GATE = saved;
20
+ }
21
+ });
22
+
23
+ test('section:关闭态返回空串(装配时被丢掉),开启态返回门提示', () => {
24
+ const saved = process.env.DSH_DELIVERY_GATE;
25
+ try {
26
+ delete process.env.DSH_DELIVERY_GATE;
27
+ let captured = null;
28
+ const ctx = { systemPrompt: { section: (s) => { captured = s; } }, effect() {} };
29
+ assert.equal(m.apply(ctx, {}), undefined, 'apply must not return a plain object (cordis "Invalid effect")');
30
+ assert.equal(captured.text(), '', '关闭时一个字都不注入(上游 L217-229)');
31
+ assert.equal(captured.name, 'lean-delivery-gate');
32
+ assert.equal(captured.order, 42);
33
+ } finally {
34
+ if (saved === undefined) delete process.env.DSH_DELIVERY_GATE; else process.env.DSH_DELIVERY_GATE = saved;
35
+ }
36
+ });
37
+
38
+ test('apply 登记效果;无工作区/无脚本的回合直接跳过(不跑脚本、不 steer)', async () => {
39
+ const saved = process.env.DSH_DELIVERY_GATE;
40
+ delete process.env.DSH_DELIVERY_GATE;
41
+ try {
42
+ let onHandler = null;
43
+ const ctx = {
44
+ systemPrompt: { section() {} },
45
+ on(event, handler) { assert.equal(event, 'agent/turn-stopping'); onHandler = handler; return () => {}; },
46
+ effect(factory) { factory(); },
47
+ get(name) { return undefined; },
48
+ };
49
+ m.apply(ctx, { enabled: true, scripts: ['definitely-missing-verify-script.txt'] });
50
+ assert.equal(typeof onHandler, 'function', 'turn-stopping 钩子已登记');
51
+ const agent = { session: { id: 's-gate-test' }, steer() { throw new Error('should not steer'); } };
52
+ // session 无 cwd 字段 → resolveCwd 返回 null → 跳过(上游 L238 同语义)
53
+ await onHandler({ agent, turn: 1, signal: undefined });
54
+ assert.ok(true, '无工作区时静默跳过、不抛错');
55
+ } finally {
56
+ if (saved === undefined) delete process.env.DSH_DELIVERY_GATE; else process.env.DSH_DELIVERY_GATE = saved;
57
+ }
58
+ });
59
+
60
+ test('校验:未知键拒绝;空 scripts 回落默认;非正整数拒绝', () => {
61
+ assert.throws(() => m.validateDeliveryGateConfig({ bogus: 1 }), /unknown key/);
62
+ assert.throws(() => m.validateDeliveryGateConfig({ maxRounds: 0 }), /positive integer/);
63
+ const cfg = m.validateDeliveryGateConfig({ scripts: [] });
64
+ assert.deepEqual(cfg.scripts, process.platform === 'win32' ? ['verify.ps1', 'verify.sh'] : ['verify.sh', 'verify.ps1'], '空数组回落默认(上游 maybeResolve 同语义)');
65
+ });
66
+
67
+ test('无顶层静态宿主依赖:源码级断言(缺宿主依赖也不得加载即崩)', async () => {
68
+ const { readFile } = await import('node:fs/promises');
69
+ const src = await readFile(new URL('../lib/lean/delivery-gate.js', import.meta.url), 'utf8');
70
+ assert.ok(!/^import .*@deepseek-ai/m.test(src), '不得顶层静态 import @deepseek-ai/*(须动态 import + 显式降级)');
71
+ assert.ok(!/^import .*zod/m.test(src), '不得顶层静态 import zod');
72
+ assert.ok(/await import\('@deepseek-ai\/dsh-llm'\)/.test(src), 'createUserMessage 走动态 import');
73
+ // 纯 node 环境本模块已成功加载(上一测试文件已 import),说明无加载即崩路径
74
+ assert.ok(m.__internals && m.__internals.MIN_GAP_MS === 15000);
75
+ });
@@ -0,0 +1,132 @@
1
+ // test/lean-frag.test.mjs —— frag-lean.patch.yml 形态与模块同源(验收项 2:顶层为列表续项)
2
+ import test from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { readFile } from 'node:fs/promises';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const ROOT = fileURLToPath(new URL('..', import.meta.url));
8
+ const fragPath = ROOT + 'presets/base/frag-lean.patch.yml';
9
+ const basePath = ROOT + 'presets/base/lean-router.patch.yml';
10
+
11
+ test('分片存在且顶层为 YAML 块序列续项(首个非注释行为顶层列表项)', async () => {
12
+ const frag = await readFile(fragPath, 'utf8');
13
+ const firstLine = frag.split('\n').map((l) => l.trim()).find((l) => l.length > 0 && !l.startsWith('#'));
14
+ assert.ok(firstLine.startsWith('- '), '首个非注释行必须是顶层块序列项(- 开头),got: ' + firstLine);
15
+ // 所有顶层项都在 0 列
16
+ const topLevel = frag.split('\n').filter((l) => /^- /.test(l) || /^-insert/.test(l));
17
+ assert.ok(topLevel.length >= 4, '至少 4 个顶层项(裸覆写行 + 3 个 insert 块)');
18
+ assert.equal(frag.split('\n').filter((l) => l.startsWith('- ')).length, 4, '顶层项恰好 4 个:裸行 + balance + delivery-gate + concurrency(usage-ledger 已移入 preset plugins)');
19
+ });
20
+
21
+ test('裸覆写行重声明 preset-lean-router 完整 config(dsh-app-boot config 整键替换形态)', async () => {
22
+ const frag = await readFile(fragPath, 'utf8');
23
+ assert.ok(frag.includes('- id: preset-lean-router\n name: \'@deepseek-ai/dsh-agent-preset\'\n config:'), '裸覆写行形态');
24
+ assert.ok(frag.includes(' id: lean-router'));
25
+ assert.ok(frag.includes(' order: 30'));
26
+ // 口径数值(机制 1/2)
27
+ assert.ok(frag.includes('thresholdRatio: 0.25'));
28
+ assert.ok(frag.includes('retainTokens: 20000'));
29
+ assert.ok(frag.includes('compactionRetries: 1'));
30
+ assert.ok(frag.includes('auto: true'));
31
+ assert.ok(frag.includes('thresholdChars: 8192'));
32
+ assert.ok(frag.includes('headChars: 4096'));
33
+ assert.ok(frag.includes('tailChars: 1024'));
34
+ });
35
+
36
+ test('机制 3:六件 disabled 全在分片(五件在 delegation 组 + plugin-manager 在预设顶层)', async () => {
37
+ const frag = await readFile(fragPath, 'utf8');
38
+ for (const id of ['tool-subagent-codex', 'tool-subagent-claude-code', 'workflow-ptc', 'tool-workflow', 'tool-ralph', 'tool-plugin-manager']) {
39
+ assert.ok(frag.includes('- id: ' + id), '缺 disabled 行:' + id);
40
+ }
41
+ assert.ok(frag.includes(' disabled: true'));
42
+ });
43
+
44
+ test('balance 预设行与两个 bundle 插件行就位', async () => {
45
+ const frag = await readFile(fragPath, 'utf8');
46
+ assert.ok(frag.includes('- id: preset-lean-router-balance'));
47
+ assert.ok(frag.includes(' id: lean-router-balance'));
48
+ assert.ok(frag.includes(' order: 29'));
49
+ assert.ok(frag.includes('- id: lean-delivery-gate'));
50
+ assert.ok(frag.includes("name: 'dsh-lean-router/lean/delivery-gate'"));
51
+ assert.ok(frag.includes(' enabled: false'));
52
+ assert.ok(frag.includes('- id: lean-concurrency'));
53
+ assert.ok(frag.includes("name: 'dsh-lean-router/lean/tool-concurrency'"));
54
+ assert.ok(frag.includes(' enabled: true'));
55
+ });
56
+
57
+ test('拼接占位行在分片的两个 suffix 内(不写路由内容)', async () => {
58
+ const frag = await readFile(fragPath, 'utf8');
59
+ const slots = frag.match(/# \[ticket-05\] 路由分类指令由票 05 拼接/g) || [];
60
+ assert.equal(slots.length, 2, 'lean 与 balance 两个 suffix 各一行占位');
61
+ assert.ok(!frag.includes('band=spec') && !frag.includes('[router] band='), '不得自行写路由内容(票 05 的)');
62
+ });
63
+
64
+ test('数据同源:分片内 persona suffix / plan-mode section 与 lib/lean 模块逐字符一致', async () => {
65
+ const frag = await readFile(fragPath, 'utf8');
66
+ const persona = await import(new URL('../lib/lean/persona-text.js', import.meta.url).href + '?v=' + Date.now());
67
+ const planMode = await import(new URL('../lib/lean/plan-mode.js', import.meta.url).href + '?v=' + Date.now());
68
+ // 从 YAML literal block 提取:suffix 键缩进 10 → 内容缩进 12
69
+ const extract = (text, keyIndent) => {
70
+ const lines = text.split('\n');
71
+ const idx = lines.findIndex((l) => l.startsWith(' '.repeat(keyIndent) + 'suffix: |-'));
72
+ assert.ok(idx >= 0, '找到 suffix 块');
73
+ const pad = ' '.repeat(keyIndent + 2);
74
+ const out = [];
75
+ for (let i = idx + 1; i < lines.length; i++) {
76
+ const l = lines[i];
77
+ if (l === '') { out.push(''); continue; }
78
+ if (l.startsWith(pad)) { out.push(l.slice(pad.length)); continue; }
79
+ break;
80
+ }
81
+ while (out.length > 0 && out[out.length - 1] === '') out.pop();
82
+ return out.join('\n');
83
+ };
84
+ const leanIdx = frag.indexOf('- id: persona');
85
+ const leanPart = frag.slice(leanIdx, frag.indexOf('- id: agent-instructions'));
86
+ assert.equal(extract(leanPart, 10), persona.LEAN_PERSONA_SUFFIX, 'lean suffix 与模块逐字符一致');
87
+ const balIdx = frag.indexOf('- id: preset-lean-router-balance');
88
+ const balPart = frag.slice(balIdx);
89
+ assert.equal(extract(balPart, 12), persona.BALANCE_PERSONA_SUFFIX, 'balance suffix 与模块逐字符一致');
90
+ // plan-mode section:键缩进 14 → 内容缩进 16
91
+ const planIdx = frag.indexOf('- id: plan-mode');
92
+ const planPart = frag.slice(planIdx, frag.indexOf(' # 机制 1'));
93
+ const pad = ' '.repeat(16);
94
+ const secIdx = planPart.split('\n').findIndex((l) => l.startsWith(' section: |'));
95
+ assert.ok(secIdx >= 0, '找到 section 块');
96
+ const secLines = planPart.split('\n').slice(secIdx + 1);
97
+ const out = [];
98
+ for (const l of secLines) {
99
+ if (l === '') { out.push(''); continue; }
100
+ if (l.startsWith(pad)) { out.push(l.slice(pad.length)); continue; }
101
+ break;
102
+ }
103
+ while (out.length > 0 && out[out.length - 1] === '') out.pop();
104
+ assert.equal(out.join('\n'), planMode.PLAN_MODE_SECTION, 'plan-mode section 与模块逐字符一致');
105
+ });
106
+
107
+ test('(宿主 yaml 可用时)合并后整文件可解析且行形态符合预期', async (t) => {
108
+ let yaml = null;
109
+ try {
110
+ const { pathToFileURL } = await import('node:url');
111
+ const mod = await import(pathToFileURL('D:/Deepseek Harness/resources/app.asar/dsh/node_modules/yaml/dist/index.js').href);
112
+ yaml = mod.parse ? mod : mod.default;
113
+ } catch (e) { yaml = null; }
114
+ if (!yaml || typeof yaml.parse !== 'function') {
115
+ // 说明:宿主包树位于 app.asar(Electron 归档)内,纯 node 子进程读不到其中文件,
116
+ // 因此 yaml 只在 Electron 侧可解析;本测试在纯 node 下跳过,静态断言已覆盖结构,
117
+ // 真实合并复验由 master 用宿主 --dump-config 执行(验收项 2 已标注待复验)。
118
+ t.skip('宿主 yaml 在 app.asar 内、纯 node 不可读;静态断言已覆盖,合并复验归 master');
119
+ return;
120
+ }
121
+ const base = await readFile(basePath, 'utf8');
122
+ const frag = await readFile(fragPath, 'utf8');
123
+ const doc = yaml.parse(base + (frag.endsWith('\n') ? frag : frag + '\n'), { schema: 'core' });
124
+ assert.equal(doc.length, 6, '合并后顶层 6 项:base insert + 裸覆写 + balance + delivery-gate + concurrency + usage-ledger');
125
+ const override = doc.find((d) => d.id === 'preset-lean-router');
126
+ assert.equal(override.config.plugins.length, 21);
127
+ const deleg = override.config.plugins.find((p) => p.id === 'delegation');
128
+ assert.deepEqual(deleg.config.filter((c) => c.disabled === true).map((c) => c.id), ['tool-subagent-codex', 'tool-subagent-claude-code', 'workflow-ptc', 'tool-workflow', 'tool-ralph']);
129
+ const balance = doc.find((d) => d.insert && d.insert[0] && d.insert[0].id === 'preset-lean-router-balance');
130
+ assert.equal(balance.insert[0].config.plugins.find((p) => p.id === 'persona').config.suffix.match(/^\d+\./gm).length, 3);
131
+ // 合并复验由 master 做(--dump-config);本断言只保证 YAML 层可解析与行形态。
132
+ });
@@ -0,0 +1,112 @@
1
+ // test/lean-modules.test.mjs —— lib/lean/ 各模块可独立加载与导出面(验收项 3)
2
+ import test from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+
5
+ const base = new URL('../lib/lean/', import.meta.url);
6
+ const mod = (name) => import(new URL(name, base).href + '?v=' + Date.now());
7
+
8
+ test('compaction.js 独立加载:口径常量与校验导出', async () => {
9
+ const m = await mod('compaction.js');
10
+ assert.deepEqual({ ...m.LEAN_COMPACTION_CONFIG }, { thresholdRatio: 0.25, retainTokens: 20000, compactionRetries: 1, auto: true });
11
+ assert.equal(m.validateCompactionConfig(m.LEAN_COMPACTION_CONFIG), true);
12
+ assert.equal(m.HOST_DEFAULTS.thresholdRatio, 0.8);
13
+ });
14
+
15
+ test('pruner.js 独立加载:marker 与口径常量', async () => {
16
+ const m = await mod('pruner.js');
17
+ assert.equal(m.PRUNE_MARKER.includes('tool result middle pruned'), true);
18
+ assert.deepEqual({ ...m.LEAN_PRUNER_CONFIG }, { thresholdChars: 8192, headChars: 4096, tailChars: 1024 });
19
+ assert.equal(typeof m.pruneText, 'function');
20
+ });
21
+
22
+ test('disabled.js 独立加载:6 件清单与上游一致', async () => {
23
+ const m = await mod('disabled.js');
24
+ assert.deepEqual([...m.DISABLED_PLUGIN_IDS], ['tool-subagent-codex', 'tool-subagent-claude-code', 'workflow-ptc', 'tool-workflow', 'tool-ralph', 'tool-plugin-manager']);
25
+ assert.equal(m.DISABLED_PLUGIN_ROWS.length, 6);
26
+ assert.equal(m.DISABLED_PLUGIN_ROWS.every((r) => r.disabled === true), true);
27
+ });
28
+
29
+ test('persona-text.js 独立加载:lean 13 条 + 2 软门 + 自检题钩子 + balance 3 条 + 拼接占位', async () => {
30
+ const m = await mod('persona-text.js');
31
+ const leanRules = m.LEAN_PERSONA_SUFFIX.match(/^\d+\./gm) || [];
32
+ assert.equal(leanRules.length, 13);
33
+ assert.equal((m.BALANCE_PERSONA_SUFFIX.match(/^\d+\./gm) || []).length, 3);
34
+ assert.equal(m.LEAN_SOFT_GATES.length, 2);
35
+ assert.equal(m.LEAN_SELF_CHECK_HOOKS.length, 1);
36
+ // 2 软门:澄清/计划(交付门已由规则 4 覆盖,不再单列)
37
+ assert.ok(m.LEAN_PERSONA_SUFFIX.includes('CLARIFY:'));
38
+ assert.ok(m.LEAN_PERSONA_SUFFIX.includes('PLAN:'));
39
+ assert.ok(!m.LEAN_PERSONA_SUFFIX.includes('DELIVER:'), '交付门不得与规则 4 重复');
40
+ // 自检题钩子:只留合卷(勤勉自检已并入规则 1)
41
+ assert.ok(!m.LEAN_PERSONA_SUFFIX.includes('Diligence (~every 10 turns):'), '勤勉自检不得与规则 1 重复');
42
+ assert.ok(m.LEAN_PERSONA_SUFFIX.includes('Close-the-book:'));
43
+ // 票 05 拼接占位(两个 suffix 都要有;不写任何路由内容)
44
+ for (const s of [m.LEAN_PERSONA_SUFFIX, m.BALANCE_PERSONA_SUFFIX]) {
45
+ assert.ok(s.includes('# [ticket-05] 路由分类指令由票 05 拼接'), 'suffix 需含票 05 拼接占位');
46
+ }
47
+ // 不含路由内容(不出现 band/classify/router 指令字样)
48
+ assert.ok(!m.LEAN_PERSONA_SUFFIX.includes('band='), '不得自行写路由内容');
49
+ // prefix 与上游一致
50
+ assert.equal(m.PERSONA_PREFIX, 'You are a coding agent powered by the {{model}} model.');
51
+ });
52
+
53
+ test('persona 并行调用引导:只读并发 + 写向同批省往返 + 遮挡整批拒绝(块 <=320,suffix <=4200)', async () => {
54
+ const m = await mod('persona-text.js');
55
+ const s = m.LEAN_PERSONA_SUFFIX;
56
+ // 事实 1:只读工具可真正重叠执行(tool-concurrency.js 给 glob/grep 打了 isConcurrencySafe)
57
+ for (const t of ['read', 'grep', 'glob', 'read_image']) {
58
+ assert.ok(s.includes(t), '并行引导缺只读工具名:' + t);
59
+ }
60
+ // 事实 2:写向/独占工具同批仍只算一次往返
61
+ for (const t of ['pwsh', 'edit', 'write']) {
62
+ assert.ok(s.includes(t), '并行引导缺写向工具名:' + t);
63
+ }
64
+ // 事实 3:混入被遮挡(masked)名字会让整批被拒、兄弟调用不执行
65
+ assert.ok(s.includes('masked'), '需提醒不要在同批混入被遮挡(masked)工具名');
66
+ // 体积上界:引导块本身极度精简,且 suffix 总长受控
67
+ const start = s.indexOf('PARALLEL CALLS');
68
+ assert.ok(start >= 0, '需有并行调用引导块');
69
+ const end = s.indexOf('7. Programmatic tool mode');
70
+ assert.ok(end > start, '并行引导块须位于规则 6 与规则 7 之间');
71
+ const block = s.slice(start, end).replace(/\n+$/, '');
72
+ assert.ok(block.length <= 320, '并行引导块须 <=320 字符,实为 ' + block.length);
73
+ assert.ok(s.length <= 4200, 'persona suffix 总长须 <=4200,实为 ' + s.length);
74
+ });
75
+
76
+ test('plan-mode.js 独立加载:v1 政策段原文要点', async () => {
77
+ const m = await mod('plan-mode.js');
78
+ for (const needle of ['You are in plan mode.', 'exit_plan_mode', 'Do not use todo_write to track this planning phase', 'Make the plan decision-complete']) {
79
+ assert.ok(m.PLAN_MODE_SECTION.includes(needle), 'section 缺:' + needle);
80
+ }
81
+ assert.deepEqual({ ...m.PLANNING_GROUP_ISOLATE }, { planMode: true });
82
+ });
83
+
84
+ test('delivery-gate.js 独立加载:插件形态与手写校验(动态 import 降级不崩)', async () => {
85
+ const m = await mod('delivery-gate.js');
86
+ assert.equal(m.name, 'lean-delivery-gate');
87
+ assert.deepEqual([...m.inject], ['systemPrompt']);
88
+ assert.equal(typeof m.apply, 'function');
89
+ assert.equal(typeof m.default.apply, 'function');
90
+ const cfg = m.validateDeliveryGateConfig({ enabled: true, maxRounds: 3 });
91
+ assert.equal(cfg.enabled, true);
92
+ assert.equal(cfg.maxRounds, 3);
93
+ assert.deepEqual(cfg.scripts, process.platform === 'win32' ? ['verify.ps1', 'verify.sh'] : ['verify.sh', 'verify.ps1']);
94
+ assert.throws(() => m.validateDeliveryGateConfig({ bogus: 1 }), /unknown key/);
95
+ assert.equal(m.validateDeliveryGateConfig({}).enabled, false, '默认关闭');
96
+ });
97
+
98
+ test('tool-concurrency.js 独立加载:导出面与默认插件', async () => {
99
+ const m = await mod('tool-concurrency.js');
100
+ assert.equal(typeof m.markConcurrencySafe, 'function');
101
+ assert.equal(typeof m.unmarkConcurrencySafe, 'function');
102
+ assert.equal(typeof m.installToolConcurrency, 'function');
103
+ assert.equal(m.default.name, 'lean-concurrency');
104
+ assert.deepEqual([...m.default.inject], ['tools', 'agents']);
105
+ assert.deepEqual([...m.__internals.DEFAULT_TARGETS], ['glob', 'grep']);
106
+ });
107
+
108
+ test('barrel index.js 汇总加载且不崩(零宿主静态依赖)', async () => {
109
+ const m = await mod('index.js');
110
+ assert.equal(Object.keys(m).length >= 25, true, 'barrel 导出应覆盖全部子模块');
111
+ assert.ok(m.LEAN_PERSONA_SUFFIX && m.PRUNE_MARKER && m.deliveryGateApply && m.installToolConcurrency);
112
+ });
@@ -0,0 +1,42 @@
1
+ // test/lean-pruner.test.mjs —— 机制 2:裁剪口径、不变量与 pruneText 行为(验收项 5 之参数覆盖)
2
+ import test from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+
5
+ const base = new URL('../lib/lean/', import.meta.url);
6
+ const m = await import(new URL('pruner.js', base).href + '?v=' + Date.now());
7
+
8
+ test('口径照抄 flash 实测:8192 / 4096 / 1024;marker 与宿主同文', () => {
9
+ assert.deepEqual({ ...m.LEAN_PRUNER_CONFIG }, { thresholdChars: 8192, headChars: 4096, tailChars: 1024 });
10
+ assert.equal(m.PRUNE_MARKER, '\n\n[... tool result middle pruned ...]\n\n');
11
+ });
12
+
13
+ test('不变量:headChars + marker + tailChars <= thresholdChars(宿主 L43-44 同判据)', () => {
14
+ // lean 口径本身合法
15
+ assert.deepEqual({ ...m.validatePrunerConfig({}) }, { thresholdChars: 8192, headChars: 4096, tailChars: 1024 });
16
+ // 违反不变量即抛(flash 四机制文档 L92-93:这三个数不能随手乱配)
17
+ assert.throws(() => m.validatePrunerConfig({ thresholdChars: 5000 }), /must be at most thresholdChars/);
18
+ assert.throws(() => m.validatePrunerConfig({ thresholdChars: 0 }), /positive integer/);
19
+ assert.throws(() => m.validatePrunerConfig({ headChars: -1 }), /non-negative/);
20
+ assert.throws(() => m.validatePrunerConfig({ bogus: 1 }), /unknown key/);
21
+ });
22
+
23
+ test('pruneText:未超阈值返回 null;超阈值保头 4096 + marker + 尾 1024', () => {
24
+ assert.equal(m.pruneText('abc'), null);
25
+ assert.equal(m.pruneText('x'.repeat(8192)), null, '恰好等于阈值不裁');
26
+ const pruned = m.pruneText('x'.repeat(10000));
27
+ assert.ok(pruned.startsWith('x'.repeat(4096)));
28
+ assert.ok(pruned.endsWith('x'.repeat(1024)));
29
+ assert.ok(pruned.includes('[... tool result middle pruned ...]'));
30
+ assert.ok(m.codePointLength(pruned) <= 8192, '裁后不超过阈值');
31
+ });
32
+
33
+ test('pruneText 按码点切分:CJK 与代理对不被拆(宿主 codePointLength 同语义)', () => {
34
+ const cjk = '汉'.repeat(9000); // 9000 码点
35
+ const pruned = m.pruneText(cjk);
36
+ assert.ok(pruned.startsWith('汉'.repeat(4096)));
37
+ assert.ok(pruned.endsWith('汉'.repeat(1024)));
38
+ const emoji = '😀'.repeat(9000); // 9000 码点(= 18000 UTF-16 单元),码点数 > 8192 才触发
39
+ const pe = m.pruneText(emoji);
40
+ assert.ok(!pe.includes('\uFFFD'), '不得出现替换符(代理对被拆的迹象)');
41
+ assert.ok(pe.startsWith('😀'.repeat(4096)));
42
+ });
@@ -0,0 +1,212 @@
1
+ // test/output-slim.test.mjs —— 机制 5:保守工具输出压缩(纯函数判据与 marker)
2
+ //
3
+ // 样本与期望串全部手写:期望值不从实现反算,只从「哪些行该保留、哪些该折叠」推出来。
4
+ import test from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+
7
+ import {
8
+ COLLAPSE_MIN_LINES,
9
+ SLIM_THRESHOLD_CHARS,
10
+ slimContentBlocks,
11
+ slimToolOutput,
12
+ } from '../lib/lean/output-slim.js';
13
+
14
+ /** 60 字符的重复行:折叠收益远大于 marker 自身长度。 */
15
+ const RULE = 'a'.repeat(60);
16
+ /** 默认阈值下不会被改写的短输出:连 3 行相同也不折叠(阈值优先)。 */
17
+ const SMALL = 'line one\nline two\nline two\nline two\n';
18
+ /** 10 行相同 + 首尾两行:625 字符。 */
19
+ const REPEATED = ['first line', ...Array(10).fill(RULE), 'done'].join('\n');
20
+ /**
21
+ * 手写期望:保留第一行 + 折叠 marker(10 - 1 = 9 行)+ 结尾节省字符数 marker。
22
+ * 节省 = 10 行原文(600 字符 + 9 个换行 = 609) - (1 行 60 字符 + 1 换行 + 33 字符 marker)= 515。
23
+ */
24
+ const REPEATED_EXPECTED = 'first line\n' + RULE
25
+ + '\n[... 9 identical lines collapsed]\ndone\n[... output compacted: 515 chars saved ...]';
26
+
27
+ test('未超过阈值时原样返回:短输出一个字都不改', () => {
28
+ assert.equal(SLIM_THRESHOLD_CHARS, 2000);
29
+ assert.equal(COLLAPSE_MIN_LINES, 3);
30
+ assert.equal(slimToolOutput(SMALL), SMALL, '短输出里的 3 连相同行也不折叠');
31
+ assert.equal(slimToolOutput('x'.repeat(2000)), 'x'.repeat(2000), '正好等于阈值不启用');
32
+ assert.equal(slimToolOutput('x'), 'x');
33
+ });
34
+
35
+ test('超过阈值:10 行连续相同 → 保留一行 + 折叠 marker + 节省字符数 marker', () => {
36
+ const out = slimToolOutput(REPEATED, { thresholdChars: 100 });
37
+ assert.equal(out, REPEATED_EXPECTED);
38
+ assert.match(out, /\[\.\.\. 9 identical lines collapsed\]/, 'marker 文本按约定');
39
+ assert.match(out, /\[\.\.\. output compacted: 515 chars saved \.\.\.\]/, 'marker 报出节省的字符数');
40
+ assert.ok(REPEATED.length > out.length, '压缩前后字符数为正收益');
41
+ });
42
+
43
+ test('连续不足 3 行的重复不折叠', () => {
44
+ const twice = ['head', RULE, RULE, 'tail'].join('\n');
45
+ assert.equal(slimToolOutput(twice, { thresholdChars: 50 }), twice);
46
+ });
47
+
48
+ test('两段互不相邻的重复各自折叠、各带一个 marker', () => {
49
+ const twoRuns = [RULE, RULE, RULE, 'gap', RULE, RULE, RULE, 'tail'].join('\n');
50
+ const out = slimToolOutput(twoRuns, { thresholdChars: 50 });
51
+ assert.equal((out.match(/\[\.\.\. 2 identical lines collapsed\]/g) ?? []).length, 2);
52
+ assert.match(out, /gap/, '块之间的行保留');
53
+ assert.match(out, /tail/);
54
+ });
55
+
56
+ test('错误 / 异常 / 失败行永不折叠(连续 5 行也全部保留)', () => {
57
+ const failure = 'Error: ECONNREFUSED connect 127.0.0.1:5432 failed';
58
+ const mixed = [failure, failure, failure, failure, failure, 'pad', RULE, RULE, RULE, RULE, 'tail'].join('\n');
59
+ const out = slimToolOutput(mixed, { thresholdChars: 100 });
60
+ assert.equal((out.match(new RegExp(failure, 'g')) ?? []).length, 5, '5 行错误行一个不少');
61
+ assert.match(out, /\[\.\.\. 3 identical lines collapsed\]/, '同一份输出里的普通重复行仍然折叠');
62
+ assert.ok(out.length < mixed.length);
63
+ });
64
+
65
+ test('退出码 / traceback / 失败结论行同样受保护', () => {
66
+ const guarded = [
67
+ 'process exited with code 1',
68
+ 'Traceback (most recent call last):',
69
+ 'npm run build failed',
70
+ ];
71
+ const input = guarded.map((line) => Array(3).fill(line)).flat().join('\n');
72
+ assert.ok(input.length > 50);
73
+ assert.equal(slimToolOutput(input, { thresholdChars: 50 }), input, '全是受保护行时原样返回');
74
+ });
75
+
76
+ test('文件路径行永不折叠(Windows 与 POSIX 各 3 行全部保留)', () => {
77
+ const winPath = 'C:\\repo\\src\\lib\\toolface\\executor.js';
78
+ const posixPath = '/home/user/project/src/main.ts';
79
+ const input = [winPath, winPath, winPath, posixPath, posixPath, posixPath, RULE, RULE, RULE].join('\n');
80
+ const out = slimToolOutput(input, { thresholdChars: 50 });
81
+ assert.equal(out.split(winPath).length - 1, 3, 'Windows 路径全保留');
82
+ assert.equal(out.split(posixPath).length - 1, 3, 'POSIX 路径全保留');
83
+ assert.match(out, /\[\.\.\. 2 identical lines collapsed\]/, '普通重复行照常折叠');
84
+ });
85
+
86
+ test('非字符串与空串安全返回原值', () => {
87
+ assert.equal(slimToolOutput(undefined), undefined);
88
+ assert.equal(slimToolOutput(null), null);
89
+ assert.equal(slimToolOutput(42), 42);
90
+ assert.equal(slimToolOutput(''), '');
91
+ });
92
+
93
+ test('slimContentBlocks 只改 text 块、保留其余字段与未变化块的引用', () => {
94
+ const untouched = [{ type: 'image', source: { data: 'x' } }, { type: 'text', text: 'short' }];
95
+ assert.equal(slimContentBlocks(untouched), untouched, '无变化时返回原数组引用');
96
+
97
+ const blocks = [
98
+ { type: 'text', text: REPEATED, name: 'pwsh' },
99
+ { type: 'text', text: 'tail' },
100
+ ];
101
+ const slimmed = slimContentBlocks(blocks, { thresholdChars: 100 });
102
+ assert.notEqual(slimmed, blocks);
103
+ assert.equal(slimmed[0].text, REPEATED_EXPECTED);
104
+ assert.equal(slimmed[0].name, 'pwsh', '同一 block 的其他字段保留');
105
+ assert.equal(slimmed[1], blocks[1], '未变化的块保持原引用');
106
+ });
107
+
108
+ // ===== JSON 文档:GT-17「不改 JSON 结构」=====
109
+ // code_run 的 content 恒为 JSON 文本(transport.renderJson),所以 JSON 路径绝不能按行
110
+ // 折叠顶层,只能递归压缩字符串值内部:键、数组长度、类型必须一个不差。
111
+
112
+ /** 一份 JSON 字符串值内部可折叠的重复块:40 行 × 60 字符。 */
113
+ const REPEATED_LINES = Array(40).fill(RULE).join('\n');
114
+
115
+ test('code_run 风格 JSON:只有字符串值内部折叠,JSON 结构 / 键 / 数组长度 / 类型不变', () => {
116
+ const json = JSON.stringify({
117
+ logs: [REPEATED_LINES, 'Error: boom failed'],
118
+ result: { ok: true, count: 3 },
119
+ }, null, 2);
120
+
121
+ const out = slimToolOutput(json);
122
+ const parsed = JSON.parse(out); // 不是合法 JSON 时这里就抛错
123
+
124
+ assert.deepEqual(Object.keys(parsed), ['logs', 'result'], '键与顺序不变');
125
+ assert.equal(parsed.logs.length, 2, '没有相邻重复元素时数组长度不变');
126
+ assert.equal(parsed.logs[1], 'Error: boom failed', 'logs 内的错误行保留');
127
+ assert.equal(typeof parsed.logs[0], 'string');
128
+ assert.match(parsed.logs[0], /\[\.\.\. 39 identical lines collapsed\]/, 'marker 是字符串内容');
129
+ assert.equal(typeof parsed.result.ok, 'boolean');
130
+ assert.equal(parsed.result.count, 3, '数字类型与值不变');
131
+ assert.ok(out.length < json.length, '压缩后确实更短');
132
+
133
+ const bareMarker = out.split('\n').some((line) => /^\s*\[\.\.\. .*\]\s*$/.test(line));
134
+ assert.equal(bareMarker, false, '顶层不出现裸 marker 行(marker 只能在字符串内)');
135
+ });
136
+
137
+ test('嵌套数组 / 对象里的长字符串同样只压缩内部,容器形状不变', () => {
138
+ const json = JSON.stringify({ a: [{ b: REPEATED_LINES }], c: [[REPEATED_LINES]] }, null, 2);
139
+ const parsed = JSON.parse(slimToolOutput(json));
140
+ assert.equal(parsed.a.length, 1);
141
+ assert.equal(Array.isArray(parsed.a[0]), false);
142
+ assert.match(parsed.a[0].b, /identical lines collapsed/);
143
+ assert.equal(parsed.c.length, 1);
144
+ assert.equal(parsed.c[0].length, 1, '二维数组内层长度不变');
145
+ assert.match(parsed.c[0][0], /identical lines collapsed/);
146
+ });
147
+
148
+ test('JSON 里全是受保护行时不折叠,原文逐字返回', () => {
149
+ const errors = Array(40).fill('Error: boom failed').join('\n');
150
+ const json = JSON.stringify({ logs: errors }, null, 2);
151
+ assert.equal(slimToolOutput(json), json, '没有任何可折叠字符串时原样返回(不重排格式)');
152
+ });
153
+
154
+ test('没有可压缩字符串的 JSON 原样返回:不改缩进、不重排', () => {
155
+ const json = JSON.stringify({ note: 'x'.repeat(2100), n: 1 }); // 单行 JSON,超过阈值
156
+ assert.equal(slimToolOutput(json), json);
157
+ });
158
+
159
+ test('含超长整数 token 的 JSON 完全不碰(避免 JSON.parse 的精度损失)', () => {
160
+ const json = JSON.stringify({ big: 9223372036854775807, logs: [REPEATED_LINES] }, null, 2);
161
+ assert.equal(slimToolOutput(json), json);
162
+ });
163
+
164
+ // ===== 真实 code_run 形状:logs 是 string[],重复日志是数组里多个相同元素 =====
165
+
166
+ /** 一条普通日志:60 条相同元素就是当前设计的零压缩反例。 */
167
+ const LOG_LINE = '[dsh] polling workspace/index: no changes';
168
+ /** 一条错误日志:受保护,永不折叠。 */
169
+ const ERROR_LOG = 'Error: ECONNREFUSED 127.0.0.1:5432';
170
+
171
+ test('60 条相同 log:折叠为「一条 + marker 元素」,显著变短且仍是合法 JSON', () => {
172
+ const json = JSON.stringify({ logs: Array(60).fill(LOG_LINE), result: { ok: true } }, null, 2);
173
+ const out = slimToolOutput(json);
174
+ const parsed = JSON.parse(out);
175
+
176
+ assert.deepEqual(parsed.logs, [LOG_LINE, '[... 59 identical lines collapsed]'], '保留第一条 + marker 元素');
177
+ assert.deepEqual(Object.keys(parsed), ['logs', 'result'], '键不变');
178
+ assert.equal(parsed.result.ok, true, '类型不变');
179
+ assert.ok(out.length < json.length / 2, '显著变短(至少减半)');
180
+ assert.equal(out.split('\n').some((line) => /^\s*\[\.\.\. .*\]\s*$/.test(line)), false, '顶层无裸 marker 行');
181
+ });
182
+
183
+ test('重复的错误行元素永不折叠,普通重复日志照常折叠', () => {
184
+ const logs = [ERROR_LOG, ERROR_LOG, ERROR_LOG, ...Array(60).fill(LOG_LINE)];
185
+ const json = JSON.stringify({ logs }, null, 2);
186
+ const parsed = JSON.parse(slimToolOutput(json));
187
+
188
+ assert.equal(parsed.logs.filter((line) => line === ERROR_LOG).length, 3, '错误行元素一个不少');
189
+ assert.equal(parsed.logs.filter((line) => line === LOG_LINE).length, 1, '普通重复折叠为一条');
190
+ assert.ok(parsed.logs.includes('[... 59 identical lines collapsed]'), 'marker 元素存在');
191
+ assert.equal(parsed.logs.length, 5);
192
+ });
193
+
194
+ test('非重复的字符串数组原样返回(不重排、不改缩进)', () => {
195
+ const logs = Array.from({ length: 60 }, (_, index) => `log line ${index}`);
196
+ const json = JSON.stringify({ logs }, null, 2);
197
+ assert.equal(slimToolOutput(json), json);
198
+ });
199
+
200
+ test('只有 2 个相邻相同元素时不折叠(N >= 2 才折叠)', () => {
201
+ const logs = [LOG_LINE, LOG_LINE, ...Array.from({ length: 40 }, (_, index) => `unique line ${index}`)];
202
+ const json = JSON.stringify({ logs, note: 'y'.repeat(2100) }, null, 2);
203
+ const parsed = JSON.parse(slimToolOutput(json));
204
+ assert.equal(parsed.logs.length, 42, '数组长度保持');
205
+ assert.equal(parsed.logs.filter((line) => line === LOG_LINE).length, 2);
206
+ assert.equal(parsed.logs.some((line) => line.includes('collapsed')), false);
207
+ });
208
+
209
+ test('数组里的非字符串元素不参与折叠', () => {
210
+ const json = JSON.stringify({ items: [1, 1, 1, { a: 1 }, { a: 1 }], note: 'z'.repeat(2100) }, null, 2);
211
+ assert.equal(slimToolOutput(json), json);
212
+ });
@@ -0,0 +1,20 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { readFile } from "node:fs/promises";
4
+ import { join } from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+
7
+ const ROOT = fileURLToPath(new URL("..", import.meta.url));
8
+
9
+ test("package.json 骨架字段", async () => {
10
+ const pkg = JSON.parse(await readFile(join(ROOT, "package.json"), "utf8"));
11
+ assert.equal(pkg.name, "dsh-lean-router");
12
+ assert.match(pkg.version, /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/);
13
+ assert.equal(pkg.license, "MIT");
14
+ assert.equal(pkg.type, "module");
15
+ assert.equal(pkg.main, "lib/index.js");
16
+ // 上限 <0.2.4-0:DSH 用 semver.satisfies(..., { includePrerelease: true }) 校验,
17
+ // 旧的 <0.2.3-0 会把 0.2.3-alpha.2 判为不兼容并拦截激活。
18
+ assert.equal(pkg.engines.dsh, ">=0.2.1-rc.5 <0.2.4-0");
19
+ assert.equal(pkg.dsh.bundle.patch, "./cordis.patch.yml");
20
+ });
@@ -0,0 +1,45 @@
1
+ // test/patch-yaml.test.mjs - 补丁 YAML 解析回归(dsh 用 js-yaml + !!js 自定义标签装载 overlay)。
2
+ import test from "node:test";
3
+ import assert from "node:assert/strict";
4
+ import { readFileSync, readdirSync } from "node:fs";
5
+ import { fileURLToPath } from "node:url";
6
+ import { join, dirname } from "node:path";
7
+ import { createRequire } from "node:module";
8
+
9
+ const require = createRequire(import.meta.url);
10
+ const yaml = require("js-yaml");
11
+ const root = join(dirname(fileURLToPath(import.meta.url)), "..");
12
+
13
+ const jsType = new yaml.Type("tag:yaml.org,2002:js", { kind: "scalar", construct: (data) => ({ __js: data }) });
14
+ const schema = yaml.DEFAULT_SCHEMA.extend([jsType]);
15
+
16
+ function parseFile(path) {
17
+ return yaml.load(readFileSync(path, "utf8"), { schema });
18
+ }
19
+
20
+ test("cordis.patch.yml 可被 dsh 等价解析器装载", () => {
21
+ const doc = parseFile(join(root, "cordis.patch.yml"));
22
+ assert.ok(Array.isArray(doc), "顶层必须是操作数组");
23
+ assert.equal(doc.length, 8, "8 个顶层操作");
24
+ const rows = doc.flatMap((op) => op.insert ?? []);
25
+ assert.ok(rows.some((row) => row.id === "preset-lean-router"), "含 preset-lean-router 行");
26
+ });
27
+
28
+ test("全部 presets/base 补丁片段可解析", () => {
29
+ const dir = join(root, "presets", "base");
30
+ const files = readdirSync(dir).filter((f) => f.endsWith(".yml"));
31
+ assert.ok(files.length >= 5, "至少 5 个片段");
32
+ for (const f of files) {
33
+ const doc = parseFile(join(dir, f));
34
+ assert.ok(Array.isArray(doc), f + " 顶层必须是操作数组");
35
+ }
36
+ });
37
+
38
+ test("ptc-runtime 是宿主层插件,不得出现在 preset 内(1.0.3 事故回归)", () => {
39
+ const doc = parseFile(join(root, "presets", "base", "frag-preset.patch.yml"));
40
+ assert.ok(Array.isArray(doc), "frag 是裸行数组");
41
+ const preset = doc.find((p) => p.id === "preset-lean-router");
42
+ assert.ok(preset, "preset 行存在");
43
+ const row = preset.config.plugins.find((p) => p.id === "ptc-runtime");
44
+ assert.equal(row, undefined, "ptc-runtime 由宿主 dsh-base/cordis.patch.yml 挂载;放进 preset 会让整条 preset 激活失败、从预设列表消失");
45
+ });