Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

Commit 96cf3d2

Browse files
claude[bot]claude
andauthored
fix(scripts): make the three host-dependent scripts/__tests__ files run on a stock macOS host (#8511)
Three files in `scripts/__tests__` passed on Linux CI and failed on a stock macOS host on byte-identical bytes. None of the four assertions was about the tree; each read a host command or a host behaviour. check-bash32-floor `--self-test` — the sharpest of the three, and fixed in the GATE rather than in the test that runs it. Every probe, harness and `bash -n` leg drives a bash-4+ construct through the host's own bash, and the host this gate exists for is macOS: bash 3.2.57, where `coproc`/`|&`/`&>>` are syntax errors, `mapfile` is not a builtin there is anything to disable, and `[[ -v ]]` is a conditional operator `bash -n` also refuses. A floor gate whose battery cannot run on the floor it declares is a gate asserting something it has never demonstrated. The self-test now states that premise, detects it by CAPABILITY (a bash-4 operator and a bash-4 builtin, never a platform name), and narrows exactly those cases where the host cannot judge them — counted, printed per case, and carried in the verdict line, because a narrowing is a real coverage loss. The SCAN is untouched and is not narrowed: it is pure JS and judges a 3.2 host exactly as it judges CI. check-control-bytes — `expect(declined.stdout).toBe('')` asserted one userland's way of reporting a refusal rather than the refusal. GNU grep >= 3.5 writes `grep: <f>: binary file matches` to stderr and leaves stdout empty; BSD grep writes `Binary file <f> matches` to stdout. Both refuse and both print no line of the file, which is the search outage the case is about, so the assertion is now written against matching lines. A shim first on PATH pins the BSD reading here on Linux. ensure-chromium-ready.sh — a bare `timeout` is GNU coreutils, and a stock macOS host has neither it nor Homebrew's `gtimeout`. The bound did not merely go missing there: the call failed at 127 before `install-deps` ran, so the recovery path could not recover. `run_bounded` resolves `timeout`, then `gtimeout`, then bounds the call from bash itself (bash 3.2 clean, as this repo's floor requires) and reports the same 124 either way. Two cases run under a PATH where both binaries are genuinely absent, with a control that proves they are. ⛔ Nothing is skipped, disabled or quarantined, and no assertion is weakened to accommodate a host: the GNU paths are still measured by the same cases on the same run. Claude-Session: https://claude.ai/code/session_01FhBNJcLRZLe8M87VcUgpKr Co-authored-by: Claude <noreply@anthropic.com>
1 parent b8b0ac1 commit 96cf3d2

4 files changed

Lines changed: 363 additions & 11 deletions

File tree

‎scripts/__tests__/check-control-bytes.test.ts‎

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,13 @@ describe('repo state — the gate is green on this tree', () => {
306306
* GNU grep prefixes `grep: <file>: `, older builds print `Binary file <file>
307307
* matches` on stdout. Reading BOTH streams means this does not depend on which.
308308
*/
309-
function contentSearch(needle: string, file: string, cwd: string = repoRoot) {
310-
const run = spawnSync('grep', ['-n', needle, file], { cwd, encoding: 'utf8' });
309+
function contentSearch(
310+
needle: string,
311+
file: string,
312+
cwd: string = repoRoot,
313+
env: NodeJS.ProcessEnv = process.env,
314+
) {
315+
const run = spawnSync('grep', ['-n', needle, file], { cwd, encoding: 'utf8', env });
311316
const both = `${run.stdout ?? ''}${run.stderr ?? ''}`;
312317
return {
313318
status: run.status,
@@ -356,7 +361,15 @@ describe('objectstack#5425 — the file that started this is readable again', ()
356361
fs.writeFileSync(probe, `const includeKey = 1;${String.fromCharCode(0)}\n`);
357362
const declined = contentSearch('includeKey', probe, dir);
358363
expect(declined.refusedAsBinary, 'grep must decline a NUL-bearing file').toBe(true);
359-
expect(declined.stdout, 'and print no line at all — that is the search outage').toBe('');
364+
expect(
365+
declined.stdout,
366+
'and print no MATCHING LINE — that is the search outage. ⚠️ objectui#8404: this read ' +
367+
"`toBe('')` until a stock macOS host reddened it on bytes CI called green. An empty " +
368+
'stdout is not the outage, it is one userland\'s way of reporting it: GNU grep >= 3.5 ' +
369+
'writes its refusal to stderr and leaves stdout empty, BSD grep writes ' +
370+
'`Binary file <path> matches` to STDOUT. Both refuse, both print no line of the file, ' +
371+
'and the refusal itself is already pinned by `refusedAsBinary` above.',
372+
).not.toMatch(/^\d+:/m);
360373
expect(declined.status, 'while exiting 0, which is what makes the outage silent').toBe(0);
361374
} finally {
362375
fs.rmSync(dir, { recursive: true, force: true });
@@ -375,6 +388,58 @@ describe('objectstack#5425 — the file that started this is readable again', ()
375388
* there would be a fabricated pin, so it is asserted only on the byte's absence,
376389
* which is the harm it actually had: an unreviewable literal.
377390
*/
391+
/**
392+
* ⭐ objectui#8404 — the two assertions above hold on EITHER grep userland.
393+
*
394+
* Established without a macOS host, because the discriminator is not the
395+
* platform: it is which stream grep writes its refusal to. GNU grep 3.11 (this
396+
* container, and what CI runs) writes `grep: <f>: binary file matches` to
397+
* stderr and leaves stdout empty; BSD grep writes `Binary file <f> matches` to
398+
* stdout. Both exit 0 and both print no line of the file. A shim first on PATH
399+
* stands in for the second, so the host-independence is pinned here, on Linux,
400+
* on every run — ⛔ not left as a claim nobody can re-measure.
401+
*/
402+
describe('objectui#8404 — the refusal is read the same on either grep userland', () => {
403+
it('recognises the BSD spelling, which arrives on stdout', () => {
404+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'control-bytes-bsd-grep-'));
405+
try {
406+
const shim = path.join(dir, 'grep');
407+
fs.writeFileSync(
408+
shim,
409+
[
410+
'#!/bin/sh',
411+
'# Stands in for BSD grep declining a binary file: the refusal on STDOUT,',
412+
'# exit 0, and no line of the file. $3 is the path, after `-n <needle>`.',
413+
'printf "Binary file %s matches\\n" "$3"',
414+
'exit 0',
415+
'',
416+
].join('\n'),
417+
);
418+
fs.chmodSync(shim, 0o755);
419+
fs.writeFileSync(path.join(dir, 'probe.ts'), 'const includeKey = 1;\n');
420+
421+
const bsd = contentSearch('includeKey', 'probe.ts', dir, {
422+
...process.env,
423+
PATH: `${dir}${path.delimiter}${process.env.PATH ?? ''}`,
424+
});
425+
426+
// The control: the shim really is the grep that ran, or this measures GNU
427+
// grep again and proves nothing about the other userland.
428+
expect(bsd.stdout, 'the shim on PATH was not the grep that ran').toMatch(/^Binary file /m);
429+
expect(bsd.refusedAsBinary, 'the BSD spelling must be read as the refusal it is').toBe(true);
430+
expect(
431+
bsd.stdout,
432+
'and it is not a line of the file — which is why the search-outage assertion is written ' +
433+
"against matching lines rather than against an empty stdout (the `toBe('')` spelling " +
434+
'was false here, and only here, which is how objectui#8404 was found).',
435+
).not.toMatch(/^\d+:/m);
436+
expect(bsd.status, 'exit 0 either way — that is what makes the outage silent').toBe(0);
437+
} finally {
438+
fs.rmSync(dir, { recursive: true, force: true });
439+
}
440+
});
441+
});
442+
378443
describe('objectstack#5450 — the four baselined files are clean', () => {
379444
const cleaned = [
380445
{ file: 'packages/core/src/evaluator/listConditional.ts', grepFor: 'warnedError' },

‎scripts/__tests__/ensure-chromium-ready.test.ts‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ function marker(name: string): string {
6363
return path.join(fs.mkdtempSync(path.join(os.tmpdir(), `os-5304-${name}-`)), 'deps-ran');
6464
}
6565

66+
/**
67+
* A PATH carrying the externals this script needs and NOTHING else — in
68+
* particular neither `timeout` nor `gtimeout`.
69+
*
70+
* objectui#8404. `timeout` is GNU coreutils and a stock macOS host has neither
71+
* it nor Homebrew's `gtimeout`. Two of the cases in this file were red there on
72+
* bytes CI called green, because the bare `timeout` call failed at 127 before
73+
* the dependency install ever ran.
74+
*
75+
* ⚠️ The stand-in is a CAPABILITY, not a platform name: what makes those hosts
76+
* different is the absent binary, so hiding the binary reproduces it exactly —
77+
* on Linux, in this container, with no macOS anywhere. A
78+
* `process.platform === 'darwin'` skip would have measured nothing and would
79+
* red again on the next non-GNU host.
80+
*/
81+
function pathWithoutTimeout(): { dir: string; env: Record<string, string> } {
82+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-8404-no-timeout-'));
83+
for (const tool of ['bash', 'rm', 'sleep', 'touch']) {
84+
const found = spawnSync('sh', ['-c', `command -v ${tool}`], { encoding: 'utf8' }).stdout.trim();
85+
if (!found) throw new Error(`cannot build the restricted PATH: this host has no ${tool}`);
86+
fs.symlinkSync(found, path.join(dir, tool));
87+
}
88+
return { dir, env: { PATH: dir } };
89+
}
90+
6691
describe('ensure-chromium-ready.sh — apt is off the happy path', () => {
6792
it('never invokes the dependency install when Chromium already launches', () => {
6893
const ran = marker('happy');
@@ -137,6 +162,81 @@ describe('ensure-chromium-ready.sh — the gate still reports', () => {
137162
});
138163
});
139164

165+
/**
166+
* ⭐ objectui#8404 — the bound survives a host with no GNU coreutils.
167+
*
168+
* The two cases below are the two this file had that a stock macOS host reddens,
169+
* run under a PATH where `timeout` and `gtimeout` are genuinely absent. They are
170+
* not a re-run of the cases above with a decoration: on `origin/main`'s script,
171+
* under this same PATH, the recovery case exits 1 with the dependency install
172+
* never executed, and the deadline case never prints the #5304 signature.
173+
*
174+
* ⛔ Nothing here is skipped, and nothing above is weakened — the GNU path is
175+
* still measured by the cases above, on the same run.
176+
*/
177+
describe('ensure-chromium-ready.sh — the bound holds where GNU `timeout` is absent (objectui#8404)', () => {
178+
it('the restricted PATH really hides both spellings — the control for the two cases below', () => {
179+
// Without this, both cases below could be measuring the GNU path again and
180+
// would pass for a reason that has nothing to do with what they assert.
181+
const { dir, env } = pathWithoutTimeout();
182+
try {
183+
const found = spawnSync('bash', ['-c', 'command -v timeout || command -v gtimeout'], {
184+
env,
185+
encoding: 'utf8',
186+
});
187+
expect(found.status, `PATH=${dir} still resolves a timeout: ${found.stdout}`).not.toBe(0);
188+
// And the positive half of the same control: the PATH is not simply empty.
189+
expect(
190+
spawnSync('bash', ['-c', 'command -v sleep'], { env, encoding: 'utf8' }).status,
191+
'the restricted PATH resolves nothing at all, so the two cases below would fail for that reason',
192+
).toBe(0);
193+
} finally {
194+
fs.rmSync(dir, { recursive: true, force: true });
195+
}
196+
});
197+
198+
it('installs the system libraries and succeeds once Chromium launches', () => {
199+
const ran = marker('recover-no-timeout');
200+
const { dir, env } = pathWithoutTimeout();
201+
try {
202+
const result = run({ ...env, OS_CHROMIUM_PROBE_CMD: `test -f ${ran}`, OS_CHROMIUM_DEPS_CMD: `touch ${ran}` });
203+
expect(result.status, result.stderr).toBe(0);
204+
expect(
205+
fs.existsSync(ran),
206+
'the dependency install never ran. That is the objectui#8404 signature: the bound was ' +
207+
'spelled as a bare `timeout`, so on a host without it the call failed at 127 before ' +
208+
'install-deps was reached, and the recovery path could not recover.',
209+
).toBe(true);
210+
expect(result.stdout).toMatch(/Chromium launches after installing its system libraries/);
211+
} finally {
212+
fs.rmSync(dir, { recursive: true, force: true });
213+
}
214+
});
215+
216+
it('terminates well inside the job ceiling when the dependency install never returns', () => {
217+
const { dir, env } = pathWithoutTimeout();
218+
try {
219+
const result = run({
220+
...env,
221+
OS_CHROMIUM_PROBE_CMD: 'false',
222+
OS_CHROMIUM_DEPS_CMD: 'sleep 600',
223+
OS_CHROMIUM_DEPS_TIMEOUT: '2',
224+
});
225+
226+
expect(
227+
result.elapsedMs,
228+
`The script ran for ${result.elapsedMs}ms with no GNU timeout on PATH. An unbounded ` +
229+
'dependency install is objectui#5304, and a host without coreutils must not be the ' +
230+
'way back to it.',
231+
).toBeLessThan(60_000);
232+
expect(result.status, 'a browser that never became usable must still fail the job').not.toBe(0);
233+
expect(result.stderr).toMatch(/objectui#5304 signature/);
234+
} finally {
235+
fs.rmSync(dir, { recursive: true, force: true });
236+
}
237+
}, 120_000);
238+
});
239+
140240
describe('the workflows actually use it', () => {
141241
const workflows = ['.github/workflows/ci.yml', '.github/workflows/live-e2e.yml'];
142242

0 commit comments

Comments
 (0)