skillfit 0.11.0 → 0.13.0

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 (172) hide show
  1. package/README.md +68 -104
  2. package/README.zh-CN.md +68 -101
  3. package/benches/README.md +6 -2
  4. package/dist/cli.js +28 -16
  5. package/dist/commands/bench-calibration.js +5 -1
  6. package/dist/commands/bench-check-report.js +1 -34
  7. package/dist/commands/bench-draft.js +167 -0
  8. package/dist/commands/bench-draft.test.js +168 -0
  9. package/dist/commands/bench-manage.js +5 -4
  10. package/dist/commands/bench-source.js +101 -0
  11. package/dist/commands/bench-source.test.js +84 -0
  12. package/dist/commands/bench.js +157 -328
  13. package/dist/commands/eval-api-failure.test.js +46 -0
  14. package/dist/commands/eval-layout.test.js +126 -0
  15. package/dist/commands/eval-preflight-error.js +9 -0
  16. package/dist/commands/eval-preflight.js +4 -11
  17. package/dist/commands/eval-report.js +6 -459
  18. package/dist/commands/eval.js +7 -32
  19. package/dist/commands/install.js +14 -98
  20. package/dist/harness/agent-preflight.js +18 -2
  21. package/dist/harness/bench-check.js +277 -0
  22. package/dist/harness/bench-diagnostics.js +34 -0
  23. package/dist/harness/bench-location.js +29 -0
  24. package/dist/harness/bench-location.test.js +33 -0
  25. package/dist/harness/bench.js +8 -3
  26. package/dist/harness/eval-acceptance.js +1 -1
  27. package/dist/harness/eval-audit.js +2 -2
  28. package/dist/harness/eval-manifest.js +456 -0
  29. package/dist/harness/evaluation-layout.js +30 -0
  30. package/dist/harness/executors/api.js +20 -7
  31. package/dist/harness/executors/cli.js +15 -25
  32. package/dist/harness/experiment-session.js +5 -15
  33. package/dist/harness/hash.js +3 -1
  34. package/dist/harness/runner.js +5 -4
  35. package/dist/harness/single-arm-audit.js +1 -1
  36. package/dist/harness/trigger.js +1 -1
  37. package/dist/harness/verifier-timeout.js +8 -0
  38. package/dist/harness/verifier-timeout.test.js +76 -0
  39. package/dist/install/constants.js +1 -0
  40. package/dist/install/transaction.js +112 -0
  41. package/docs/README.md +65 -0
  42. package/docs/architecture.md +86 -0
  43. package/docs/archive-delivery.md +83 -0
  44. package/docs/archive-inventory.md +91 -0
  45. package/docs/bench-authoring.md +23 -3
  46. package/docs/bench-drafting.md +75 -0
  47. package/docs/case-management.md +12 -1
  48. package/docs/eval-agent-preflight.md +15 -2
  49. package/docs/eval-costs.md +28 -2
  50. package/docs/eval-planning.md +14 -0
  51. package/docs/evaluation-input-snapshots.md +20 -4
  52. package/docs/evaluation-reports.md +1 -1
  53. package/docs/first-real-eval.md +28 -3
  54. package/docs/growth-roadmap-2026-10.md +23 -18
  55. package/docs/package-contents.md +73 -0
  56. package/docs/plans/2026-10-17-workflow-foundations.md +37 -2
  57. package/docs/plans/2026-10-20-archive-replay-verification.json +125 -0
  58. package/docs/plans/2026-10-20-archive-source-verification.json +256 -0
  59. package/docs/plans/2026-10-20-delivery-verification.json +146 -0
  60. package/docs/plans/2026-10-20-docs-architecture-cleanup.md +233 -0
  61. package/docs/plans/2026-10-20-install-transactions-and-archive-delivery.md +233 -0
  62. package/docs/plans/2026-10-21-npm-0.13.0-release.md +41 -0
  63. package/docs/releases/0.11.0-ci-registry-install.json +130 -0
  64. package/docs/releases/0.11.0-feature-smoke.json +1576 -0
  65. package/docs/releases/0.11.0-local-attempt-1.json +24 -0
  66. package/docs/releases/0.11.0-local-attempt-1.log +19 -0
  67. package/docs/releases/0.11.0-local-registry-install.json +25 -0
  68. package/docs/releases/0.11.0-registry-metadata.json +33 -0
  69. package/docs/releases/0.11.0-signatures.txt +12 -0
  70. package/docs/releases/0.11.0-verification.json +95 -0
  71. package/docs/releases/0.11.0.md +54 -11
  72. package/docs/releases/0.12.0-attestation-check.json +22 -0
  73. package/docs/releases/0.12.0-attestations.json +155 -0
  74. package/docs/releases/0.12.0-ci-registry-install.json +90 -0
  75. package/docs/releases/0.12.0-feature-smoke.json +34 -0
  76. package/docs/releases/0.12.0-feature-smoke.mjs +73 -0
  77. package/docs/releases/0.12.0-foundations-smoke.json +1576 -0
  78. package/docs/releases/0.12.0-local-registry-install.json +75 -0
  79. package/docs/releases/0.12.0-preparation-attempt-1.json +22 -0
  80. package/docs/releases/0.12.0-registry-metadata.json +96 -0
  81. package/docs/releases/0.12.0-signatures.txt +6 -0
  82. package/docs/releases/0.12.0-verification.json +99 -0
  83. package/docs/releases/0.12.0.md +82 -0
  84. package/docs/releases/0.13.0-feature-smoke.mjs +114 -0
  85. package/docs/releases/0.13.0-preparation.json +102 -0
  86. package/docs/releases/0.13.0.md +61 -0
  87. package/docs/releases/archive-delivery-smoke.mjs +37 -0
  88. package/docs/reproducible-offline-example.md +1 -1
  89. package/docs/schemas/agent-preflight.schema.json +1 -1
  90. package/docs/verifier-contract.md +9 -0
  91. package/evidence/README.md +24 -1
  92. package/evidence/archive-catalog.v1.json +8044 -0
  93. package/evidence/fetch-archives.mjs +211 -0
  94. package/package.json +9 -2
  95. package/skills/skillfit/SKILL.md +25 -5
  96. package/dist/cli.test.js +0 -193
  97. package/dist/commands/bench-calibration.test.js +0 -237
  98. package/dist/commands/bench-check-json.test.js +0 -242
  99. package/dist/commands/bench-manage.test.js +0 -87
  100. package/dist/commands/bench.test.js +0 -1162
  101. package/dist/commands/bundle.test.js +0 -142
  102. package/dist/commands/calibration-cli.test.js +0 -145
  103. package/dist/commands/doctor.test.js +0 -280
  104. package/dist/commands/eval-agent-preflight.test.js +0 -245
  105. package/dist/commands/eval-export-modes.test.js +0 -350
  106. package/dist/commands/eval-export.test.js +0 -279
  107. package/dist/commands/eval-interruption.test.js +0 -238
  108. package/dist/commands/eval-preflight.test.js +0 -382
  109. package/dist/commands/eval-report.test.js +0 -367
  110. package/dist/commands/eval.test.js +0 -503
  111. package/dist/commands/evaluation-report.test.js +0 -243
  112. package/dist/commands/install.test.js +0 -555
  113. package/dist/commands/replay-cancellation.test.js +0 -105
  114. package/dist/commands/report.test.js +0 -110
  115. package/dist/commands/setup.test.js +0 -150
  116. package/dist/commands/upstream.test.js +0 -139
  117. package/dist/commands/workflow-entrypoints.test.js +0 -137
  118. package/dist/docs.test.js +0 -154
  119. package/dist/frontmatter.test.js +0 -49
  120. package/dist/harness/bench.test.js +0 -109
  121. package/dist/harness/bundle.test.js +0 -71
  122. package/dist/harness/codex-usage.test.js +0 -87
  123. package/dist/harness/costs.test.js +0 -92
  124. package/dist/harness/eval-budget.test.js +0 -237
  125. package/dist/harness/eval-component.test.js +0 -770
  126. package/dist/harness/eval-efficiency.test.js +0 -56
  127. package/dist/harness/execution-timing.test.js +0 -61
  128. package/dist/harness/executors/api.test.js +0 -136
  129. package/dist/harness/executors/cli.test.js +0 -510
  130. package/dist/harness/executors/mock.test.js +0 -43
  131. package/dist/harness/experiment-session.test.js +0 -317
  132. package/dist/harness/installed-skill.test.js +0 -162
  133. package/dist/harness/interruption.test.js +0 -31
  134. package/dist/harness/judge-accounting.test.js +0 -216
  135. package/dist/harness/judge.test.js +0 -181
  136. package/dist/harness/kimi-usage.test.js +0 -62
  137. package/dist/harness/native-diff.test.js +0 -53
  138. package/dist/harness/oss-lru-cache.test.js +0 -79
  139. package/dist/harness/oss-normalize-url.test.js +0 -64
  140. package/dist/harness/oss-regression-witness.test.js +0 -89
  141. package/dist/harness/oss-skill-followup.test.js +0 -59
  142. package/dist/harness/prompt.test.js +0 -48
  143. package/dist/harness/receipts.test.js +0 -148
  144. package/dist/harness/report.test.js +0 -297
  145. package/dist/harness/runner.test.js +0 -635
  146. package/dist/harness/skill-revision.test.js +0 -148
  147. package/dist/harness/stats.test.js +0 -124
  148. package/dist/harness/target.test.js +0 -60
  149. package/dist/harness/trigger.test.js +0 -261
  150. package/dist/harness/verifier-summary.test.js +0 -99
  151. package/dist/harness/verifier.test.js +0 -128
  152. package/dist/harness/waza-behavior.test.js +0 -139
  153. package/dist/mcp/probe.test.js +0 -139
  154. package/evidence/artifacts/2026-10-12-diagnosing-revision/calibration-records.tar.gz +0 -0
  155. package/evidence/artifacts/2026-10-12-diagnosing-revision/interrupted-records.tar.gz +0 -0
  156. package/evidence/artifacts/2026-10-12-diagnosing-revision/validation-records.tar.gz +0 -0
  157. package/evidence/artifacts/2026-10-12-diagnosing-v2/regression-records.tar.gz +0 -0
  158. package/evidence/artifacts/2026-10-12-diagnosing-v2/transfer-records.tar.gz +0 -0
  159. package/evidence/artifacts/2026-10-12-normalize-url-v2-available/readiness-records.tar.gz +0 -0
  160. package/evidence/artifacts/2026-10-12-normalize-url-v2-comparison/records.tar.gz +0 -0
  161. package/evidence/artifacts/2026-10-12-normalize-url-v2-recovery/records.tar.gz +0 -0
  162. package/evidence/artifacts/2026-10-12-normalize-url-v2-validated/records.tar.gz +0 -0
  163. package/evidence/artifacts/2026-10-13-debugging-completed-development/package.tar.gz +0 -0
  164. package/evidence/artifacts/2026-10-13-debugging-controls-and-sleep-stop/package.tar.gz +0 -0
  165. package/evidence/artifacts/2026-10-13-debugging-development-stops/package.tar.gz +0 -0
  166. package/evidence/artifacts/2026-10-14-debugging-followup-routing-stop/package.tar.gz +0 -0
  167. package/evidence/artifacts/2026-10-14-debugging-independent-validation/package.tar.gz +0 -0
  168. package/evidence/artifacts/2026-10-14-debugging-reading-pilot-and-cost-review/package.tar.gz +0 -0
  169. package/evidence/artifacts/2026-10-14-debugging-spending-stop/package.tar.gz +0 -0
  170. package/evidence/artifacts/2026-10-15-independent-comparison-regression-stop/package.tar.gz +0 -0
  171. package/evidence/artifacts/2026-10-15-native-diff-mechanism/package.tar.gz +0 -0
  172. package/evidence/artifacts/2026-10-15-receiver-mechanism-stop/package.tar.gz +0 -0
@@ -1,142 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { promises as fs } from 'node:fs';
4
- import * as os from 'node:os';
5
- import * as path from 'node:path';
6
- import test from 'node:test';
7
- import { runInstall } from './install.js';
8
- import { runBundleExport } from './bundle.js';
9
- async function fixture(t) {
10
- const root = await fs.mkdtemp(path.join(os.tmpdir(), 'skillfit-bundle-'));
11
- t.after(async () => { await fs.rm(root, { recursive: true, force: true }); });
12
- const home = path.join(root, 'source-home');
13
- const targetHome = path.join(root, 'target-home');
14
- await fs.mkdir(path.join(home, '.codex'), { recursive: true });
15
- await fs.mkdir(targetHome, { recursive: true });
16
- return { root, home, targetHome };
17
- }
18
- test('exports a portable Codex profile and installs it into a fresh home', async (t) => {
19
- const { root, home, targetHome } = await fixture(t);
20
- const skill = path.join(home, '.agents', 'skills', 'example');
21
- await fs.mkdir(skill, { recursive: true });
22
- await fs.writeFile(path.join(skill, 'SKILL.md'), '---\nname: example\ndescription: Handle example tasks.\n---\nDo the example.\n');
23
- const icon = Buffer.from([0, 0xff, 0x89, 0x50]);
24
- await fs.writeFile(path.join(skill, 'icon.png'), icon);
25
- for (const artifact of ['SKILL.md.skillfit-bak', 'SKILL.md.123.skillfit-staged', 'SKILL.md.123.skillfit-restore']) {
26
- await fs.writeFile(path.join(skill, artifact), 'Old private instructions');
27
- }
28
- await fs.writeFile(path.join(home, '.codex', 'AGENTS.md'), '# My global rules\n\nUse concise answers.\n');
29
- const outputDir = path.join(root, 'personal-codex');
30
- await runBundleExport({ outputDir, homeDir: home, skillNames: ['example'], yes: true, log: () => { } });
31
- const manifest = JSON.parse(await fs.readFile(path.join(outputDir, 'profile.json'), 'utf8'));
32
- assert.deepEqual(manifest.agents, ['codex']);
33
- assert.deepEqual(manifest.skills, [{ name: 'example', source: 'skills/example' }]);
34
- assert.deepEqual(await fs.readFile(path.join(outputDir, 'skills', 'example', 'icon.png')), icon);
35
- for (const artifact of ['SKILL.md.skillfit-bak', 'SKILL.md.123.skillfit-staged', 'SKILL.md.123.skillfit-restore']) {
36
- await assert.rejects(fs.stat(path.join(outputDir, 'skills', 'example', artifact)), { code: 'ENOENT' });
37
- }
38
- const rules = await fs.readFile(path.join(outputDir, 'rules', 'global.md'), 'utf8');
39
- assert.match(rules, /My global rules/);
40
- assert.match(rules, /example/);
41
- await runInstall({
42
- profile: 'ignored', profilePath: outputDir, agent: 'codex', homeDir: targetHome,
43
- projectDir: root, env: { PATH: '' }, yes: true, log: () => { },
44
- });
45
- assert.deepEqual(await fs.readFile(path.join(targetHome, '.agents', 'skills', 'example', 'icon.png')), icon);
46
- assert.match(await fs.readFile(path.join(targetHome, '.codex', 'AGENTS.md'), 'utf8'), /My global rules/);
47
- const standaloneHome = path.join(root, 'standalone-home');
48
- await fs.mkdir(standaloneHome);
49
- const result = spawnSync(process.execPath, [path.join(outputDir, 'setup.mjs'), '--yes'], {
50
- cwd: root,
51
- env: { ...process.env, HOME: standaloneHome, USERPROFILE: standaloneHome, CODEX_HOME: path.join(standaloneHome, 'codex-home') },
52
- encoding: 'utf8',
53
- });
54
- assert.equal(result.status, 0, result.stderr);
55
- assert.deepEqual(await fs.readFile(path.join(standaloneHome, '.agents', 'skills', 'example', 'icon.png')), icon);
56
- assert.match(await fs.readFile(path.join(standaloneHome, 'codex-home', 'AGENTS.md'), 'utf8'), /My global rules/);
57
- await assert.rejects(runInstall({
58
- profile: 'ignored', profilePath: outputDir, agent: 'codex', homeDir: targetHome,
59
- projectDir: root, env: { PATH: '' }, project: true, yes: true, log: () => { },
60
- }), /user scope/);
61
- });
62
- test('export selects locally installed skills used in multiple sessions by default', async (t) => {
63
- const { root, home } = await fixture(t);
64
- for (const name of ['often', 'once']) {
65
- const dir = path.join(home, '.agents', 'skills', name);
66
- await fs.mkdir(dir, { recursive: true });
67
- await fs.writeFile(path.join(dir, 'SKILL.md'), `---\nname: ${name}\ndescription: ${name} tasks.\n---\nDo it.\n`);
68
- }
69
- const outputDir = path.join(root, 'personal-codex');
70
- await runBundleExport({
71
- outputDir, homeDir: home, yes: true, log: () => { },
72
- loadUsage: async () => [
73
- { name: 'often', sessionCount: 3 },
74
- { name: 'once', sessionCount: 1 },
75
- { name: 'plugin-owned', sessionCount: 20 },
76
- ],
77
- });
78
- const manifest = JSON.parse(await fs.readFile(path.join(outputDir, 'profile.json'), 'utf8'));
79
- assert.deepEqual(manifest.skills.map((skill) => skill.name), ['often']);
80
- });
81
- test('exported global guidance preserves user-invoked-only skill routing', async (t) => {
82
- const { root, home } = await fixture(t);
83
- const skillDir = path.join(home, '.agents', 'skills', 'explicit-skill');
84
- await fs.mkdir(skillDir, { recursive: true });
85
- await fs.writeFile(path.join(skillDir, 'SKILL.md'), '---\nname: explicit-skill\ndescription: Explicit writing help.\n---\nUse when named.\n');
86
- await fs.mkdir(path.join(skillDir, 'agents'));
87
- await fs.writeFile(path.join(skillDir, 'agents', 'openai.yaml'), 'interface:\n display_name: Explicit Skill\npolicy:\n allow_implicit_invocation: false\n');
88
- const outputDir = path.join(root, 'portable-codex');
89
- await runBundleExport({ outputDir, homeDir: home, skillNames: ['explicit-skill'], yes: true, log: () => { } });
90
- const rules = await fs.readFile(path.join(outputDir, 'rules', 'global.md'), 'utf8');
91
- assert.match(rules, /Available for implicit routing in this portable profile: none/);
92
- assert.match(rules, /User-invoked only: `explicit-skill`/);
93
- });
94
- test('export recognizes flow-style and quoted invocation policies', async (t) => {
95
- const { root, home } = await fixture(t);
96
- const skillDir = path.join(home, '.agents', 'skills', 'explicit-skill');
97
- await fs.mkdir(path.join(skillDir, 'agents'), { recursive: true });
98
- await fs.writeFile(path.join(skillDir, 'SKILL.md'), '---\nname: explicit-skill\ndescription: Explicit writing help.\n---\nUse when named.\n');
99
- for (const [index, metadata] of [
100
- 'policy: { allow_implicit_invocation: false }\n',
101
- 'policy:\n allow_implicit_invocation: "false"\n',
102
- ].entries()) {
103
- await fs.writeFile(path.join(skillDir, 'agents', 'openai.yaml'), metadata);
104
- const outputDir = path.join(root, `portable-codex-${index}`);
105
- await runBundleExport({ outputDir, homeDir: home, skillNames: ['explicit-skill'], yes: true, log: () => { } });
106
- const rules = await fs.readFile(path.join(outputDir, 'rules', 'global.md'), 'utf8');
107
- assert.match(rules, /User-invoked only: `explicit-skill`/);
108
- }
109
- });
110
- test('export dry-run writes nothing and refuses an existing destination', async (t) => {
111
- const { root, home } = await fixture(t);
112
- const outputDir = path.join(root, 'personal-codex');
113
- await runBundleExport({ outputDir, homeDir: home, skillNames: [], dryRun: true, log: () => { } });
114
- await assert.rejects(fs.stat(outputDir), { code: 'ENOENT' });
115
- await fs.mkdir(outputDir);
116
- await fs.writeFile(path.join(outputDir, 'keep.txt'), 'keep');
117
- await assert.rejects(runBundleExport({ outputDir, homeDir: home, skillNames: [], yes: true, log: () => { } }), /already exists/);
118
- assert.equal(await fs.readFile(path.join(outputDir, 'keep.txt'), 'utf8'), 'keep');
119
- });
120
- test('upstream export pins a GitHub skill and keeps a self-written skill local', async (t) => {
121
- const { root, home } = await fixture(t);
122
- for (const name of ['local-skill']) {
123
- const dir = path.join(home, '.agents', 'skills', name);
124
- await fs.mkdir(dir, { recursive: true });
125
- await fs.writeFile(path.join(dir, 'SKILL.md'), `---\nname: ${name}\ndescription: ${name} tasks.\n---\nUse it.\n`);
126
- }
127
- const lockPath = path.join(root, 'sources.json');
128
- await fs.writeFile(lockPath, JSON.stringify({ version: 1, skills: [{
129
- name: 'remote-skill', repo: 'owner/repo', commit: 'a'.repeat(40), path: 'skills/remote-skill',
130
- files: [{ path: 'SKILL.md', sha256: 'b'.repeat(64) }], explicitOnly: true,
131
- }], localSkills: ['local-skill'] }));
132
- const outputDir = path.join(root, 'portable-codex');
133
- await runBundleExport({ outputDir, homeDir: home, upstreamLockPath: lockPath, yes: true, log: () => { }, loadUsage: async () => { throw new Error('usage selection should not run'); } });
134
- await assert.rejects(fs.stat(path.join(outputDir, 'skills', 'remote-skill')), { code: 'ENOENT' });
135
- assert.match(await fs.readFile(path.join(outputDir, 'skills', 'local-skill', 'SKILL.md'), 'utf8'), /Use it/);
136
- const lock = JSON.parse(await fs.readFile(path.join(outputDir, 'upstream.lock.json'), 'utf8'));
137
- assert.deepEqual(lock.skills.map((skill) => skill.name), ['remote-skill']);
138
- assert.deepEqual(lock.localSkills, ['local-skill']);
139
- assert.match(await fs.readFile(path.join(outputDir, 'setup.mjs'), 'utf8'), /prepareUpstreamProfile/);
140
- const rules = await fs.readFile(path.join(outputDir, 'rules', 'global.md'), 'utf8');
141
- assert.match(rules, /User-invoked only: `remote-skill`/);
142
- });
@@ -1,145 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
4
- import { tmpdir } from 'node:os';
5
- import { join } from 'node:path';
6
- import { fileURLToPath } from 'node:url';
7
- import { test } from 'node:test';
8
- import { runBenchInit } from './bench.js';
9
- const CLI = fileURLToPath(new URL('../cli.js', import.meta.url));
10
- const budget = { input: 100, cachedInput: 100, uncachedInput: 100, output: 100, durationSeconds: 60 };
11
- async function fixture(t) {
12
- const root = mkdtempSync(join(tmpdir(), 'skillfit-calibration-cli-')), dir = join(root, 'bench with spaces');
13
- t.after(() => rmSync(root, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 }));
14
- await runBenchInit({ dir, kind: 'command', yes: true, log: () => { } });
15
- const home = join(root, 'home'), sentinel = join(root, 'unexpected-probe'), budgetPath = join(root, 'budget.json');
16
- mkdirSync(home);
17
- writeFileSync(budgetPath, JSON.stringify(budget));
18
- const env = { ...Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toUpperCase() !== 'PATH')),
19
- PATH: '', HOME: home, USERPROFILE: home, CODEX_HOME: join(home, 'codex') };
20
- const manifest = JSON.parse(readFileSync(join(dir, 'bench.json'), 'utf8'));
21
- manifest.tasks.push({ ...manifest.tasks[0], id: 'second-task' });
22
- writeFileSync(join(dir, 'bench.json'), JSON.stringify(manifest));
23
- writeFileSync(join(dir, 'verifiers/example-task.mjs'), `import{writeFileSync}from'node:fs';writeFileSync(${JSON.stringify(sentinel)},'must never run');process.exit(1);`);
24
- const args = ['bench', 'check', dir, '--calibrate', '--json', '--agent', 'codex', '--run-group', 'reviewed', '--runs-root', join(root, 'results')];
25
- const cli = (extra, status, base = args) => {
26
- const result = spawnSync(process.execPath, [CLI, ...base, ...extra], { cwd: root, env, encoding: 'utf8', timeout: 20_000 });
27
- assert.equal(result.status, status, result.stderr || result.stdout);
28
- const data = JSON.parse(result.stdout);
29
- assert.equal(data.schemaVersion, 1);
30
- assert.ok(!existsSync(sentinel), 'plans and rejected executions must not run even the verifier');
31
- assert.ok(!existsSync(join(root, 'runs')));
32
- assert.ok(!existsSync(join(root, 'results')));
33
- return { data, stderr: result.stderr };
34
- };
35
- return { root, dir, sentinel, budgetPath, args, cli, env };
36
- }
37
- test('public calibration JSON preview is read-only and retains blocked CLI, capabilities, unknown login and effective settings', async (t) => {
38
- const f = await fixture(t);
39
- const settings = ['--dry-run', '--trials', '3', '--max-calls', '3', '--task', 'second-task', '--input', 'workspace',
40
- '--executor-timeout-seconds', '13', '--spending-budget', f.budgetPath];
41
- const first = f.cli(settings, 0), plan = first.data.plan;
42
- assert.equal(first.stderr, '');
43
- assert.equal(first.data.kind, 'skillfit.calibration-result');
44
- assert.equal(first.data.status, 'planned');
45
- assert.equal(plan.kind, 'skillfit.calibration-plan');
46
- assert.match(plan.planSha256, /^[0-9a-f]{64}$/);
47
- assert.match(plan.implementationSha256, /^[0-9a-f]{64}$/);
48
- assert.match(plan.bench.sha256, /^[0-9a-f]{64}$/);
49
- assert.deepEqual(plan.bench.taskIds, ['second-task']);
50
- assert.equal(plan.trials, 3);
51
- assert.equal(plan.plannedCalls, 3);
52
- assert.equal(plan.maxCalls, 3);
53
- assert.equal(plan.executorTimeoutSeconds, 13);
54
- assert.equal(plan.inputMode, 'workspace');
55
- assert.deepEqual(plan.spendingBudget, budget);
56
- assert.equal(plan.outputDir, join(f.root, 'results/reviewed'));
57
- assert.equal(plan.casePreflight.status, 'pending');
58
- assert.equal(plan.agentPreflight.status, 'blocked');
59
- assert.ok(plan.agentPreflight.checks.some((check) => check.code === 'CLI_AVAILABLE' && check.status === 'FAIL'));
60
- assert.ok(plan.agentPreflight.checks.some((check) => check.code === 'MATRIX_CAPABILITY' && check.status === 'PASS'));
61
- assert.ok(plan.agentPreflight.checks.some((check) => check.code === 'AUTHENTICATION' && check.status === 'UNKNOWN'));
62
- assert.equal(plan.agentPreflight.cost.modelCalls, 0);
63
- assert.equal(plan.agentPreflight.cost.cliInvocations, 0);
64
- assert.equal(first.data.acceptance.automaticUpgrade, false);
65
- assert.equal(first.data.acceptance.eligibleForUpgrade, false);
66
- assert.deepEqual(f.cli(settings, 0).data, first.data, 'identical effective settings yield a reproducible plan');
67
- });
68
- test('JSON calibration execution requires a current plan and its explicit output group before any call', async (t) => {
69
- const f = await fixture(t);
70
- assert.match(f.cli([], 2).data.error.message, /requires --plan-sha/);
71
- const withoutGroup = f.args.filter((_, index, values) => values[index - 1] !== '--run-group' && values[index] !== '--run-group');
72
- assert.match(f.cli(['--plan-sha', '0'.repeat(64)], 2, withoutGroup).data.error.message, /requires --run-group/);
73
- assert.match(f.cli(['--plan-sha', '0'.repeat(64)], 2).data.error.message, /plan changed/);
74
- assert.match(f.cli(['--dry-run', '--plan-sha', '0'.repeat(64)], 2).data.error.message, /non-dry-run/);
75
- const preview = f.cli(['--dry-run'], 0).data;
76
- const live = f.cli(['--plan-sha', preview.plan.planSha256], 2);
77
- assert.equal(live.data.kind, 'skillfit.eval-error');
78
- assert.equal(live.data.error.code, 'AGENT_PREFLIGHT_FAILED');
79
- assert.equal(live.data.agentPreflight.status, 'blocked');
80
- assert.match(live.data.error.message, /CLI executable is missing/);
81
- assert.doesNotMatch(live.data.error.message, /ENOENT|no such file or directory/i);
82
- });
83
- test('changing a calibration bench, spending lines, task set or executor deadline invalidates its reviewed plan', async (t) => {
84
- for (const change of ['bench', 'budget', 'tasks', 'timeout'])
85
- await t.test(change, async (t) => {
86
- const f = await fixture(t), settings = ['--spending-budget', f.budgetPath];
87
- const preview = f.cli(['--dry-run', ...settings], 0).data;
88
- let altered = [];
89
- if (change === 'bench')
90
- writeFileSync(join(f.dir, 'prompts/example-task.md'), 'A new task.');
91
- if (change === 'budget')
92
- writeFileSync(f.budgetPath, JSON.stringify({ ...budget, input: 101 }));
93
- if (change === 'tasks')
94
- altered = ['--task', 'second-task'];
95
- if (change === 'timeout')
96
- altered = ['--executor-timeout-seconds', '12'];
97
- const live = f.cli([...settings, ...altered, '--plan-sha', preview.plan.planSha256], 2).data;
98
- assert.equal(live.kind, 'skillfit.eval-error');
99
- assert.equal(live.status, 'error');
100
- assert.equal(live.acceptance.eligibleForUpgrade, false);
101
- assert.match(live.error.message, /plan changed/);
102
- });
103
- });
104
- test('invalid calibration task selection, budgets, timeout, output and paired-only settings fail before probes', async (t) => {
105
- const f = await fixture(t), invalidBudget = join(f.root, 'bad-budget.json');
106
- writeFileSync(invalidBudget, JSON.stringify({ ...budget, input: 0 }));
107
- const malformedBudget = join(f.root, 'malformed-budget.json');
108
- writeFileSync(malformedBudget, '{');
109
- const cases = [
110
- [['--task', 'missing'], /Unknown task/],
111
- [['--task', 'second-task', '--task', 'second-task'], /Duplicate task/],
112
- [['--max-calls', '1'], /exceeding --max-calls/],
113
- [['--executor-timeout-seconds', '0'], /executorTimeoutSeconds/],
114
- [['--executor-timeout-seconds', '3601'], /executorTimeoutSeconds/],
115
- [['--executor-timeout-seconds', '1.5'], /executorTimeoutSeconds/],
116
- [['--spending-budget', invalidBudget], /spendingBudget.input/],
117
- [['--spending-budget', malformedBudget], /JSON/],
118
- [['--pair-order', 'balanced'], /requires a paired eval/],
119
- [['--run-group', '../outside'], /Invalid run group/],
120
- ];
121
- for (const [extra, message] of cases) {
122
- const data = f.cli(['--dry-run', ...extra], 2).data;
123
- assert.equal(data.kind, 'skillfit.eval-error');
124
- assert.match(data.error.message, message);
125
- }
126
- });
127
- test('ordinary offline bench JSON retains its own integrity contract while calibration JSON returns a plan', async (t) => {
128
- const f = await fixture(t);
129
- const ordinary = spawnSync(process.execPath, [CLI, 'bench', 'check', f.dir, '--json'], { cwd: f.root, env: f.env, encoding: 'utf8', timeout: 20_000 });
130
- // PATH is deliberately empty, so Node verifier commands cannot start; that is an offline
131
- // integrity failure, distinct from a paid calibration or a model outcome.
132
- assert.equal(ordinary.status, 1, ordinary.stderr || ordinary.stdout);
133
- assert.equal(ordinary.stderr, '');
134
- const data = JSON.parse(ordinary.stdout);
135
- assert.equal(data.kind, 'skillfit.bench-check');
136
- assert.equal(data.scope, 'offline-integrity');
137
- assert.equal(data.status, 'failed');
138
- assert.ok(data.summary.failures > 0);
139
- assert.equal(data.plan, undefined);
140
- assert.ok(!existsSync(f.sentinel));
141
- const preview = f.cli(['--dry-run'], 0).data;
142
- assert.equal(preview.kind, 'skillfit.calibration-result');
143
- assert.equal(preview.status, 'planned');
144
- assert.ok(preview.plan);
145
- });
@@ -1,280 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import path from 'node:path';
5
- import { after, test } from 'node:test';
6
- import { collectDoctorReport, formatDoctorReport, runDoctor, } from './doctor.js';
7
- const VALID_SKILL_MD = '---\nname: demo\ndescription: does things\n---\n\n# Demo\n';
8
- const tempDirs = [];
9
- after(() => {
10
- for (const dir of tempDirs)
11
- rmSync(dir, { recursive: true, force: true });
12
- });
13
- function tempDir() {
14
- const dir = mkdtempSync(path.join(tmpdir(), 'skillfit-doctor-'));
15
- tempDirs.push(dir);
16
- return dir;
17
- }
18
- function makeOptions(homeDir, cwd, extra = {}) {
19
- return { homeDir, cwd, which: () => null, ...extra };
20
- }
21
- function writeFile(root, rel, content) {
22
- const target = path.join(root, ...rel.split('/'));
23
- mkdirSync(path.dirname(target), { recursive: true });
24
- writeFileSync(target, content);
25
- }
26
- function writeSkill(homeDir, skillsDir, name, skillMd) {
27
- const dir = path.join(homeDir, ...skillsDir.split('/'), name);
28
- mkdirSync(dir, { recursive: true });
29
- if (skillMd !== null)
30
- writeFileSync(path.join(dir, 'SKILL.md'), skillMd);
31
- }
32
- function healthChecks(report, agentId, section) {
33
- const agent = report.health.find((h) => h.id === agentId);
34
- assert.ok(agent, `expected health report for ${agentId}`);
35
- const found = agent.sections.find((s) => s.title === section);
36
- assert.ok(found, `expected section ${section}`);
37
- return found.checks;
38
- }
39
- function hasCheck(checks, status, pattern) {
40
- return checks.some((c) => c.status === status && pattern.test(c.message));
41
- }
42
- // parseFrontmatter's own tests live in src/frontmatter.test.ts, next to the single implementation
43
- // doctor and install now share.
44
- test('detects nothing on a clean machine', () => {
45
- const report = collectDoctorReport(makeOptions(tempDir(), tempDir()));
46
- assert.equal(report.detection.length, 3);
47
- assert.ok(report.detection.every((d) => !d.detected && d.evidence.length === 0));
48
- assert.equal(report.health.length, 0);
49
- });
50
- test('detects agents through user dirs and files with evidence', () => {
51
- const home = tempDir();
52
- mkdirSync(path.join(home, '.claude'));
53
- writeFile(home, '.claude.json', '{}');
54
- const report = collectDoctorReport(makeOptions(home, tempDir()));
55
- const claude = report.detection.find((d) => d.id === 'claude-code');
56
- assert.ok(claude?.detected);
57
- assert.ok(claude.evidence.some((e) => e.includes('directory ~/.claude')));
58
- assert.ok(claude.evidence.some((e) => e.includes('file ~/.claude.json')));
59
- assert.equal(report.health.length, 1);
60
- assert.equal(report.health[0]?.id, 'claude-code');
61
- });
62
- test('detects agents through binaries via injected which', () => {
63
- const which = (binary) => (binary === 'codex' ? '/usr/local/bin/codex' : null);
64
- const report = collectDoctorReport(makeOptions(tempDir(), tempDir(), { which }));
65
- const codex = report.detection.find((d) => d.id === 'codex');
66
- assert.ok(codex?.detected);
67
- assert.ok(codex.evidence.some((e) => e.includes('binary "codex"') && e.includes('/usr/local/bin/codex')));
68
- });
69
- test('--agent forces inspection of an undetected agent', () => {
70
- const report = collectDoctorReport(makeOptions(tempDir(), tempDir(), { agent: 'kimi-code' }));
71
- assert.equal(report.health.length, 1);
72
- assert.equal(report.health[0]?.id, 'kimi-code');
73
- assert.equal(report.health[0]?.detected, false);
74
- });
75
- test('unknown agent id throws from the pure function', () => {
76
- assert.throws(() => collectDoctorReport(makeOptions(tempDir(), tempDir(), { agent: 'nope' })), /Unknown agent/);
77
- });
78
- test('small CLAUDE.md passes with line and byte stats', () => {
79
- const home = tempDir();
80
- writeFile(home, '.claude/CLAUDE.md', '# Rules\n\nBe brief.\n');
81
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'Rules');
82
- assert.ok(hasCheck(checks, 'PASS', /~\/\.claude\/CLAUDE\.md — 3 lines, \d+ B/));
83
- });
84
- test('CLAUDE.md over 200 lines warns about bloat', () => {
85
- const home = tempDir();
86
- writeFile(home, '.claude/CLAUDE.md', Array.from({ length: 250 }, (_, i) => `line ${i}`).join('\n'));
87
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'Rules');
88
- assert.ok(hasCheck(checks, 'WARN', /250 lines.*exceeds 200 lines/));
89
- });
90
- test('AGENTS.md over 32 KiB warns about the budget', () => {
91
- const home = tempDir();
92
- writeFile(home, '.codex/AGENTS.md', 'x'.repeat(40 * 1024));
93
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'codex' })), 'codex', 'Rules');
94
- assert.ok(hasCheck(checks, 'WARN', /exceeds the 32 KiB/));
95
- });
96
- test('Codex rules check resolves CODEX_HOME and warns when a global override shadows AGENTS.md', () => {
97
- const home = tempDir();
98
- const codexHome = path.join(home, 'alternate-codex');
99
- writeFile(home, 'alternate-codex/AGENTS.md', '# Portable rules\n');
100
- writeFile(home, 'alternate-codex/AGENTS.override.md', '# Temporary override\n');
101
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), {
102
- agent: 'codex', env: { CODEX_HOME: codexHome },
103
- })), 'codex', 'Rules');
104
- assert.ok(hasCheck(checks, 'PASS', /AGENTS\.md — 1 lines/));
105
- assert.ok(hasCheck(checks, 'WARN', /AGENTS\.override\.md.*shadows.*AGENTS\.md/));
106
- });
107
- test('rules notes from the matrix are surfaced', () => {
108
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), tempDir(), { agent: 'claude-code' })), 'claude-code', 'Rules');
109
- assert.ok(hasCheck(checks, 'INFO', /notes: .*AGENTS\.md requires an @import bridge/));
110
- });
111
- test('claude-code warns when project AGENTS.md lacks a bridge', () => {
112
- const cwd = tempDir();
113
- writeFile(cwd, 'AGENTS.md', '# project rules\n');
114
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), cwd, { agent: 'claude-code' })), 'claude-code', 'Rules');
115
- assert.ok(hasCheck(checks, 'WARN', /does not read it/));
116
- assert.ok(checks.some((c) => c.message.includes('@AGENTS.md')));
117
- });
118
- test('claude-code warns when CLAUDE.md exists without the import', () => {
119
- const cwd = tempDir();
120
- writeFile(cwd, 'AGENTS.md', '# project rules\n');
121
- writeFile(cwd, 'CLAUDE.md', '# Claude rules\n');
122
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), cwd, { agent: 'claude-code' })), 'claude-code', 'Rules');
123
- assert.ok(hasCheck(checks, 'WARN', /does not read it/));
124
- });
125
- test('claude-code passes when CLAUDE.md imports AGENTS.md', () => {
126
- const cwd = tempDir();
127
- writeFile(cwd, 'AGENTS.md', '# project rules\n');
128
- writeFile(cwd, 'CLAUDE.md', '# Claude rules\n\n@AGENTS.md\n');
129
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), cwd, { agent: 'claude-code' })), 'claude-code', 'Rules');
130
- assert.ok(hasCheck(checks, 'PASS', /bridged into CLAUDE\.md/));
131
- });
132
- test('agents that read AGENTS.md natively get no bridge warning', () => {
133
- const cwd = tempDir();
134
- writeFile(cwd, 'AGENTS.md', '# project rules\n');
135
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), cwd, { agent: 'codex' })), 'codex', 'Rules');
136
- assert.ok(!checks.some((c) => c.message.includes('does not read it')));
137
- });
138
- test('skills scan validates SKILL.md frontmatter', () => {
139
- const home = tempDir();
140
- writeSkill(home, '.claude/skills', 'good', VALID_SKILL_MD);
141
- writeSkill(home, '.claude/skills', 'no-file', null);
142
- writeSkill(home, '.claude/skills', 'broken', 'no frontmatter at all');
143
- writeSkill(home, '.claude/skills', 'missing-fields', '---\nname: only\n---\n');
144
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'Skills');
145
- assert.ok(hasCheck(checks, 'PASS', /1 valid skill/));
146
- assert.ok(hasCheck(checks, 'WARN', /no-file — no SKILL\.md/));
147
- assert.ok(hasCheck(checks, 'WARN', /broken\/SKILL\.md — missing or malformed YAML frontmatter/));
148
- assert.ok(hasCheck(checks, 'WARN', /missing-fields\/SKILL\.md — frontmatter missing required field\(s\): description/));
149
- });
150
- test('more than 10 skills triggers an overload warning', () => {
151
- const home = tempDir();
152
- for (let i = 0; i < 11; i++)
153
- writeSkill(home, '.claude/skills', `skill-${i}`, VALID_SKILL_MD);
154
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'Skills');
155
- assert.ok(hasCheck(checks, 'PASS', /11 valid skill/));
156
- assert.ok(hasCheck(checks, 'WARN', /11 skills installed \(> 10\)/));
157
- });
158
- test('codex skills under ~/.codex/skills and CODEX_HOME are visible', () => {
159
- const home = tempDir();
160
- writeSkill(home, '.codex/skills', 'from-codex', VALID_SKILL_MD);
161
- const local = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'codex', env: {} })), 'codex', 'Skills');
162
- assert.ok(hasCheck(local, 'PASS', /1 valid skill/));
163
- assert.ok(!local.some((check) => check.message.includes('~/.codex/skills — not present')));
164
- const relocated = tempDir();
165
- writeSkill(relocated, 'skills', 'moved', VALID_SKILL_MD);
166
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), tempDir(), { agent: 'codex', env: { CODEX_HOME: relocated } })), 'codex', 'Skills');
167
- assert.ok(hasCheck(checks, 'PASS', /1 valid skill/));
168
- });
169
- test('no skills directories is informational', () => {
170
- const checks = healthChecks(collectDoctorReport(makeOptions(tempDir(), tempDir(), { agent: 'claude-code' })), 'claude-code', 'Skills');
171
- assert.ok(hasCheck(checks, 'INFO', /no skills directories present/));
172
- });
173
- test('skill name conflicts between shared and private dirs are flagged', () => {
174
- const home = tempDir();
175
- writeSkill(home, '.kimi-code/skills', 'dup', VALID_SKILL_MD);
176
- writeSkill(home, '.agents/skills', 'dup', VALID_SKILL_MD);
177
- writeSkill(home, '.agents/skills', 'shared-only', VALID_SKILL_MD);
178
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'kimi-code' })), 'kimi-code', 'Skills');
179
- assert.ok(hasCheck(checks, 'PASS', /3 valid skill/));
180
- assert.ok(hasCheck(checks, 'WARN', /skill "dup" exists in both shared \(~\/\.agents\/skills\) and private \(~\/\.kimi-code\/skills\)/));
181
- assert.ok(!checks.some((c) => c.message.includes('"shared-only" exists in both')));
182
- });
183
- test('invalid JSON MCP config is a FAIL', () => {
184
- const home = tempDir();
185
- writeFile(home, '.claude.json', '{ not json');
186
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'MCP');
187
- assert.ok(hasCheck(checks, 'FAIL', /invalid JSON/));
188
- });
189
- test('valid MCP config lists servers by name', () => {
190
- const home = tempDir();
191
- writeFile(home, '.claude.json', JSON.stringify({ mcpServers: { github: {}, filesystem: {} } }));
192
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'MCP');
193
- assert.ok(hasCheck(checks, 'PASS', /2 MCP server\(s\): github, filesystem/));
194
- });
195
- test('MCP config without mcpServers key is informational', () => {
196
- const home = tempDir();
197
- writeFile(home, '.claude.json', '{}');
198
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'claude-code' })), 'claude-code', 'MCP');
199
- assert.ok(hasCheck(checks, 'INFO', /no "mcpServers" key/));
200
- });
201
- test('more than 10 MCP servers warns about tool overload', () => {
202
- const home = tempDir();
203
- const mcpServers = Object.fromEntries(Array.from({ length: 11 }, (_, i) => [`server-${i}`, {}]));
204
- writeFile(home, '.kimi-code/mcp.json', JSON.stringify({ mcpServers }));
205
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'kimi-code' })), 'kimi-code', 'MCP');
206
- assert.ok(hasCheck(checks, 'WARN', /11 MCP servers configured \(> 10\)/));
207
- });
208
- test('TOML MCP configs are scanned without JSON parsing', () => {
209
- const home = tempDir();
210
- writeFile(home, '.codex/config.toml', 'model = "gpt-5"\n\n[mcp_servers.docs]\ncommand = "x"\n\n[mcp_servers.docs.env]\nFOO = "1"\n\n[mcp_servers.fs]\ncommand = "y"\n');
211
- const checks = healthChecks(collectDoctorReport(makeOptions(home, tempDir(), { agent: 'codex' })), 'codex', 'MCP');
212
- assert.ok(hasCheck(checks, 'INFO', /text declares 2 MCP server\(s\): docs, fs.*does not prove the agent loaded/));
213
- assert.ok(!checks.some((c) => c.status === 'FAIL'));
214
- });
215
- test('formatDoctorReport renders sections, prefixes and summary', () => {
216
- const home = tempDir();
217
- mkdirSync(path.join(home, '.claude'));
218
- writeFile(home, '.claude/CLAUDE.md', '# hi\n');
219
- const text = formatDoctorReport(collectDoctorReport(makeOptions(home, tempDir())));
220
- assert.match(text, /skillfit doctor — read-only configuration health report/);
221
- assert.match(text, /Agent detection/);
222
- assert.match(text, /Claude Code \(claude-code\)/);
223
- assert.match(text, /\[PASS\]/);
224
- assert.match(text, /Summary/);
225
- assert.match(text, /1\/3 agents detected/);
226
- assert.match(text, /always exits 0/);
227
- });
228
- test('runDoctor prints the report and never sets an exit code', async () => {
229
- const logged = [];
230
- const original = console.log;
231
- console.log = (message) => {
232
- logged.push(String(message));
233
- };
234
- try {
235
- await runDoctor({ agent: 'claude-code', dryRun: true, yes: true });
236
- }
237
- finally {
238
- console.log = original;
239
- }
240
- const output = logged.join('\n');
241
- assert.match(output, /skillfit doctor/);
242
- assert.match(output, /Summary/);
243
- assert.equal(process.exitCode, undefined);
244
- });
245
- test('runDoctor exits non-zero on an unknown agent', async (t) => {
246
- const errors = [];
247
- const original = console.error;
248
- const priorExitCode = process.exitCode;
249
- t.after(() => {
250
- process.exitCode = priorExitCode;
251
- });
252
- console.error = (message) => {
253
- errors.push(String(message));
254
- };
255
- try {
256
- await runDoctor({ agent: 'nope' });
257
- }
258
- finally {
259
- console.error = original;
260
- }
261
- assert.match(errors.join('\n'), /Unknown agent "nope"\. Known agents: claude-code, codex, kimi-code/);
262
- // Findings stay advisory at exit 0; a typo in --agent is a usage error that never ran the check,
263
- // and exiting 0 there lets CI read it as a clean bill of health.
264
- assert.equal(process.exitCode, 2);
265
- });
266
- test('runDoctor still exits 0 when the report contains FAIL findings', async (t) => {
267
- const priorExitCode = process.exitCode;
268
- t.after(() => {
269
- process.exitCode = priorExitCode;
270
- });
271
- const original = console.log;
272
- console.log = () => { };
273
- try {
274
- await runDoctor({ agent: 'claude-code' });
275
- }
276
- finally {
277
- console.log = original;
278
- }
279
- assert.equal(process.exitCode, undefined, 'doctor is read-only and advisory: findings never set an exit code');
280
- });