Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(gate): classify saved-status shell checks by their tests [C7,Q1,Q3]

Corey Olson5dd1d3203af6
diff --git a/src/browser-admission.js b/src/browser-admission.js
index 32e2c2e5..b278c392 100644
--- a/src/browser-admission.js
+++ b/src/browser-admission.js
@@ -106,8 +106,30 @@ export function resolveExecutable(command, pathValue = process.env.PATH) {
return null;
}
-/** Recognize the exact output-capture and grep shape used by frozen named-test checks. */
-function capturedRunner(command) {
+/** Recognize output-only status wrappers without treating arbitrary shell suffixes as classified work. */
+function statusCaptureSuffix(suffix, variable) {
+ if (variable === 'rc' || variable === 'bad') return false;
+ const quotes = ['"', "'"];
+ const prints = [1, 2].flatMap(slashes => quotes.map(quote => `printf ${quote}%s${'\\'.repeat(slashes)}n${quote} "$${variable}"`));
+ for (const print of prints) {
+ const saved = `; rc=$?; ${print}; `;
+ if (suffix === `${saved}[ "$rc" -eq 0 ]`) return true;
+ for (const badPrint of prints) for (const quote of quotes) {
+ const checked = `${saved}bad=$(${badPrint} | grep -E ${quote}^# (fail|skipped) [1-9]${quote}); [ "$rc" -eq 0 ] && [ -z "$bad" ]`;
+ if (suffix === checked) return true;
+ for (const finalPrint of prints) for (const namedQuote of quotes) {
+ const prefix = `${checked} && ${finalPrint} | grep -Eq ${namedQuote}`;
+ if (!suffix.startsWith(prefix) || !suffix.endsWith(namedQuote)) continue;
+ const pattern = suffix.slice(prefix.length, -1);
+ if (pattern.startsWith('^[[:space:]]*ok [0-9]+ - ') && !/["'$`\\]/u.test(pattern)) return true;
+ }
+ }
+ }
+ return false;
+}
+
+/** Recognize fixed frozen-check wrappers; new status wrappers do not widen short-slot eligibility. */
+function capturedRunner(command, { status = false } = {}) {
const opening = /^([A-Za-z_][A-Za-z0-9_]*)=\$\(/u.exec(command);
if (!opening) return null;
const variable = opening[1];
@@ -116,6 +138,7 @@ function capturedRunner(command) {
if (bodyEnd < 0) return null;
const inner = command.slice(opening[0].length, bodyEnd);
const suffix = command.slice(bodyEnd + ending.length);
+ if (status && statusCaptureSuffix(suffix, variable)) return inner;
const quotes = ['"', "'"];
// Only the literal one-backslash newline form is part of the frozen capture shape.
const prints = quotes.map(quote => `printf ${quote}%s\\n${quote} "$${variable}"`);
@@ -340,7 +363,7 @@ export async function checkNeedsBrowser(root, command, { commit, env = process.e
let words = literalShellWords(command);
if (words && await ownSourceCheck(root, words, { commit, env })) return false;
if (!words) {
- const inner = capturedRunner(command);
+ const inner = capturedRunner(command, { status: true });
if (!inner) return browserFallback(onFallback, '<frozen check>', 'shell syntax is outside the supported literal capture form');
const grep = resolveExecutable('grep', env.PATH);
if (!grep || !['/usr/bin/grep', '/bin/grep'].includes(await realpath(grep).catch(() => ''))) return browserFallback(onFallback, '<frozen check>', 'capture wrapper does not resolve the system grep');
diff --git a/test/gate-admission.test.js b/test/gate-admission.test.js
index 8c08a18b..42b7d698 100644
--- a/test/gate-admission.test.js
+++ b/test/gate-admission.test.js
@@ -50,6 +50,41 @@ process.stdout.write(JSON.stringify(decisions));`;
assert.deepEqual(decisions[2].fallbacks, [], 'understood core selection needs no browser fallback');
});
+test('shell admission preserves opaque suffixes and the existing short-slot boundary [C7,Q1,Q3]', async (t) => {
+ const { root, env } = fixture(t, 2);
+ mkdirSync(join(root, 'bin'));
+ mkdirSync(join(root, 'test'));
+ writeFileSync(join(root, 'bin/run-tests.js'), "throw new Error('classification must not execute the runner');\n");
+ writeFileSync(join(root, 'test/core.test.js'), "import { test } from 'node:test';\n");
+ writeFileSync(join(root, 'test/browser.test.js'), "import { spawn } from 'node:child_process';\nspawn('Google Chrome');\n");
+ /** Build the coordinator's literal saved-exit and fail/skip wrapper without executing it. */
+ const capture = (file, quote = "'", slashes = 1) => {
+ const print = `printf ${quote}%s${'\\'.repeat(slashes)}n${quote} "$out"`;
+ return `out=$(node bin/run-tests.js ${file} 2>&1); rc=$?; ${print}; bad=$(${print} | grep -E '^# (fail|skipped) [1-9]'); [ "$rc" -eq 0 ] && [ -z "$bad" ] && ${print} | grep -Eq '^[[:space:]]*ok [0-9]+ - .*fixture'`;
+ };
+ const core = capture('test/core.test.js');
+ const commands = [
+ [core, false], [capture('test/core.test.js', '"', 2), false], [capture('test/browser.test.js'), true],
+ [`${core}; node launch-browser.js`, true], [`${core} || true`, true], [`${core} > /dev/null`, true],
+ [core.replace('rc=$?;', 'rc=0;'), true], [core.replace('"$rc" -eq', '"$status" -eq'), true],
+ [core.replace('[ -z "$bad" ]', '[ -n "$bad" ]'), true],
+ [core.replace('.*fixture', '$(node launch-browser.js)'), true],
+ [capture('$FILES'), true], [capture('test/core.test.js --unknown'), true],
+ [capture('test/core.test.js; node launch-browser.js'), true],
+ ];
+ const admission = new URL('../src/browser-admission.js', import.meta.url).href;
+ const source = `import { checkNeedsBrowser, explicitCheckFiles } from ${JSON.stringify(admission)};
+const decisions = [];
+for (const [command] of ${JSON.stringify(commands)}) decisions.push(await checkNeedsBrowser(process.cwd(), command));
+const short = await explicitCheckFiles(process.cwd(), ${JSON.stringify(core)});
+process.stdout.write(JSON.stringify({ decisions, short }));`;
+ const result = await runFixtureChildAsync(process.execPath, ['--input-type=module', '-e', source], { cwd: root, env });
+ assert.equal(result.status, 0, result.failure ?? result.stderr);
+ const actual = JSON.parse(result.stdout);
+ assert.deepEqual(actual.decisions, commands.map(([, browser]) => browser));
+ assert.equal(actual.short, null, 'new browser classification does not grant a short slot');
+});
+
/** A fixture test file that logs when its body starts and ends, holding its token for `ms`. */
function timedFile(name, ms, body = '') {
return `import { appendFileSync } from 'node:fs';