@clagentic/console 1.9.0-beta.1 → 1.9.0-beta.3

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 (61) hide show
  1. package/bin/cli.js +23 -1
  2. package/lib/agents.js +13 -3
  3. package/lib/build-sha.json +2 -2
  4. package/lib/cli/ipc-subcommands.js +84 -4
  5. package/lib/daemon.js +111 -7
  6. package/lib/effective-protocol.js +82 -0
  7. package/lib/project-connection.js +21 -8
  8. package/lib/project-filesystem.js +4 -4
  9. package/lib/project-http.js +4 -4
  10. package/lib/project-loop.js +49 -5
  11. package/lib/project-sessions.js +166 -68
  12. package/lib/project-user-mention.js +7 -7
  13. package/lib/project-user-message.js +81 -14
  14. package/lib/project.js +28 -22
  15. package/lib/public/app.js +18 -4
  16. package/lib/public/css/base.css +14 -0
  17. package/lib/public/css/filebrowser.css +6 -0
  18. package/lib/public/css/home-hub.css +28 -8
  19. package/lib/public/css/icon-strip.css +17 -0
  20. package/lib/public/css/messages.css +11 -0
  21. package/lib/public/css/mobile-nav.css +22 -0
  22. package/lib/public/css/server-settings.css +9 -0
  23. package/lib/public/css/sidebar.css +15 -0
  24. package/lib/public/css/title-bar.css +10 -1
  25. package/lib/public/index.html +9 -2
  26. package/lib/public/modules/activity-latch.js +45 -0
  27. package/lib/public/modules/activity-state.js +195 -0
  28. package/lib/public/modules/app-connection.js +31 -6
  29. package/lib/public/modules/app-favicon.js +75 -1
  30. package/lib/public/modules/app-home-hub.js +14 -11
  31. package/lib/public/modules/app-loop-ui.js +86 -2
  32. package/lib/public/modules/app-messages.js +178 -54
  33. package/lib/public/modules/app-panels.js +91 -32
  34. package/lib/public/modules/app-projects.js +46 -9
  35. package/lib/public/modules/app-rate-limit.js +13 -1
  36. package/lib/public/modules/server-settings.js +256 -21
  37. package/lib/public/modules/sidebar-mobile.js +32 -22
  38. package/lib/public/modules/sidebar-projects.js +42 -14
  39. package/lib/public/modules/sidebar-sessions.js +168 -48
  40. package/lib/public/modules/theme.js +2 -2
  41. package/lib/public/modules/tools.js +11 -39
  42. package/lib/sdk-bridge.js +375 -33
  43. package/lib/sdk-message-processor.js +98 -15
  44. package/lib/sdk-skill-discovery.js +46 -6
  45. package/lib/sdk-slash-enrichment.js +5 -2
  46. package/lib/server-dm.js +5 -5
  47. package/lib/server-hub-sessions.js +70 -0
  48. package/lib/server.js +78 -43
  49. package/lib/session-activity.js +9 -2
  50. package/lib/sessions.js +64 -18
  51. package/lib/smtp.js +10 -1
  52. package/lib/terminal-manager.js +6 -6
  53. package/lib/ws-schema.js +16 -0
  54. package/lib/yoke/adapters/claude.js +7 -1
  55. package/lib/yoke/adapters/codex.js +219 -31
  56. package/package.json +2 -2
  57. package/scripts/check-test-count.js +397 -0
  58. package/scripts/test-file-completion-reporter.js +43 -0
  59. package/scripts/verify-installed-build.js +242 -15
  60. package/lib/model-context-windows.js +0 -74
  61. package/lib/public/modules/model-context-windows.js +0 -71
@@ -0,0 +1,397 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ //
4
+ // check-test-count.js — per-file completion + count floor for `npm test`
5
+ // (lr-795882, hardened after PEACHES/BOBBIE PR #395 review).
6
+ //
7
+ // PROBLEM: `node --test` can exit 0 with a self-consistent-looking summary
8
+ // even when a truncated run silently dropped an entire test file's worth of
9
+ // tests (proved by MILLER during lr-a7b03e: 1406/1385/1406/1406 across four
10
+ // runs on unmodified main, all exit 0, 1385 missing 21 real security tests
11
+ // from test/xss-escape.test.js). A green `npm test` did not prove the full
12
+ // suite ran. Fixing the underlying leaked handles (lr-795882) closed the
13
+ // mechanism that caused THAT truncation, but nothing short of verifying
14
+ // every file actually ran can catch the NEXT regression of this class — a
15
+ // future leaked handle in a NEW test file would reproduce the exact same
16
+ // silent-drop failure mode this script exists to catch.
17
+ //
18
+ // WHAT THIS DOES AND DOES NOT CATCH — state this plainly, not left for a
19
+ // reader to work out (PR #395 review, andy):
20
+ // - CATCHES: any single test FILE that reports zero test:pass/test:fail
21
+ // events at all — the literal MILLER failure mode (one file's tests
22
+ // silently vanish while `node --test` still exits 0). This is a hard
23
+ // per-file boundary, not a probabilistic total: every file named on
24
+ // the command line is checked individually against the reporter's own
25
+ // event stream; there is no "close enough" combined count to hide
26
+ // behind, and — unlike an earlier version of this script — this
27
+ // mechanism does NOT need to isolate each file into its own process
28
+ // to get that per-file signal (see MECHANISM below), so it carries no
29
+ // risk of changing test timing/ordering behavior.
30
+ // - DOES NOT CATCH: a handful of tests silently dropped from WITHIN an
31
+ // otherwise-reporting file (e.g. 3 of a file's 40 tests vanish but the
32
+ // file still reports other passes and exits 0). Catching that would
33
+ // require a checked-in expected test-name list per file, which is far
34
+ // more maintenance than this bug class justifies. TEST_COUNT_FLOOR
35
+ // below is a coarser secondary net for a LARGE in-file drop, not a
36
+ // precise one.
37
+ //
38
+ // MECHANISM (v2 — replaces the v1 "single combined run + parse the shared
39
+ // TAP summary's total" design, which BOBBIE/PEACHES correctly flagged as
40
+ // too loose: a floor of 1300 against a live count of ~1407 has 107 tests
41
+ // of slack, comfortably hiding MILLER's own 21-test drop; and a v1.5
42
+ // per-file-isolated-process design, which was correct in principle but
43
+ // exposed an unrelated pre-existing test-order flake
44
+ // (project-connection-hydrate-session-model-lr-041af8.test.js's
45
+ // millisecond tie-break) purely as a side effect of changing how files are
46
+ // scheduled — rejected because the count-verification mechanism itself
47
+ // should never be the thing introducing new failure risk):
48
+ //
49
+ // Run ALL files in ONE node --test invocation, exactly as `npm test`
50
+ // always has (no per-file process isolation, no timing/ordering change),
51
+ // but attach a CUSTOM REPORTER (test-file-completion-reporter.js)
52
+ // alongside the normal `tap` reporter. Node's reporter API delivers a
53
+ // `file` field on every test:pass/test:fail event REGARDLESS of what
54
+ // TAP's own text output shows (TAP text has no per-file marker when
55
+ // multiple files share one process — that's what made v1 unable to do
56
+ // this without isolating files). The custom reporter emits one
57
+ // machine-readable "RESULT <pass|fail> <file>" line per test result to a
58
+ // separate destination stream; this script reads that stream, buckets
59
+ // results by file, and requires every file passed on argv to have at
60
+ // least one RESULT line.
61
+ //
62
+ var TEST_COUNT_FLOOR = 1300;
63
+
64
+ var fs = require("fs");
65
+ var path = require("path");
66
+ var { spawnSync } = require("child_process");
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // CI legibility (lr-e551b9, MILLER re-diagnosis of PR #400 / lr-4e1242 seq 5;
70
+ // re-diagnosed again post-merge, same task, when the shipped fix turned out
71
+ // not to survive a real CI pipe — see DELIVERY below).
72
+ //
73
+ // GitHub Actions does not surface arbitrary stderr text anywhere a crew
74
+ // agent can reach it: the raw job log requires following a redirect to a
75
+ // blob store that loadout-git-host-api correctly refuses (crew-manifest
76
+ // lr-90a3e1). A `::error::`-prefixed line, by contrast, is turned into a
77
+ // check-run ANNOTATION by the Actions runner, which IS reachable via the
78
+ // GitHub API. emitAnnotation() below exists so every FAIL path
79
+ // in this script — not just the final exit code — lands somewhere a crew
80
+ // agent can actually read it, without changing which conditions fail the
81
+ // run (see the module header above: every condition that fails today must
82
+ // keep failing).
83
+ //
84
+ // DELIVERY (lr-e551b9 reopen, MILLER third-pass diagnosis, confidence 0.93,
85
+ // reproduced locally and in CI on PR #400's rebased head): the first version
86
+ // of this function used `process.stdout.write`. When stdout is a PIPE
87
+ // (always true in CI, and in any captured run), that write is ASYNCHRONOUS —
88
+ // it queues in userspace once the 64KB kernel pipe buffer fills. The
89
+ // multi-MB TAP dump this script also writes to stdout vastly exceeds that
90
+ // buffer, so by the time emitAnnotation() ran, its own write was queued
91
+ // BEHIND the still-draining TAP blob. process.exit() then tore the process
92
+ // down without draining the queue, so the annotation reached the Writable
93
+ // stream object and never reached the file descriptor: exit code 1 with NO
94
+ // annotation, indistinguishable from a genuine test failure at the very
95
+ // point this script exists to make that distinguishable.
96
+ //
97
+ // Fixed by writing the annotation with fs.writeSync(1, ...) instead of
98
+ // process.stdout.write(...). writeSync is a direct, synchronous syscall to
99
+ // the fd — it is not subject to the Writable stream's internal async queue
100
+ // at all, so there is no buffer to race process.exit() against. This is
101
+ // belt: it holds even if something upstream changes how/when the process
102
+ // terminates. See below for suspenders (annotation ordered before the large
103
+ // stdout dump; process.exitCode instead of process.exit()).
104
+ // ---------------------------------------------------------------------------
105
+ // writeFullySync(fd, data) — fs.writeSync performs exactly ONE write(2)
106
+ // syscall attempt and returns the number of bytes actually written; it does
107
+ // NOT loop to guarantee the whole buffer lands, and a pipe fd can legitimately
108
+ // short-write under backpressure once the payload is large (BOBBIE, PR #402
109
+ // comment 5360992190). The single unlooped call this replaced discarded that
110
+ // return value entirely, so a short write silently truncated its output —
111
+ // exactly the class of silent-truncation defect this whole task (lr-e551b9)
112
+ // exists to eliminate, now against the raw TAP evidence trail instead of the
113
+ // verdict. This loops until every byte is confirmed written.
114
+ //
115
+ // `data` may be a Buffer or a string; if it is a string it is converted to a
116
+ // Buffer ONCE up front, and the loop advances over that Buffer by byte
117
+ // offset. This matters because fs.writeSync's offset/length/return-value
118
+ // semantics are BYTE-indexed always, but a JS string is indexed by UTF-16
119
+ // code unit — slicing a string by a byte count returned from a short write
120
+ // would misalign mid multi-byte UTF-8 sequence. Converting once avoids that
121
+ // mismatch entirely rather than trying to reconcile the two index spaces on
122
+ // every partial-write iteration.
123
+ //
124
+ // Any thrown error (e.g. EPIPE/EAGAIN) propagates uncaught — deliberately not
125
+ // swallowed here. This function is called from FAIL-path code whose only job
126
+ // is to make a non-zero exit legible; the exit code itself is already
127
+ // determined by classifyRun() before either write site runs (see
128
+ // process.exitCode below), so an uncaught throw here can only ever turn an
129
+ // already-nonzero process into a hard crash (still non-zero), never a FAIL
130
+ // verdict into exit 0. Swallowing the error here would risk exactly that.
131
+ //
132
+ // NON-ADVANCING WRITE GUARD (lr-e551b9 fold-in, PEACHES PR #402 BLOCKING).
133
+ // fs.writeSync's return value is the ONLY thing that advances `offset`; the
134
+ // Node docs do not rule out a 0-byte return (distinct from throwing EAGAIN),
135
+ // and this loop's sole invariant is that it always terminates. An unguarded
136
+ // `while (offset < buffer.length)` against a 0-byte return spins forever —
137
+ // on this specific script, the merge-gate wrapper whose entire purpose is
138
+ // turning a FAIL into a legible signal, an infinite loop here is strictly
139
+ // worse than the truncation bug it replaced: truncation still failed fast
140
+ // with a usable exit code, while a hang burns the runner until the workflow
141
+ // timeout kills it and produces NO verdict and NO annotation at all.
142
+ //
143
+ // A single 0-byte return is not necessarily fatal — a transient EAGAIN-like
144
+ // stall on a pipe under backpressure could plausibly resolve on the very
145
+ // next attempt without ever surfacing as a thrown error. But an unbounded
146
+ // RUN of 0-byte returns with no forward progress is exactly the spin this
147
+ // guard exists to rule out. MAX_CONSECUTIVE_ZERO_WRITES bounds that run:
148
+ // each 0-byte return increments a counter; any return >0 resets it; hitting
149
+ // the bound throws. Throwing (not returning/silently giving up) matches the
150
+ // existing EPIPE/EAGAIN posture directly above — an uncaught throw always
151
+ // exits non-zero, so it can never produce a false green, and it surfaces
152
+ // immediately in CI as a hard crash rather than a silent short-delivery.
153
+ var MAX_CONSECUTIVE_ZERO_WRITES = 100;
154
+
155
+ function writeFullySync(fd, data) {
156
+ var buffer = Buffer.isBuffer(data) ? data : Buffer.from(String(data), "utf8");
157
+ var offset = 0;
158
+ var consecutiveZeroWrites = 0;
159
+ while (offset < buffer.length) {
160
+ var written = fs.writeSync(fd, buffer, offset, buffer.length - offset);
161
+ if (written === 0) {
162
+ consecutiveZeroWrites += 1;
163
+ if (consecutiveZeroWrites >= MAX_CONSECUTIVE_ZERO_WRITES) {
164
+ throw new Error(
165
+ "writeFullySync: fs.writeSync returned 0 " + consecutiveZeroWrites +
166
+ " times in a row with no forward progress (delivered " + offset + " of " +
167
+ buffer.length + " bytes) — aborting instead of spinning forever."
168
+ );
169
+ }
170
+ continue;
171
+ }
172
+ consecutiveZeroWrites = 0;
173
+ offset += written;
174
+ }
175
+ }
176
+
177
+ function emitAnnotation(message) {
178
+ // GitHub Actions workflow-command syntax. `%`, CR and LF must be escaped
179
+ // in the message text per GitHub's documented encoding for `::error::` —
180
+ // https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions
181
+ var escaped = String(message)
182
+ .replace(/%/g, "%25")
183
+ .replace(/\r/g, "%0D")
184
+ .replace(/\n/g, "%0A");
185
+ writeFullySync(1, "::error::" + escaped + "\n");
186
+ }
187
+
188
+ // classifyRun() is the pure decision core of this script: given the raw
189
+ // spawnSync() result plus the bucketed RESULT-line data, decide whether the
190
+ // run passes and, if not, exactly WHY. Pulled out of the top-level script
191
+ // body (which is otherwise unavoidably I/O-coupled — it shells out to a
192
+ // real `node --test`) specifically so the signal-death path (the highest-
193
+ // value item in lr-e551b9) is exercisable by a fast, deterministic unit
194
+ // test against a hand-built `result` object, without spawning a real child
195
+ // process or running the real suite.
196
+ //
197
+ // Returns { ok: bool, exitCode: number, reason: string|null, kind: string }.
198
+ // `kind` names which of this script's distinct FAIL routes produced the
199
+ // verdict (see the module header's WHAT THIS DOES AND DOES NOT CATCH /
200
+ // MECHANISM sections for the full list). Checked in this precedence order
201
+ // when multiple conditions are live at once (lr-e551b9 fold-in, PR #401):
202
+ // 'spawn-error' > 'missing-files' > 'signal-death' > 'below-floor' >
203
+ // 'test-failure' (a genuine node --test non-zero exit with no wrapper-level
204
+ // condition tripped — i.e. an ordinary named test failure, not a wrapper
205
+ // failure) > 'ok'. missing-files outranks signal-death because it names a
206
+ // specific file, the most actionable cause available; signal-death outranks
207
+ // below-floor because a signal-killed run IS the truncated run that
208
+ // produces a below-floor count in the first place — see the check itself
209
+ // for the full reasoning.
210
+ function classifyRun(result, files, resultsByFile, totalTests, floor) {
211
+ if (result.error) {
212
+ return {
213
+ ok: false,
214
+ exitCode: 1,
215
+ kind: "spawn-error",
216
+ reason: "failed to spawn node --test: " + result.error.message,
217
+ };
218
+ }
219
+
220
+ var missingFiles = files.filter(function (f) {
221
+ var abs = path.resolve(f);
222
+ return !resultsByFile[abs];
223
+ });
224
+
225
+ if (missingFiles.length > 0) {
226
+ return {
227
+ ok: false,
228
+ exitCode: 1,
229
+ kind: "missing-files",
230
+ reason: (
231
+ missingFiles.length + " test file(s) reported ZERO test results — " +
232
+ "treated as a truncated/incomplete run, not a pass, regardless of the overall exit code. This is " +
233
+ "exactly the failure class lr-795882 fixed (MILLER, lr-a7b03e): a file whose tests silently vanish " +
234
+ "while the overall run still exits 0.\n " + missingFiles.join("\n ")
235
+ ),
236
+ };
237
+ }
238
+
239
+ if (result.status === null) {
240
+ // The child `node --test` ORCHESTRATOR process itself (not an
241
+ // individual per-file worker/subprocess it manages internally — Node's
242
+ // own test runner already reports THOSE as ordinary test:fail events
243
+ // with a `signal` field, which is why they show up as RESULT lines
244
+ // above and never reach this branch) was killed by a signal rather than
245
+ // exiting normally. status is null in exactly this case (Node's
246
+ // child_process docs: exactly one of status/signal is non-null).
247
+ // Previously this exited 1 with ZERO explanatory output — indistinguishable
248
+ // from a genuine test failure at the exit-code level. lr-e551b9.
249
+ //
250
+ // Checked BEFORE below-floor (PEACHES PR #401 finding, lr-e551b9
251
+ // fold-in): an OOM-killed/externally-signaled orchestrator IS a
252
+ // truncated run, and a truncated run is exactly what produces a
253
+ // below-floor total — the two conditions fire TOGETHER in the ordinary
254
+ // case this whole check exists to make legible. Reporting below-floor
255
+ // here would name the wrong cause precisely when the cause matters
256
+ // most (the run still fails either way — exitCode stays 1 — but the
257
+ // diagnostic would mislabel it). missing-files is still checked above
258
+ // this because it names a more specific, actionable culprit (an actual
259
+ // file) when both conditions are live.
260
+ return {
261
+ ok: false,
262
+ exitCode: 1,
263
+ kind: "signal-death",
264
+ reason: (
265
+ "node --test was killed by " + result.signal + " — likely OOM or an external kill (e.g. CI job " +
266
+ "timeout/cancellation); no test failure was reported because the process did not exit normally. " +
267
+ "This is NOT the same as a per-file worker crash (Node's test runner already reports those as a " +
268
+ "named test:fail with a signal field); this is the top-level orchestrator process itself dying."
269
+ ),
270
+ };
271
+ }
272
+
273
+ if (totalTests < floor) {
274
+ return {
275
+ ok: false,
276
+ exitCode: 1,
277
+ kind: "below-floor",
278
+ reason: (
279
+ "total executed test count " + totalTests +
280
+ " is below the floor of " + floor + " even though every file reported at least one result — " +
281
+ "likely a large in-file test drop. See this script's header for what the floor does and does not " +
282
+ "catch, and how to update it for a deliberate suite reduction."
283
+ ),
284
+ };
285
+ }
286
+
287
+ if (result.status !== 0) {
288
+ return {
289
+ ok: false,
290
+ exitCode: result.status,
291
+ kind: "test-failure",
292
+ reason: (
293
+ "node --test exited " + result.status + " with a named test failure above (see the TAP `not ok` " +
294
+ "line(s)) — this is an ordinary test failure, not a wrapper-level condition."
295
+ ),
296
+ };
297
+ }
298
+
299
+ return { ok: true, exitCode: 0, kind: "ok", reason: null };
300
+ }
301
+
302
+ module.exports = {
303
+ classifyRun: classifyRun,
304
+ emitAnnotation: emitAnnotation,
305
+ writeFullySync: writeFullySync,
306
+ };
307
+
308
+ // Everything below only runs when this file is executed directly (`node
309
+ // scripts/check-test-count.js <file...>`), not when required as a module by
310
+ // a unit test.
311
+ if (require.main === module) {
312
+ var files = process.argv.slice(2);
313
+ if (files.length === 0) {
314
+ process.stderr.write("[check-test-count] no test files given (expected: node scripts/check-test-count.js <file...>)\n");
315
+ process.exit(1);
316
+ }
317
+
318
+ var REPORTER_PATH = path.join(__dirname, "test-file-completion-reporter.js");
319
+
320
+ var result = spawnSync(process.execPath, [
321
+ "--test",
322
+ "--test-reporter=tap", "--test-reporter-destination=stdout",
323
+ "--test-reporter=" + REPORTER_PATH, "--test-reporter-destination=stderr",
324
+ ].concat(files), {
325
+ stdio: ["inherit", "pipe", "pipe"],
326
+ encoding: "utf8",
327
+ maxBuffer: 64 * 1024 * 1024,
328
+ });
329
+
330
+ // The custom reporter's RESULT lines are the only thing routed to stderr —
331
+ // forward everything else Node itself wrote to stderr (real errors,
332
+ // warnings) so a normal `npm test` run still surfaces them, then parse the
333
+ // RESULT lines separately below.
334
+ var stderrLines = (result.stderr || "").split("\n");
335
+ var resultsByFile = Object.create(null);
336
+ var passCount = 0;
337
+ var failCount = 0;
338
+
339
+ stderrLines.forEach(function (line) {
340
+ var match = /^RESULT (pass|fail) (.+)$/.exec(line);
341
+ if (!match) {
342
+ if (line) process.stderr.write(line + "\n");
343
+ return;
344
+ }
345
+ var kind = match[1];
346
+ var file = match[2];
347
+ if (!resultsByFile[file]) resultsByFile[file] = 0;
348
+ resultsByFile[file] += 1;
349
+ if (kind === "pass") passCount += 1;
350
+ else failCount += 1;
351
+ });
352
+
353
+ var totalTests = passCount + failCount;
354
+ var verdict = classifyRun(result, files, resultsByFile, totalTests, TEST_COUNT_FLOOR);
355
+
356
+ // DELIVERY ORDER (lr-e551b9 reopen). The annotation is emitted BEFORE the
357
+ // large TAP dump below, not after: emitAnnotation() now uses
358
+ // fs.writeSync(1, ...), a direct synchronous syscall that bypasses the
359
+ // stdout Writable's async queue entirely, so this ordering is not load-
360
+ // bearing for the annotation's own delivery — but it also means the
361
+ // annotation is never at risk of landing "behind" a dump that is itself
362
+ // subject to the async-pipe race (see below), belt-and-suspenders rather
363
+ // than relying on ordering alone.
364
+ if (!verdict.ok) {
365
+ var line = "[check-test-count] FAIL (" + verdict.kind + "): " + verdict.reason;
366
+ process.stderr.write(line + "\n");
367
+ // Surfaced as a check-run annotation too (see emitAnnotation's own
368
+ // comment) — this is what makes the reason reachable without the raw
369
+ // job log, for every FAIL route including the previously-silent
370
+ // signal-death path.
371
+ emitAnnotation(line);
372
+ }
373
+
374
+ // The raw TAP dump is written with writeFullySync too, for the same reason
375
+ // as the annotation above: process.stdout.write() queues asynchronously
376
+ // once a pipe's 64KB kernel buffer fills, and a ~1400-test TAP blob is
377
+ // multi-MB — far larger than that buffer. Losing the raw output is a
378
+ // real, independent problem even though the annotation above no longer
379
+ // depends on it: a developer reading a captured `npm test` run should
380
+ // still see the actual TAP text, not a truncation artifact. A single
381
+ // unlooped fs.writeSync call here would carry the same short-write risk
382
+ // as the annotation write did (BOBBIE, PR #402) — writeFullySync loops
383
+ // until the whole multi-MB buffer is confirmed delivered.
384
+ if (result.stdout) writeFullySync(1, result.stdout);
385
+
386
+ // process.exitCode (not process.exit()) lets the event loop drain
387
+ // naturally instead of tearing the process down immediately — the second
388
+ // half of MILLER's recommended (a)+(b) combination. Nothing below this
389
+ // line can reset process.exitCode or call process.exit(0): this is the
390
+ // last statement in the script, so there is no later code path that could
391
+ // turn a red run green. The FAIL-OPEN CONSTRAINT (lr-795882, engram
392
+ // 7613980) requires this be verified, not assumed — every exit-1
393
+ // condition above still sets verdict.exitCode to 1 or the child's own
394
+ // non-zero status; process.exitCode is set from that value unconditionally
395
+ // and nothing else touches it.
396
+ process.exitCode = verdict.exitCode;
397
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ //
3
+ // test-file-completion-reporter.js — custom `node --test` reporter for
4
+ // scripts/check-test-count.js (lr-795882, hardened after PEACHES/BOBBIE PR
5
+ // #395 review).
6
+ //
7
+ // WHY A CUSTOM REPORTER, NOT TAP TEXT PARSING: when `node --test` is given
8
+ // multiple file arguments, all of them run in ONE shared process and their
9
+ // results interleave into a single flat TAP stream with no per-file marker
10
+ // in the human-readable text — there is no way to tell from TAP output
11
+ // alone whether every file in the glob actually reported. An earlier
12
+ // version of this check ran each file as its OWN `node --test` invocation
13
+ // to get per-file attribution, but that changes timing/jitter
14
+ // characteristics enough to expose an unrelated pre-existing flake
15
+ // (test/project-connection-hydrate-session-model-lr-041af8.test.js's
16
+ // millisecond-tie-break race in findRestoredActiveSession, filed
17
+ // separately as a follow-up) — a mechanism change should not itself
18
+ // introduce new failure risk. Node's reporter API (this file) receives a
19
+ // `file` field on every test:pass/test:fail event regardless of TAP's own
20
+ // text output, so this gets real per-file attribution from the SAME
21
+ // single-process run `npm test` has always used, with no isolation/timing
22
+ // change at all.
23
+ //
24
+ // CONTRACT: this reporter is used TOGETHER with the default `tap` reporter
25
+ // (`node --test --test-reporter=tap --test-reporter-destination=stdout
26
+ // --test-reporter=./test-file-completion-reporter.js
27
+ // --test-reporter-destination=stderr`, see check-test-count.js) — Node
28
+ // supports multiple --test-reporter flags, each with its own
29
+ // --test-reporter-destination, so a developer running `npm test` still
30
+ // sees normal TAP output on stdout; this reporter's machine-readable
31
+ // RESULT lines go to a separate stream that scripts/check-test-count.js
32
+ // parses. Output shape, one line per test:pass/test:fail event:
33
+ // RESULT <pass|fail> <absolute-file-path>
34
+
35
+ module.exports = async function* fileCompletionReporter(source) {
36
+ for await (var event of source) {
37
+ if (event.type === "test:pass" || event.type === "test:fail") {
38
+ var file = (event.data && event.data.file) || "";
39
+ var kind = event.type === "test:pass" ? "pass" : "fail";
40
+ yield "RESULT " + kind + " " + file + "\n";
41
+ }
42
+ }
43
+ };