Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions scripts/__tests__/check-control-bytes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,13 @@ describe('repo state — the gate is green on this tree', () => {
* GNU grep prefixes `grep: <file>: `, older builds print `Binary file <file>
* matches` on stdout. Reading BOTH streams means this does not depend on which.
*/
function contentSearch(needle: string, file: string, cwd: string = repoRoot) {
const run = spawnSync('grep', ['-n', needle, file], { cwd, encoding: 'utf8' });
function contentSearch(
needle: string,
file: string,
cwd: string = repoRoot,
env: NodeJS.ProcessEnv = process.env,
) {
const run = spawnSync('grep', ['-n', needle, file], { cwd, encoding: 'utf8', env });
const both = `${run.stdout ?? ''}${run.stderr ?? ''}`;
return {
status: run.status,
Expand Down Expand Up @@ -356,7 +361,15 @@ describe('objectstack#5425 — the file that started this is readable again', ()
fs.writeFileSync(probe, `const includeKey = 1;${String.fromCharCode(0)}\n`);
const declined = contentSearch('includeKey', probe, dir);
expect(declined.refusedAsBinary, 'grep must decline a NUL-bearing file').toBe(true);
expect(declined.stdout, 'and print no line at all — that is the search outage').toBe('');
expect(
declined.stdout,
'and print no MATCHING LINE — that is the search outage. ⚠️ objectui#8404: this read ' +
"`toBe('')` until a stock macOS host reddened it on bytes CI called green. An empty " +
'stdout is not the outage, it is one userland\'s way of reporting it: GNU grep >= 3.5 ' +
'writes its refusal to stderr and leaves stdout empty, BSD grep writes ' +
'`Binary file <path> matches` to STDOUT. Both refuse, both print no line of the file, ' +
'and the refusal itself is already pinned by `refusedAsBinary` above.',
).not.toMatch(/^\d+:/m);
expect(declined.status, 'while exiting 0, which is what makes the outage silent').toBe(0);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
Expand All @@ -375,6 +388,58 @@ describe('objectstack#5425 — the file that started this is readable again', ()
* there would be a fabricated pin, so it is asserted only on the byte's absence,
* which is the harm it actually had: an unreviewable literal.
*/
/**
* ⭐ objectui#8404 — the two assertions above hold on EITHER grep userland.
*
* Established without a macOS host, because the discriminator is not the
* platform: it is which stream grep writes its refusal to. GNU grep 3.11 (this
* container, and what CI runs) writes `grep: <f>: binary file matches` to
* stderr and leaves stdout empty; BSD grep writes `Binary file <f> matches` to
* stdout. Both exit 0 and both print no line of the file. A shim first on PATH
* stands in for the second, so the host-independence is pinned here, on Linux,
* on every run — ⛔ not left as a claim nobody can re-measure.
*/
describe('objectui#8404 — the refusal is read the same on either grep userland', () => {
it('recognises the BSD spelling, which arrives on stdout', () => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'control-bytes-bsd-grep-'));
try {
const shim = path.join(dir, 'grep');
fs.writeFileSync(
shim,
[
'#!/bin/sh',
'# Stands in for BSD grep declining a binary file: the refusal on STDOUT,',
'# exit 0, and no line of the file. $3 is the path, after `-n <needle>`.',
'printf "Binary file %s matches\\n" "$3"',
'exit 0',
'',
].join('\n'),
);
fs.chmodSync(shim, 0o755);
fs.writeFileSync(path.join(dir, 'probe.ts'), 'const includeKey = 1;\n');

const bsd = contentSearch('includeKey', 'probe.ts', dir, {
...process.env,
PATH: `${dir}${path.delimiter}${process.env.PATH ?? ''}`,
});

// The control: the shim really is the grep that ran, or this measures GNU
// grep again and proves nothing about the other userland.
expect(bsd.stdout, 'the shim on PATH was not the grep that ran').toMatch(/^Binary file /m);
expect(bsd.refusedAsBinary, 'the BSD spelling must be read as the refusal it is').toBe(true);
expect(
bsd.stdout,
'and it is not a line of the file — which is why the search-outage assertion is written ' +
"against matching lines rather than against an empty stdout (the `toBe('')` spelling " +
'was false here, and only here, which is how objectui#8404 was found).',
).not.toMatch(/^\d+:/m);
expect(bsd.status, 'exit 0 either way — that is what makes the outage silent').toBe(0);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});
});

describe('objectstack#5450 — the four baselined files are clean', () => {
const cleaned = [
{ file: 'packages/core/src/evaluator/listConditional.ts', grepFor: 'warnedError' },
Expand Down
100 changes: 100 additions & 0 deletions scripts/__tests__/ensure-chromium-ready.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ function marker(name: string): string {
return path.join(fs.mkdtempSync(path.join(os.tmpdir(), `os-5304-${name}-`)), 'deps-ran');
}

/**
* A PATH carrying the externals this script needs and NOTHING else — in
* particular neither `timeout` nor `gtimeout`.
*
* objectui#8404. `timeout` is GNU coreutils and a stock macOS host has neither
* it nor Homebrew's `gtimeout`. Two of the cases in this file were red there on
* bytes CI called green, because the bare `timeout` call failed at 127 before
* the dependency install ever ran.
*
* ⚠️ The stand-in is a CAPABILITY, not a platform name: what makes those hosts
* different is the absent binary, so hiding the binary reproduces it exactly —
* on Linux, in this container, with no macOS anywhere. A
* `process.platform === 'darwin'` skip would have measured nothing and would
* red again on the next non-GNU host.
*/
function pathWithoutTimeout(): { dir: string; env: Record<string, string> } {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'os-8404-no-timeout-'));
for (const tool of ['bash', 'rm', 'sleep', 'touch']) {
const found = spawnSync('sh', ['-c', `command -v ${tool}`], { encoding: 'utf8' }).stdout.trim();
if (!found) throw new Error(`cannot build the restricted PATH: this host has no ${tool}`);
fs.symlinkSync(found, path.join(dir, tool));
}
return { dir, env: { PATH: dir } };
}

describe('ensure-chromium-ready.sh — apt is off the happy path', () => {
it('never invokes the dependency install when Chromium already launches', () => {
const ran = marker('happy');
Expand Down Expand Up @@ -137,6 +162,81 @@ describe('ensure-chromium-ready.sh — the gate still reports', () => {
});
});

/**
* ⭐ objectui#8404 — the bound survives a host with no GNU coreutils.
*
* The two cases below are the two this file had that a stock macOS host reddens,
* run under a PATH where `timeout` and `gtimeout` are genuinely absent. They are
* not a re-run of the cases above with a decoration: on `origin/main`'s script,
* under this same PATH, the recovery case exits 1 with the dependency install
* never executed, and the deadline case never prints the #5304 signature.
*
* ⛔ Nothing here is skipped, and nothing above is weakened — the GNU path is
* still measured by the cases above, on the same run.
*/
describe('ensure-chromium-ready.sh — the bound holds where GNU `timeout` is absent (objectui#8404)', () => {
it('the restricted PATH really hides both spellings — the control for the two cases below', () => {
// Without this, both cases below could be measuring the GNU path again and
// would pass for a reason that has nothing to do with what they assert.
const { dir, env } = pathWithoutTimeout();
try {
const found = spawnSync('bash', ['-c', 'command -v timeout || command -v gtimeout'], {
env,
encoding: 'utf8',
});
expect(found.status, `PATH=${dir} still resolves a timeout: ${found.stdout}`).not.toBe(0);
// And the positive half of the same control: the PATH is not simply empty.
expect(
spawnSync('bash', ['-c', 'command -v sleep'], { env, encoding: 'utf8' }).status,
'the restricted PATH resolves nothing at all, so the two cases below would fail for that reason',
).toBe(0);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});

it('installs the system libraries and succeeds once Chromium launches', () => {
const ran = marker('recover-no-timeout');
const { dir, env } = pathWithoutTimeout();
try {
const result = run({ ...env, OS_CHROMIUM_PROBE_CMD: `test -f ${ran}`, OS_CHROMIUM_DEPS_CMD: `touch ${ran}` });
expect(result.status, result.stderr).toBe(0);
expect(
fs.existsSync(ran),
'the dependency install never ran. That is the objectui#8404 signature: the bound was ' +
'spelled as a bare `timeout`, so on a host without it the call failed at 127 before ' +
'install-deps was reached, and the recovery path could not recover.',
).toBe(true);
expect(result.stdout).toMatch(/Chromium launches after installing its system libraries/);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
});

it('terminates well inside the job ceiling when the dependency install never returns', () => {
const { dir, env } = pathWithoutTimeout();
try {
const result = run({
...env,
OS_CHROMIUM_PROBE_CMD: 'false',
OS_CHROMIUM_DEPS_CMD: 'sleep 600',
OS_CHROMIUM_DEPS_TIMEOUT: '2',
});

expect(
result.elapsedMs,
`The script ran for ${result.elapsedMs}ms with no GNU timeout on PATH. An unbounded ` +
'dependency install is objectui#5304, and a host without coreutils must not be the ' +
'way back to it.',
).toBeLessThan(60_000);
expect(result.status, 'a browser that never became usable must still fail the job').not.toBe(0);
expect(result.stderr).toMatch(/objectui#5304 signature/);
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
}, 120_000);
});

describe('the workflows actually use it', () => {
const workflows = ['.github/workflows/ci.yml', '.github/workflows/live-e2e.yml'];

Expand Down
Loading
Loading