pi-odd-worktree 2.0.0 → 3.0.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 (160) hide show
  1. package/README.md +54 -311
  2. package/extensions/odd-worktree-tools.ts +4149 -2447
  3. package/lib/bash-activity.js +1164 -0
  4. package/lib/bash-design.js +684 -0
  5. package/lib/bash-destructive.js +559 -0
  6. package/lib/bash-frame.js +205 -0
  7. package/lib/card-content.js +23 -0
  8. package/lib/card-style.js +175 -0
  9. package/lib/checkout-facts.js +30 -70
  10. package/lib/codegraph-card-preview.js +628 -0
  11. package/lib/codegraph-card.js +515 -0
  12. package/lib/codegraph-compaction.js +76 -0
  13. package/lib/codegraph-daemon.js +246 -0
  14. package/lib/codegraph-edit-sync.js +182 -0
  15. package/lib/codegraph-guard-target.js +337 -0
  16. package/lib/codegraph-guard.js +211 -0
  17. package/lib/codegraph-index.js +1020 -0
  18. package/lib/codegraph-lock.js +607 -0
  19. package/lib/codegraph-mcp-config.js +134 -0
  20. package/lib/codegraph-mcp.js +123 -0
  21. package/lib/codegraph-paths.js +69 -0
  22. package/lib/codegraph-prompt/explore.md +11 -0
  23. package/lib/codegraph-prompt/fix.md +6 -0
  24. package/lib/codegraph-prompt/generic.md +8 -0
  25. package/lib/codegraph-prompt/judge.md +9 -0
  26. package/lib/codegraph-prompt/orchestrator.md +17 -0
  27. package/lib/codegraph-prompt/verify.md +10 -0
  28. package/lib/codegraph-prompt/worker.md +7 -0
  29. package/lib/codegraph-role.js +55 -0
  30. package/lib/codegraph-rules.js +146 -0
  31. package/lib/codegraph-session.js +303 -383
  32. package/lib/codegraph-warmup.js +139 -0
  33. package/lib/file-card-markdown.js +141 -0
  34. package/lib/file-card-resolver.js +245 -0
  35. package/lib/file-card.js +659 -0
  36. package/lib/files-index.js +387 -0
  37. package/lib/files-insert.js +81 -0
  38. package/lib/files-orders.js +326 -0
  39. package/lib/files-picker-view.js +1416 -0
  40. package/lib/files-preview.js +338 -0
  41. package/lib/files-scope-detail.js +171 -0
  42. package/lib/files-scope-view.js +507 -0
  43. package/lib/gh-issues.js +308 -14
  44. package/lib/issue-preview.js +26 -7
  45. package/lib/issues-bash-mutation.js +206 -0
  46. package/lib/issues-cache-store.js +261 -0
  47. package/lib/issues-section.js +710 -0
  48. package/lib/issues-view.js +649 -52
  49. package/lib/odd-prompt/odd-worktrees.md +21 -0
  50. package/lib/odd-worktrees-prompt.js +10 -28
  51. package/lib/related-issues-cache.js +210 -0
  52. package/lib/shell-card.js +825 -0
  53. package/lib/skill-odd-card.js +183 -0
  54. package/lib/tui-paint.js +4 -5
  55. package/lib/warp-create-panel.js +538 -250
  56. package/lib/warp-create-picker.js +56 -9
  57. package/lib/warp-delete-confirm.js +19 -28
  58. package/lib/warp-selector-view.js +160 -82
  59. package/lib/which-command.js +90 -0
  60. package/lib/worktree-card.js +267 -897
  61. package/lib/worktree-cards.js +383 -0
  62. package/lib/worktree-create.js +287 -0
  63. package/lib/worktree-git.js +3 -3
  64. package/lib/worktree-guard.js +548 -0
  65. package/lib/worktree-hooks.js +421 -711
  66. package/lib/worktree-list.js +120 -0
  67. package/lib/worktree-registry.js +162 -879
  68. package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
  69. package/lib/worktree-setup-runner.js +376 -0
  70. package/lib/worktree-setup.js +140 -0
  71. package/lib/worktree-warp-busy.js +462 -85
  72. package/lib/worktree-warp-sessions.js +1 -2
  73. package/package.json +2 -2
  74. package/tools/bash-activity.test.js +1419 -0
  75. package/tools/bash-design.test.js +1091 -0
  76. package/tools/bash-destructive.test.js +139 -0
  77. package/tools/card-content.test.js +44 -0
  78. package/tools/card-style.test.js +298 -0
  79. package/tools/codegraph-card-preview.test.js +254 -0
  80. package/tools/codegraph-card.test.js +1080 -0
  81. package/tools/codegraph-compaction.test.js +378 -0
  82. package/tools/codegraph-daemon.test.js +248 -0
  83. package/tools/codegraph-edit-sync.test.js +295 -0
  84. package/tools/codegraph-guard-target.test.js +174 -0
  85. package/tools/codegraph-guard.test.js +238 -0
  86. package/tools/codegraph-index.test.js +1948 -0
  87. package/tools/codegraph-lock.test.js +932 -0
  88. package/tools/codegraph-mcp-config.test.js +181 -0
  89. package/tools/codegraph-mcp.test.js +194 -0
  90. package/tools/codegraph-paths.test.js +44 -0
  91. package/tools/codegraph-role.test.js +30 -0
  92. package/tools/codegraph-rules.test.js +250 -0
  93. package/tools/codegraph-session.test.js +660 -391
  94. package/tools/codegraph-warmup.test.js +316 -0
  95. package/tools/commands.test.js +510 -31
  96. package/tools/file-card-markdown.test.js +188 -0
  97. package/tools/file-card.test.js +1289 -0
  98. package/tools/files-bridge.test.js +575 -0
  99. package/tools/files-command.test.js +610 -0
  100. package/tools/files-index.test.js +473 -0
  101. package/tools/files-insert.test.js +139 -0
  102. package/tools/files-orders.test.js +597 -0
  103. package/tools/files-picker-view.test.js +1871 -0
  104. package/tools/files-preview.test.js +452 -0
  105. package/tools/files-scope-detail.test.js +264 -0
  106. package/tools/files-scope-view.test.js +614 -0
  107. package/tools/fixtures/card-codegraph-outputs.js +110 -0
  108. package/tools/fixtures/codegraph-cli-stub.js +16 -0
  109. package/tools/fixtures/codegraph-init-process.js +28 -0
  110. package/tools/fixtures/codegraph-lock-worker.js +117 -0
  111. package/tools/fixtures/daemon-fake.js +98 -0
  112. package/tools/fixtures/daemon-mcp-server.js +39 -0
  113. package/tools/fixtures/daemon-warmup-worker.js +12 -0
  114. package/tools/fixtures/load-extension.js +136 -3
  115. package/tools/gh-issues-feedback.test.js +31 -7
  116. package/tools/gh-issues.test.js +391 -1
  117. package/tools/issue-preview.test.js +44 -7
  118. package/tools/issues-bash-mutation.test.js +101 -0
  119. package/tools/issues-cache-store.test.js +222 -0
  120. package/tools/issues-command.test.js +1512 -66
  121. package/tools/issues-open-guard.test.js +1096 -0
  122. package/tools/issues-section.test.js +4195 -0
  123. package/tools/issues-seed-query-regression.test.js +67 -0
  124. package/tools/issues-view.test.js +1489 -60
  125. package/tools/odd-worktrees-prompt.test.js +98 -65
  126. package/tools/package-surface.test.js +431 -36
  127. package/tools/related-issues-cache.test.js +324 -0
  128. package/tools/shell-card.test.js +834 -0
  129. package/tools/skill-odd-card.test.js +200 -0
  130. package/tools/t5-session-identity.test.js +44 -22
  131. package/tools/warp-busy-guard.test.js +2569 -308
  132. package/tools/warp-create-panel.test.js +499 -74
  133. package/tools/warp-create-picker.test.js +101 -5
  134. package/tools/warp-delete-confirm.test.js +49 -15
  135. package/tools/warp-empty-session.test.js +0 -1
  136. package/tools/warp-fallback-regression.test.js +533 -0
  137. package/tools/warp-selector-view.test.js +460 -196
  138. package/tools/which-command.test.js +126 -0
  139. package/tools/worktree-card.test.js +551 -0
  140. package/tools/worktree-cards.test.js +845 -0
  141. package/tools/worktree-changes.test.js +4 -5
  142. package/tools/worktree-create.test.js +489 -0
  143. package/tools/worktree-guard.test.js +823 -0
  144. package/tools/worktree-hooks.test.js +905 -0
  145. package/tools/worktree-list.test.js +170 -0
  146. package/tools/worktree-registry.test.js +89 -230
  147. package/tools/worktree-remove-async.test.js +318 -0
  148. package/tools/worktree-setup-runner.test.js +276 -0
  149. package/tools/worktree-setup.test.js +140 -0
  150. package/tools/worktree-tools.test.js +477 -93
  151. package/lib/codegraph-commands.js +0 -165
  152. package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
  153. package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
  154. package/lib/worktree-model-result.js +0 -291
  155. package/tools/codegraph-commands.test.js +0 -371
  156. package/tools/herdr-free-create.test.js +0 -161
  157. package/tools/worktree-close-herdr-async.test.js +0 -204
  158. package/tools/worktree-odd-migration.test.js +0 -224
  159. package/tools/worktree-registry-cache.test.js +0 -163
  160. package/tools/worktree-registry-odd.test.js +0 -231
@@ -0,0 +1,316 @@
1
+ 'use strict';
2
+ // S5: the warm-up reuses a live daemon before starting one, runs `codegraph serve --mcp` bounded through
3
+ // CodeGraph's own proxy, never kills a daemon and never holds its caller when it is fired in the background.
4
+
5
+ const { test, after } = require('node:test');
6
+ const assert = require('node:assert/strict');
7
+ const { spawn } = require('node:child_process');
8
+ const fs = require('node:fs');
9
+ const os = require('node:os');
10
+ const path = require('node:path');
11
+
12
+ const { exploreOnce, warmUpDaemon, WARMUP_BACKGROUND_LIVE_MS, WARMUP_QUERY } = require('../lib/codegraph-warmup.js');
13
+
14
+ const FAKE_SERVER = path.join(__dirname, 'fixtures', 'daemon-mcp-server.js');
15
+ const WARMUP_WORKER = path.join(__dirname, 'fixtures', 'daemon-warmup-worker.js');
16
+ const WARMUP_MODULE = require.resolve('../lib/codegraph-warmup.js');
17
+
18
+ const tempDirs = [];
19
+ function scratch(prefix) {
20
+ const dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), prefix)));
21
+ tempDirs.push(dir);
22
+ return dir;
23
+ }
24
+
25
+ after(() => {
26
+ for (const dir of tempDirs) fs.rmSync(dir, { recursive: true, force: true });
27
+ });
28
+
29
+ /** The command line exploreOnce runs: the same shape as the real one, pointing at the fake server instead. */
30
+ function fakeServer(mode) {
31
+ return `"${process.execPath}" "${FAKE_SERVER}" ${mode}`;
32
+ }
33
+
34
+ function write(dir, name, body) {
35
+ const file = path.join(dir, name);
36
+ fs.writeFileSync(file, body);
37
+ return file;
38
+ }
39
+
40
+ /** Runs a caller in a fresh process and reports how long it stayed alive and what it printed. */
41
+ function run(script, env = {}) {
42
+ return new Promise((resolve) => {
43
+ const started = Date.now();
44
+ const child = spawn(process.execPath, [script], { stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, ...env } });
45
+ let stdout = '';
46
+ let stderr = '';
47
+ child.stdout.on('data', (chunk) => { stdout += chunk.toString('utf8'); });
48
+ child.stderr.on('data', (chunk) => { stderr += chunk.toString('utf8'); });
49
+ const killer = setTimeout(() => child.kill(), 30_000);
50
+ child.on('close', (code) => {
51
+ clearTimeout(killer);
52
+ resolve({ status: code, stdout, stderr, elapsed: Date.now() - started });
53
+ });
54
+ });
55
+ }
56
+
57
+ /** A server that reads its stdin, never answers and lives for ten seconds. */
58
+ function hangServer(dir) {
59
+ return write(dir, 'hang.mjs', [
60
+ 'import { createInterface } from "node:readline";',
61
+ 'createInterface({ input: process.stdin }).on("line", () => {});',
62
+ 'setTimeout(() => {}, 10_000);',
63
+ '',
64
+ ].join('\n'));
65
+ }
66
+
67
+ /** A server that answers both calls after `ms`. */
68
+ function slowServer(dir, ms) {
69
+ return write(dir, 'slow-server.mjs', [
70
+ 'import { createInterface } from "node:readline";',
71
+ 'const out = (message) => process.stdout.write(JSON.stringify(message) + "\\n");',
72
+ 'createInterface({ input: process.stdin }).on("line", (line) => {',
73
+ ' const message = JSON.parse(line);',
74
+ ` if (message.id === 1) setTimeout(() => out({ jsonrpc: "2.0", id: 1, result: {} }), ${ms});`,
75
+ ` if (message.id === 2) setTimeout(() => out({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text: "OK" }] } }), ${ms});`,
76
+ '});',
77
+ '',
78
+ ].join('\n'));
79
+ }
80
+
81
+ function command(script) {
82
+ return `"${process.execPath}" "${script}"`;
83
+ }
84
+
85
+ /** An awaited warm-up: the caller waits for the answer and prints it. */
86
+ function awaitedCaller(dir, project, timeoutMs, script) {
87
+ return write(dir, 'caller.js', [
88
+ "'use strict';",
89
+ `const warmup = require(${JSON.stringify(WARMUP_MODULE)});`,
90
+ `warmup.exploreOnce(${JSON.stringify(project)}, "main", ${timeoutMs}, ${JSON.stringify(command(script))}, { project: ${JSON.stringify(project)} })`,
91
+ ' .then((result) => process.stdout.write(JSON.stringify(result) + "\\n"));',
92
+ '',
93
+ ].join('\n'));
94
+ }
95
+
96
+ // --- Bounded, and never fatal ---
97
+
98
+ test('S5: a timeout resolves false without waiting for the server', async () => {
99
+ const dir = scratch('odd-warm-timeout-');
100
+ const started = Date.now();
101
+ assert.equal(await warmUpDaemon(dir, 1, {
102
+ status: () => 'none',
103
+ command: fakeServer('silent'),
104
+ project: dir,
105
+ }), false);
106
+ assert.ok(Date.now() - started < 5_000);
107
+ });
108
+
109
+ test('S5: a warm-up is skipped while an init runs, so the two never write the index together', async () => {
110
+ const dir = scratch('odd-warm-init-');
111
+ let asked = false;
112
+ assert.equal(await warmUpDaemon(dir, 5_000, {
113
+ initRunning: true,
114
+ status: () => { throw new Error('a skipped warm-up resolves no daemon'); },
115
+ ask: async () => { asked = true; return { status: 'ok', text: 'X' }; },
116
+ command: fakeServer('ok'),
117
+ project: dir,
118
+ }), false);
119
+ assert.equal(asked, false);
120
+ });
121
+
122
+ test('S5: an explore call with a text result is a warm-up', async () => {
123
+ const dir = scratch('odd-warm-fake-');
124
+ const result = await exploreOnce(dir, 'main', 10_000, fakeServer('ok'), { project: dir });
125
+ assert.equal(result.ok, true);
126
+ assert.ok(Number.isFinite(result.exploreMs) && result.exploreMs >= 0);
127
+ });
128
+
129
+ test("S5: a reply with isError is a failed warm-up, so no 'ready' notice is shown", async () => {
130
+ const dir = scratch('odd-warm-fake-');
131
+ const result = await exploreOnce(dir, 'main', 10_000, fakeServer('isError'), { project: dir });
132
+ assert.equal(result.ok, false);
133
+ });
134
+
135
+ test('S5: a reply with no content is a failed warm-up too', async () => {
136
+ const dir = scratch('odd-warm-fake-');
137
+ const result = await exploreOnce(dir, 'main', 10_000, fakeServer('empty'), { project: dir });
138
+ assert.equal(result.ok, false);
139
+ });
140
+
141
+ test("S5: a stuck server's stdout is released, so it cannot keep the process alive after the timeout", async () => {
142
+ const dir = scratch('odd-warm-stuck-');
143
+ const child = spawn(process.execPath, [WARMUP_WORKER, fakeServer('stuck'), dir], { stdio: ['ignore', 'pipe', 'pipe'] });
144
+ let output = '';
145
+ let stderr = '';
146
+ let killed = false;
147
+ child.stdout.on('data', (chunk) => { output += chunk.toString('utf8'); });
148
+ child.stderr.on('data', (chunk) => { stderr += chunk.toString('utf8'); });
149
+ const guard = setTimeout(() => { killed = true; child.kill(); }, 6_000);
150
+ const code = await new Promise((resolve) => child.on('close', resolve));
151
+ clearTimeout(guard);
152
+ assert.match(output, /RESULT \{"ok":false/, `stdout ${output} stderr ${stderr}`);
153
+ assert.equal(killed, false, "the worker never exited after the timeout: a stuck server's stdout kept it alive");
154
+ assert.equal(code, 0, stderr);
155
+ });
156
+
157
+ test('S5: the server is started from the temp directory with the project as an argument, never as its cwd', async () => {
158
+ const dir = scratch('odd-warm-cwd-');
159
+ const seen = path.join(dir, 'seen.json');
160
+ const server = write(dir, 'cwd-server.mjs', [
161
+ 'import { writeFileSync } from "node:fs";',
162
+ 'import { createInterface } from "node:readline";',
163
+ 'const out = (message) => process.stdout.write(JSON.stringify(message) + "\\n");',
164
+ 'createInterface({ input: process.stdin }).on("line", (line) => {',
165
+ ' const message = JSON.parse(line);',
166
+ ' if (message.method === "initialize") {',
167
+ ` writeFileSync(${JSON.stringify(seen)}, JSON.stringify({ cwd: process.cwd(), argv: process.argv.slice(2) }));`,
168
+ ' out({ jsonrpc: "2.0", id: message.id, result: {} });',
169
+ ' }',
170
+ ' if (message.id === 2) out({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text: "OK" }] } });',
171
+ '});',
172
+ '',
173
+ ].join('\n'));
174
+ const result = await exploreOnce(dir, 'main', 10_000, command(server), { project: dir });
175
+ assert.equal(result.ok, true);
176
+ const recorder = JSON.parse(fs.readFileSync(seen, 'utf8'));
177
+ const realTmp = fs.realpathSync(os.tmpdir());
178
+ assert.equal(fs.realpathSync(recorder.cwd), realTmp);
179
+ assert.ok(recorder.argv.includes('-p'), JSON.stringify(recorder.argv));
180
+ });
181
+
182
+ // --- S5: reuse the checkout's live daemon before warming one ---
183
+
184
+ test('S5: a live daemon of this checkout is reused for the warm-up instead of spawning a server', async () => {
185
+ // This directory has no index: a spawn here cannot succeed, so a true result proves the daemon was reused.
186
+ const dir = scratch('odd-warm-reuse-');
187
+ const asked = [];
188
+ const reused = await warmUpDaemon(dir, 5_000, {
189
+ status: () => 'live',
190
+ ask: async (root, query) => { asked.push({ root, query }); return { status: 'ok', text: 'WARM' }; },
191
+ command: fakeServer('silent'),
192
+ project: dir,
193
+ });
194
+ assert.equal(reused, true);
195
+ assert.deepEqual(asked, [{ root: dir, query: WARMUP_QUERY }], 'the live daemon is asked once, for this checkout');
196
+ });
197
+
198
+ test('S5: a live daemon that does not answer is not doubled by a second server', async () => {
199
+ const dir = scratch('odd-warm-timeout-live-');
200
+ let asked = 0;
201
+ const started = Date.now();
202
+ const warmed = await warmUpDaemon(dir, 3_000, {
203
+ status: () => 'live',
204
+ ask: async () => { asked += 1; return { status: 'timeout' }; },
205
+ // A server that would answer at once: a second server is never started, so this stays unanswered.
206
+ command: fakeServer('ok'),
207
+ project: dir,
208
+ });
209
+ assert.equal(warmed, false);
210
+ assert.equal(asked, 1);
211
+ assert.ok(Date.now() - started < 2_000, 'the caller did not wait for a spawn that must not happen');
212
+ });
213
+
214
+ test('S5: with no live daemon for this checkout, nothing is asked and the server path runs', async () => {
215
+ const dir = scratch('odd-warm-none-live-');
216
+ let asked = false;
217
+ assert.equal(await warmUpDaemon(dir, 50, {
218
+ status: () => 'none',
219
+ ask: async () => { asked = true; return { status: 'ok', text: 'X' }; },
220
+ command: fakeServer('silent'),
221
+ project: dir,
222
+ }), false);
223
+ assert.equal(asked, false, 'a checkout with no live daemon has nothing to ask');
224
+ });
225
+
226
+ test('S5: a background warm-up reusing a live daemon stays short, so it never holds its caller', async () => {
227
+ const dir = scratch('odd-warm-bg-live-');
228
+ let budget = -1;
229
+ const warmed = await warmUpDaemon(dir, 120_000, {
230
+ background: true,
231
+ status: () => 'live',
232
+ ask: async (_root, _query, ms) => { budget = ms; return { status: 'ok', text: 'WARM' }; },
233
+ project: dir,
234
+ });
235
+ assert.equal(warmed, true);
236
+ assert.ok(budget > 0 && budget <= WARMUP_BACKGROUND_LIVE_MS, `asked with ${budget} ms`);
237
+ });
238
+
239
+ // --- A background warm-up must never keep its caller alive; an awaited one must still hold on ---
240
+
241
+ test('S5: a pending background warm-up never keeps its caller alive', async () => {
242
+ const dir = scratch('odd-warm-bg-hang-');
243
+ const script = write(dir, 'caller.js', [
244
+ "'use strict';",
245
+ `const warmup = require(${JSON.stringify(WARMUP_MODULE)});`,
246
+ `warmup.exploreOnce(${JSON.stringify(dir)}, "main", 60_000, ${JSON.stringify(command(hangServer(dir)))}, { background: true, project: ${JSON.stringify(dir)} });`,
247
+ '',
248
+ ].join('\n'));
249
+ const result = await run(script);
250
+ assert.equal(result.status, 0, result.stderr);
251
+ assert.ok(result.elapsed < 5_000, `the caller stayed alive ${result.elapsed} ms`);
252
+ });
253
+
254
+ test('S5: an awaited warm-up still waits for its own timeout on a server that never answers', async () => {
255
+ const dir = scratch('odd-warm-bg-default-');
256
+ const script = awaitedCaller(dir, dir, 3_000, hangServer(dir));
257
+ const result = await run(script);
258
+ assert.equal(result.status, 0, result.stderr);
259
+ assert.ok(result.elapsed >= 2_500, `the default mode left after ${result.elapsed} ms instead of waiting for its own timer`);
260
+ assert.match(result.stdout, /"ok":false/);
261
+ });
262
+
263
+ test('S5: an awaited warm-up keeps the process until the server answers', async () => {
264
+ const dir = scratch('odd-warm-bg-awaited-');
265
+ const script = awaitedCaller(dir, dir, 15_000, slowServer(dir, 500));
266
+ const result = await run(script);
267
+ assert.equal(result.status, 0, result.stderr);
268
+ assert.match(result.stdout, /"ok":true/);
269
+ });
270
+
271
+ test('S5: a background warm-up still reads its server while the caller is alive', async () => {
272
+ const dir = scratch('odd-warm-bg-slow-');
273
+ const script = write(dir, 'caller.js', [
274
+ "'use strict';",
275
+ `const warmup = require(${JSON.stringify(WARMUP_MODULE)});`,
276
+ 'const keep = setTimeout(() => {}, 20_000);',
277
+ `warmup.exploreOnce(${JSON.stringify(dir)}, "main", 15_000, ${JSON.stringify(command(slowServer(dir, 400)))}, { background: true, project: ${JSON.stringify(dir)} })`,
278
+ ' .then((result) => { clearTimeout(keep); process.stdout.write(JSON.stringify(result) + "\\n"); });',
279
+ '',
280
+ ].join('\n'));
281
+ const result = await run(script);
282
+ assert.equal(result.status, 0, result.stderr);
283
+ assert.match(result.stdout, /"ok":true/);
284
+ });
285
+
286
+ test('S5: closing the warm-up hands the server every message, in order', async () => {
287
+ const dir = scratch('odd-warm-bg-eof-');
288
+ const log = path.join(dir, 'seen.log');
289
+ const server = write(dir, 'order-server.mjs', [
290
+ 'import { appendFileSync } from "node:fs";',
291
+ 'import { createInterface } from "node:readline";',
292
+ 'const out = (message) => process.stdout.write(JSON.stringify(message) + "\\n");',
293
+ 'const seen = [];',
294
+ 'createInterface({ input: process.stdin }).on("line", (line) => {',
295
+ ' const message = JSON.parse(line);',
296
+ ' seen.push(message.method ?? "id" + message.id);',
297
+ ' if (message.id === 1) out({ jsonrpc: "2.0", id: 1, result: {} });',
298
+ ' if (message.id === 2) { appendFileSync(process.env.SEEN, JSON.stringify({ seen }) + "\\n"); out({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text: "OK" }] } }); }',
299
+ '});',
300
+ '',
301
+ ].join('\n'));
302
+ const script = awaitedCaller(dir, dir, 10_000, server);
303
+ const result = await run(script, { SEEN: log });
304
+ assert.equal(result.status, 0, result.stderr);
305
+ assert.match(result.stdout, /"ok":true/);
306
+ const first = JSON.parse(fs.readFileSync(log, 'utf8').split('\n')[0]);
307
+ assert.deepEqual(first.seen, ['initialize', 'notifications/initialized', 'tools/call']);
308
+ });
309
+
310
+ test('S5: a warm-up that cannot start a child resolves false instead of throwing', async () => {
311
+ const dir = scratch('odd-warm-nospawn-');
312
+ assert.equal(await exploreOnce(dir, 'main', 1_000, fakeServer('ok'), {
313
+ project: dir,
314
+ spawn: () => { throw new Error('ENOENT'); },
315
+ }).then((result) => result.ok), false);
316
+ });