From 05f5dec4bffc27283ae0d1ccf1706b1506137ed5 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 25 Aug 2026 06:33:35 +0000 Subject: [PATCH] fix(scripts): bound objectui-range --help's self-read to the header prefix --help built its usage text by keeping every column-0 `//` line in the whole file, not just the header. Six mid-file implementation comments (the pinAt() helper's rationale, and this file's own self-test section banner) leaked into the usage text a reader pastes. The header IS a contiguous prefix of the file (right after the shebang), so printHelp() now walks lines in order and stops at the first non-`//` line once the block has started -- a takeWhile, not a filter -- so a column-0 comment added anywhere later in the file can never reach --help again. Pinned as a self-test assertion (the file's own #4843 idiom): --help still carries the real header, and none of the six measured stray lines. Reverse-verified: mutating printHelp() back to the old unbounded filter flips the new pin red; rebuilding the fix restores green. column-0 `//` count is unchanged at 79 -- the new rationale uses a `/** */` block, per PR #11951's byte-identity concern for this file. --- scripts/objectui-range.mjs | 51 ++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/scripts/objectui-range.mjs b/scripts/objectui-range.mjs index f662d862c9..231bdd0902 100644 --- a/scripts/objectui-range.mjs +++ b/scripts/objectui-range.mjs @@ -105,15 +105,27 @@ const SHOW_EXCLUDED = has('--all'); * to its stdout and then `process.exit(0)` — its process ended mid-import * carrying a SUCCESS status, which no caller reading the status alone can * tell apart from a clean import. + * + * BOUNDED to the header, not every column-0 `//` line in the file (#11952). + * A bare `.filter(startsWith('//'))` has no notion of "the header": it took + * EVERY column-0 `//` line anywhere in the file, so an ordinary implementation + * comment written at column 0 later in the file — a helper's one-line + * rationale, a self-test section banner — silently became part of the usage + * text a reader pastes. The header IS a contiguous prefix of this file (right + * after the shebang), so this walks lines in order, skips the shebang before + * the block starts, and STOPS at the first line that is not a `//` line once + * the block has started — a `takeWhile`, not a `filter`. That makes "add a + * column-0 comment anywhere later" structurally unable to reach `--help` + * again, rather than merely detectable after the fact. */ function printHelp() { - console.log( - readFileSync(fileURLToPath(import.meta.url), 'utf8') - .split('\n') - .filter((l) => l.startsWith('//')) - .map((l) => l.slice(3)) - .join('\n'), - ); + const lines = readFileSync(fileURLToPath(import.meta.url), 'utf8').split('\n'); + const start = lines.findIndex((l) => l.startsWith('//')); + const header = []; + for (let i = start; i >= 0 && i < lines.length && lines[i].startsWith('//'); i++) { + header.push(lines[i].slice(3)); + } + console.log(header.join('\n')); return 0; } @@ -614,6 +626,31 @@ function selfTest() { cliJson.releasing.filter((r) => r.breaking).length === 2, JSON.stringify(cliJson.releasing.map((r) => r.breakingSource)), ); + + // --- #11952: `--help`'s self-read is bound to the header, not every + // column-0 `//` line in the file. Pin the acceptance criterion literally: + // the header is still there, and none of the six measured stray lines — + // an internal helper's rationale (pinAt, mid-`main`) and this very + // self-test's own section banner — leak into the usage text. + const helpOut = run(['--help']); + check( + '--help still carries the real header (Usage/Env sections intact)', + helpOut.includes('Usage:') && + helpOut.includes('node scripts/objectui-range.mjs [new-rev]') && + helpOut.includes('OBJECTUI_ROOT=/path/to/objectui'), + helpOut, + ); + const strayLines = [ + 'Resolve the objectui SHA pinned at a given framework rev', + 'Self-test (#4843) — the repo idiom for a `scripts/` gate', + 'git repo carrying the exact shapes measured on the real range', + 'code over it, assert the ARTIFACT (the markdown a maintainer pastes)', + ]; + check( + '--help does NOT leak mid-file implementation comments (#11952)', + strayLines.every((s) => !helpOut.includes(s)), + helpOut, + ); } finally { rmSync(tmp, { recursive: true, force: true }); }