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): fail closed on unreadable test-context member use [C7]

Corey Olson872465d5a508
diff --git a/src/module-imports.js b/src/module-imports.js
index 19725fda..189a2ada 100644
--- a/src/module-imports.js
+++ b/src/module-imports.js
@@ -228,6 +228,43 @@ function callbackSource(source) {
return Boolean(parameters && code.slice(parameters.end + 1).trimStart().startsWith('=>'));
}
+/** A callback's context can register subtests; unreadable member use or aliasing must fail closed. */
+function opaqueTestContext(source) {
+ let code = lex(source).code.trim().replace(/^async\s+/u, '');
+ let parameters, body;
+ if (/^function\b/u.test(code)) {
+ const prefix = /^function(?:\s+[A-Za-z_$][\w$]*)?\s*\(/u.exec(code);
+ if (!prefix) return true;
+ const args = sourceParts(code, prefix[0].length, ')');
+ if (!args) return true;
+ parameters = code.slice(prefix[0].length, args.end).trim();
+ body = code.slice(args.end + 1);
+ } else if (code.startsWith('(')) {
+ const args = sourceParts(code, 1, ')');
+ if (!args) return true;
+ parameters = code.slice(1, args.end).trim();
+ body = code.slice(args.end + 1).trimStart().slice(2);
+ } else {
+ const arrow = /^([A-Za-z_$][\w$]*)\s*=>/u.exec(code);
+ if (!arrow) return true;
+ parameters = arrow[1]; body = code.slice(arrow[0].length);
+ }
+ if (!parameters) return false;
+ if (!/^[A-Za-z_$][\w$]*$/u.test(parameters)) return true;
+ const readable = new Set(['test', 'after', 'before', 'afterEach', 'beforeEach', 'diagnostic',
+ 'assert', 'mock', 'plan', 'skip', 'todo', 'runOnly', 'name', 'fullName', 'signal', 'passed', 'error']);
+ for (const word of body.matchAll(/\b[A-Za-z_$][\w$]*\b/gu)) {
+ if (word[0] !== parameters) continue;
+ let tail = body.slice(word.index + word[0].length).trimStart();
+ if (tail.startsWith('?.')) tail = tail.slice(2);
+ else if (tail.startsWith('.')) tail = tail.slice(1);
+ else return true; // Computed access, passing the context away or aliasing it is unresolved.
+ const member = /^\s*([A-Za-z_$][\w$]*)/u.exec(tail)?.[1];
+ if (!readable.has(member)) return true;
+ }
+ return false;
+}
+
/** Unknown test option expressions are declarations under the conservative placement contract. */
function unreadableTestOptions(source, quoted) {
const code = lex(source).code;
@@ -270,6 +307,9 @@ function unreadableTestOptions(source, quoted) {
const [first, second] = args;
const firstText = source.slice(...first).trim();
const named = /^(?:['"`])/u.test(firstText);
+ const callback = source.slice(...args.at(-1));
+ if (callbackSource(callback) && opaqueTestContext(callback)) return true;
+ if (args.length >= 3 && !callbackSource(callback)) return true;
if (named && args.length === 1 || !named && args.length === 1 && callbackSource(firstText)) continue;
if (named && args.length === 2 && callbackSource(source.slice(...second))) continue;
const options = named ? second : first;
diff --git a/test/cpu-load-test-fixture.js b/test/cpu-load-test-fixture.js
index 0c1ba644..47c25e82 100644
--- a/test/cpu-load-test-fixture.js
+++ b/test/cpu-load-test-fixture.js
@@ -24,7 +24,7 @@ import { DatabaseSync } from 'node:sqlite';
// Example text is not a declaration: { cpuLoad: true }
const example = '{ cpuLoad: true }';
finish(() => {});
-${subtest ? `${binding}('parent', async t => { await ${subtest}` : binding}('declared load stand-in', ${declaration}, () => {
+${subtest ? `${binding}('parent', async t => { t.after(() => {}); await ${subtest}` : binding}('declared load stand-in', ${declaration}, () => {
const db = new DatabaseSync(process.env.PULLBOARD_GATE_SLOT_POOL, { readOnly: true });
const row = db.prepare('SELECT * FROM holder WHERE token=?').get(process.env.PULLBOARD_GATE_SLOT_TOKEN);
db.close();
diff --git a/test/cpu-load-tests.test.js b/test/cpu-load-tests.test.js
index 741f0e23..fdca9c6e 100644
--- a/test/cpu-load-tests.test.js
+++ b/test/cpu-load-tests.test.js
@@ -150,3 +150,15 @@ for (const [kind, subtest] of [
assert.equal(remote.executor?.runnerExecution, true);
assert.notEqual(remote.executor?.cwd, box.repo);
});
+
+
+// AFTER-only negative: a readable direct subtest and its ordinary lifecycle hook are not opaque load.
+test('a readable false direct subtest and context lifecycle hook stay local [C7]', async () => {
+ const box = cpuLoadFixture(e2e, { subtest: 't.test', declaration: '{ cpuLoad: false }' });
+ const local = await box.runGate();
+ assert.equal(local.result.status, 0, local.result.context);
+ assert.equal(box.requestsMade().length, 0);
+ assert.equal(local.executor?.cwd, box.repo);
+ assert.equal(local.executor?.liveLease, true);
+ assert.equal(local.executor?.runnerExecution, false);
+});