@clagentic/console 1.9.0-beta.1 → 1.9.0-beta.2
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.
- package/bin/cli.js +12 -1
- package/lib/agents.js +13 -3
- package/lib/build-sha.json +2 -2
- package/lib/cli/ipc-subcommands.js +40 -4
- package/lib/daemon.js +25 -1
- package/lib/project-connection.js +15 -2
- package/lib/project-loop.js +46 -2
- package/lib/project-sessions.js +31 -3
- package/lib/project-user-message.js +70 -3
- package/lib/project.js +7 -1
- package/lib/public/app.js +14 -4
- package/lib/public/css/base.css +14 -0
- package/lib/public/css/home-hub.css +28 -8
- package/lib/public/css/icon-strip.css +17 -0
- package/lib/public/css/messages.css +11 -0
- package/lib/public/css/mobile-nav.css +22 -0
- package/lib/public/css/sidebar.css +15 -0
- package/lib/public/css/title-bar.css +10 -1
- package/lib/public/index.html +1 -0
- package/lib/public/modules/activity-latch.js +159 -0
- package/lib/public/modules/activity-state.js +157 -0
- package/lib/public/modules/app-connection.js +10 -4
- package/lib/public/modules/app-favicon.js +88 -1
- package/lib/public/modules/app-home-hub.js +14 -11
- package/lib/public/modules/app-loop-ui.js +86 -2
- package/lib/public/modules/app-messages.js +118 -54
- package/lib/public/modules/app-panels.js +91 -32
- package/lib/public/modules/app-projects.js +28 -8
- package/lib/public/modules/app-rate-limit.js +13 -1
- package/lib/public/modules/sidebar-mobile.js +32 -22
- package/lib/public/modules/sidebar-projects.js +42 -14
- package/lib/public/modules/sidebar-sessions.js +168 -48
- package/lib/public/modules/tools.js +11 -39
- package/lib/sdk-bridge.js +301 -22
- package/lib/sdk-message-processor.js +98 -15
- package/lib/sdk-skill-discovery.js +46 -6
- package/lib/sdk-slash-enrichment.js +5 -2
- package/lib/server-hub-sessions.js +70 -0
- package/lib/server.js +24 -22
- package/lib/session-activity.js +8 -1
- package/lib/sessions.js +47 -1
- package/lib/smtp.js +10 -1
- package/lib/ws-schema.js +16 -0
- package/lib/yoke/adapters/claude.js +7 -1
- package/lib/yoke/adapters/codex.js +219 -31
- package/package.json +2 -2
- package/scripts/check-test-count.js +397 -0
- package/scripts/test-file-completion-reporter.js +43 -0
- package/lib/model-context-windows.js +0 -74
- 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
|
+
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* model-context-windows.js — shared source of truth for the model context-window
|
|
3
|
-
* map and beta-aware resolution. (lr-336f)
|
|
4
|
-
*
|
|
5
|
-
* This is the CJS backend copy. The ES module (browser) copy lives at
|
|
6
|
-
* lib/public/modules/model-context-windows.js. A CI test
|
|
7
|
-
* (test/model-context-windows-parity.test.js) asserts both files produce
|
|
8
|
-
* identical resolution results so they cannot silently drift.
|
|
9
|
-
*
|
|
10
|
-
* When adding a new model: update BOTH this file and
|
|
11
|
-
* lib/public/modules/model-context-windows.js.
|
|
12
|
-
* The parity test will fail if they disagree.
|
|
13
|
-
*
|
|
14
|
-
* Keep this module dependency-light: no project imports, no Node built-ins.
|
|
15
|
-
* That constraint is what lets it stay close to the browser copy.
|
|
16
|
-
*
|
|
17
|
-
* The map is keyed by a lowercase model-name substring. Lookup is a linear scan so
|
|
18
|
-
* insertion order matters for overlapping substrings — more-specific keys should
|
|
19
|
-
* appear before less-specific ones.
|
|
20
|
-
*
|
|
21
|
-
* Fallback-only (lr-d91ecf): this map is consulted only when the vendor
|
|
22
|
-
* hasn't reported a context window for the active model at runtime
|
|
23
|
-
* (resolveModelContextWindow returns 0 for anything not listed here, and
|
|
24
|
-
* callers degrade gracefully — see resolveContextWindow in app-panels.js,
|
|
25
|
-
* which falls back further to the SDK-reported value before a last-resort
|
|
26
|
-
* default). A vendor-reported window always wins when present; this table
|
|
27
|
-
* exists only to cover models/betas the vendor's runtime response doesn't
|
|
28
|
-
* carry a window for.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
var KNOWN_CONTEXT_WINDOWS = {
|
|
32
|
-
"opus-4-6": 1000000,
|
|
33
|
-
"claude-sonnet-4": 1000000,
|
|
34
|
-
"gpt-5.5": 1048576,
|
|
35
|
-
"gpt-5.4": 1048576,
|
|
36
|
-
"gpt-5.3": 1048576,
|
|
37
|
-
"gpt-5.2": 1048576,
|
|
38
|
-
"gpt-4.1": 1047576,
|
|
39
|
-
"o3": 200000,
|
|
40
|
-
"o4-mini": 200000,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Resolve the context window for a model identifier, applying the beta-first
|
|
45
|
-
* rule for the context-1m beta.
|
|
46
|
-
*
|
|
47
|
-
* activeBetas: optional array of active beta strings. When any entry contains
|
|
48
|
-
* "context-1m", the true window is 1M regardless of the model — the SDK
|
|
49
|
-
* reports the model's base window in ModelUsage but the beta extends it.
|
|
50
|
-
*
|
|
51
|
-
* Returns the window size in tokens, or 0 when the model is not in
|
|
52
|
-
* KNOWN_CONTEXT_WINDOWS and no beta applies. Callers treat 0 as "unknown"
|
|
53
|
-
* and should degrade cleanly (skip any window-based guard rather than
|
|
54
|
-
* guessing a default).
|
|
55
|
-
*/
|
|
56
|
-
function resolveModelContextWindow(model, activeBetas) {
|
|
57
|
-
// Beta check must come first — the SDK does not reflect the extended window.
|
|
58
|
-
if (Array.isArray(activeBetas)) {
|
|
59
|
-
for (var bi = 0; bi < activeBetas.length; bi++) {
|
|
60
|
-
if (activeBetas[bi].indexOf("context-1m") !== -1) return 1000000;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if (!model) return 0;
|
|
64
|
-
var lc = model.toLowerCase();
|
|
65
|
-
// UI beta-toggle appends [1m] to the model name
|
|
66
|
-
if (lc.indexOf("[1m]") !== -1) return 1000000;
|
|
67
|
-
var keys = Object.keys(KNOWN_CONTEXT_WINDOWS);
|
|
68
|
-
for (var i = 0; i < keys.length; i++) {
|
|
69
|
-
if (lc.indexOf(keys[i]) !== -1) return KNOWN_CONTEXT_WINDOWS[keys[i]];
|
|
70
|
-
}
|
|
71
|
-
return 0;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
module.exports = { KNOWN_CONTEXT_WINDOWS: KNOWN_CONTEXT_WINDOWS, resolveModelContextWindow: resolveModelContextWindow };
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* model-context-windows.js — shared source of truth for the model context-window
|
|
3
|
-
* map and beta-aware resolution. (lr-336f)
|
|
4
|
-
*
|
|
5
|
-
* This is the ES module (browser) copy. The CJS backend copy lives at
|
|
6
|
-
* lib/model-context-windows.js. A CI test (test/model-context-windows-parity.test.js)
|
|
7
|
-
* asserts both files produce identical resolution results so they cannot silently drift.
|
|
8
|
-
*
|
|
9
|
-
* When adding a new model: update BOTH this file and lib/model-context-windows.js.
|
|
10
|
-
* The parity test will fail if they disagree.
|
|
11
|
-
*
|
|
12
|
-
* The map is keyed by a lowercase model-name substring. Lookup is a linear scan so
|
|
13
|
-
* insertion order matters for overlapping substrings — more-specific keys should
|
|
14
|
-
* appear before less-specific ones.
|
|
15
|
-
*
|
|
16
|
-
* Fallback-only (lr-d91ecf): this map is consulted only when the vendor
|
|
17
|
-
* hasn't reported a context window for the active model at runtime
|
|
18
|
-
* (resolveModelContextWindow returns 0 for anything not listed here, and
|
|
19
|
-
* callers degrade gracefully — see resolveContextWindow in app-panels.js,
|
|
20
|
-
* which falls back further to the SDK-reported value before a last-resort
|
|
21
|
-
* default). A vendor-reported window always wins when present; this table
|
|
22
|
-
* exists only to cover models/betas the vendor's runtime response doesn't
|
|
23
|
-
* carry a window for.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export var KNOWN_CONTEXT_WINDOWS = {
|
|
27
|
-
"opus-4-6": 1000000,
|
|
28
|
-
"claude-sonnet-4": 1000000,
|
|
29
|
-
"gpt-5.5": 1048576,
|
|
30
|
-
"gpt-5.4": 1048576,
|
|
31
|
-
"gpt-5.3": 1048576,
|
|
32
|
-
"gpt-5.2": 1048576,
|
|
33
|
-
"gpt-4.1": 1047576,
|
|
34
|
-
"o3": 200000,
|
|
35
|
-
"o4-mini": 200000,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Resolve the context window for a model identifier, applying the beta-first
|
|
40
|
-
* rule for the context-1m beta.
|
|
41
|
-
*
|
|
42
|
-
* activeBetas: optional array of active beta strings. When any entry contains
|
|
43
|
-
* "context-1m", the true window is 1M regardless of the model — the SDK
|
|
44
|
-
* reports the model's base window in ModelUsage but the beta extends it.
|
|
45
|
-
*
|
|
46
|
-
* Returns the window size in tokens, or 0 when the model is not in
|
|
47
|
-
* KNOWN_CONTEXT_WINDOWS and no beta applies. Callers treat 0 as "unknown"
|
|
48
|
-
* and should degrade cleanly (skip any window-based guard rather than
|
|
49
|
-
* guessing a default).
|
|
50
|
-
*
|
|
51
|
-
* Note: the resolveContextWindow wrapper in app-panels.js adds an sdkValue
|
|
52
|
-
* fallback and a hasBeta() store accessor on top of this core function.
|
|
53
|
-
* This function itself is store-agnostic.
|
|
54
|
-
*/
|
|
55
|
-
export function resolveModelContextWindow(model, activeBetas) {
|
|
56
|
-
// Beta check must come first — the SDK does not reflect the extended window.
|
|
57
|
-
if (Array.isArray(activeBetas)) {
|
|
58
|
-
for (var bi = 0; bi < activeBetas.length; bi++) {
|
|
59
|
-
if (activeBetas[bi].indexOf("context-1m") !== -1) return 1000000;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (!model) return 0;
|
|
63
|
-
var lc = model.toLowerCase();
|
|
64
|
-
// UI beta-toggle appends [1m] to the model name
|
|
65
|
-
if (lc.indexOf("[1m]") !== -1) return 1000000;
|
|
66
|
-
var keys = Object.keys(KNOWN_CONTEXT_WINDOWS);
|
|
67
|
-
for (var i = 0; i < keys.length; i++) {
|
|
68
|
-
if (lc.indexOf(keys[i]) !== -1) return KNOWN_CONTEXT_WINDOWS[keys[i]];
|
|
69
|
-
}
|
|
70
|
-
return 0;
|
|
71
|
-
}
|