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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(gate): conservatively place unreadable test options [C7]
Corey Olson67ae129a3795
diff --git a/docs/api.md b/docs/api.mdindex c3ef8bb8..0f624274 100644--- a/docs/api.md+++ b/docs/api.md@@ -674,4 +674,4 @@ A board-recorded item merge covers its introduced commits only when its exact suThe JSON result includes `verification` entries with PR number, exact head, state, assurance, receipt identities, and any unverified commit IDs. GitHub statuses are shared by PRs with the same head: if an outside or unproven PR shares a commit with a proven proposal, the shared status stays red rather than lending the proposal's green status to it. Publishing observes and posts statuses; it never merges a PR or requires outside authors to use Pullboard.-A Node test that intentionally generates CPU load declares `{ cpuLoad: true }` in its test options. `bin/run-tests.js` discovers declarations without running the module and places the selected files on a registered runner, even with local-first admission or an inherited coordinator lease. While runners are registered it waits for a compatible runner instead of using local or short capacity; browser and GUI requirements still apply. A runner failure never permits this load to fall back locally. With no runners registered it uses the ordinary local admission and prints the reason. Source must be clean and committed for remote execution. Discovery conservatively places the whole selected file, including when a name filter selects only some cases; comments and string examples do not declare load.+A Node test that intentionally generates CPU load declares `{ cpuLoad: true }` in its test options. `bin/run-tests.js` discovers declarations without running the module and places the selected files on a registered runner, even with local-first admission or an inherited coordinator lease. While runners are registered it waits for a compatible runner instead of using local or short capacity; browser and GUI requirements still apply. A runner failure never permits this load to fall back locally. With no runners registered it uses the ordinary local admission and prints the reason. Source must be clean and committed for remote execution. Discovery conservatively places the whole selected file, including when a name filter selects only some cases; comments and string/template examples do not declare load. Options that cannot be read statically count as declared load: computed property names, object spreads, opaque option expressions and unresolved test-function uses require runner placement. Discovery never evaluates those expressions. A directly readable literal `cpuLoad: false` remains ordinary work.diff --git a/src/module-imports.js b/src/module-imports.jsindex f5c7ce82..b0088495 100644--- a/src/module-imports.js+++ b/src/module-imports.js@@ -7,6 +7,7 @@ import {} from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';+import { lex } from './js-lex.js';/*** A child Node that compiles each source in its private input file as an ES module and reports, for each, whether@@ -179,6 +180,91 @@ function quotedCpuOptions(source) {return points;}+/** Split an executable argument/property list using balanced delimiters, never executing expressions. */+function sourceParts(code, start, closing) {+ const parts = [];+ let begin = start;+ const stack = [];+ for (let at = start; at < code.length; at++) {+ const char = code[at];+ if (!stack.length && char === closing) { parts.push([begin, at]); return { parts, end: at }; }+ if (!stack.length && char === ',') { parts.push([begin, at]); begin = at + 1; }+ else if ('([{'.includes(char)) stack.push({ '(': ')', '[': ']', '{': '}' }[char]);+ else if (')]}'.includes(char)) {+ if (stack.pop() !== char) return null;+ }+ }+ return null;+}++/** Only a directly written object with readable property names proves that no opaque option hides load. */+function opaqueOptions(source, code, from, to) {+ while (/\s/u.test(code[from] ?? '') && from < to) from++;+ while (/\s/u.test(code[to - 1] ?? '') && to > from) to--;+ if (code[from] !== '{') return true;+ const object = sourceParts(code, from + 1, '}');+ if (!object || object.end !== to - 1) return true;+ for (const [start, end] of object.parts) {+ const property = pastGap(source.slice(start, end), 0);+ if (!property) continue;+ // Computed keys, spreads and prototype inputs cannot be resolved without running code.+ if (property.startsWith('[') || property.startsWith('...') || /^(?:__proto__\b|"__proto__"|'__proto__')/u.test(property)) return true;+ if (!/^(?:[A-Za-z_$][\w$]*|"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*')/u.test(property)) return true;+ }+ return false;+}++/** Recognize callback syntax only; an opaque function-producing expression can instead be options. */+function callbackSource(source) {+ const value = pastGap(source, 0);+ return /^(?:async\s+)?function\b/u.test(value)+ || /^(?:async\s+)?(?:[A-Za-z_$][\w$]*|\([^]*?\))\s*=>/u.test(value);+}++/** Unknown test option expressions are declarations under the conservative placement contract. */+function unreadableTestOptions(source) {+ const code = lex(source).code;+ const names = new Set(['test', 'it', 'describe']);+ for (const match of source.matchAll(/\bimport\s+([^;'"]+?)\s+from\s*(['"])node:test\2/gu)) {+ const bindings = match[1].replace(/[{}*]/gu, ' ').split(',');+ for (const binding of bindings) {+ const name = binding.trim().split(/\s+as\s+/u).at(-1)?.trim();+ if (/^[A-Za-z_$][\w$]*$/u.test(name ?? '')) names.add(name);+ }+ }+ // A direct alias retains the same conservative rule, including renamed imported test functions.+ let changed = true;+ while (changed) {+ changed = false;+ for (const match of code.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*([A-Za-z_$][\w$]*)\b/gu)) {+ if (names.has(match[2]) && !names.has(match[1])) { names.add(match[1]); changed = true; }+ }+ }+ const imports = [...source.matchAll(/\bimport\s+(?:[A-Za-z_$][\w$]*\s*,?\s*)?(?:\{[^}]*\}|\*\s+as\s+[A-Za-z_$][\w$]*)?\s*from\s*(['"])[^'"]+\1/gu)]+ .map(match => [match.index, match.index + match[0].length]);+ for (const word of code.matchAll(/\b[A-Za-z_$][\w$]*\b/gu)) {+ if (!names.has(word[0]) || imports.some(([from, to]) => word.index >= from && word.index < to)) continue;+ const tail = pastGap(source, word.index + word[0].length);+ if (!/^(?:\(|\.\s*(?:only|skip|todo)\s*\()/u.test(tail)) return true;+ }+ for (const match of code.matchAll(/\b([A-Za-z_$][\w$]*)\s*(?:\.\s*(?:only|skip|todo)\s*)?\(/gu)) {+ if (!names.has(match[1])) continue;+ const open = match.index + match[0].lastIndexOf('(');+ const call = sourceParts(code, open + 1, ')');+ if (!call) return true;+ const args = call.parts.filter(([from, to]) => code.slice(from, to).trim());+ if (!args.length) continue;+ const [first, second] = args;+ const firstText = source.slice(...first).trim();+ const named = /^(?:['"`])/u.test(firstText);+ 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;+ if (!options || opaqueOptions(source, code, ...options)) return true;+ }+ return false;+}+/** Find CPU-load options without evaluating a test module; unknown identifier values require runner admission. */export function cpuLoadOptionsIn(sources) {const occurrences = sources.map(source => [@@ -200,7 +286,7 @@ export function cpuLoadOptionsIn(sources) {const parsed = look([...sources, ...variants]);let next = sources.length;return sources.map((source, index) => {- let found = !parsed[index].compiles;+ let found = !parsed[index].compiles || unreadableTestOptions(source);for (const { disabled } of occurrences[index]) {if (!parsed[next].compiles && !disabled) found = true;next += 1;diff --git a/test/cpu-load-test-fixture.js b/test/cpu-load-test-fixture.jsindex de156ca3..1e3b7738 100644--- a/test/cpu-load-test-fixture.js+++ b/test/cpu-load-test-fixture.js@@ -9,7 +9,7 @@ import { HOST, installSshStandIn } from './runner-ssh-fixture.js';const SOURCE = resolve(import.meta.dirname, '..');/** Build an ordinary CLI fixture whose declared test reports its actual checkout and live holder. */-export function cpuLoadFixture(e2e, { declaration = '{ cpuLoad: true }' } = {}) {+export function cpuLoadFixture(e2e, { declaration = '{ cpuLoad: true }', binding = 'test' } = {}) {const box = e2e.project('node bin/run-tests.js test/cpu-probe.test.js');const bin = join(box.dir, 'ssh-bin');const remoteHome = join(box.dir, 'runner-home');@@ -19,11 +19,11 @@ export function cpuLoadFixture(e2e, { declaration = '{ cpuLoad: true }' } = {})cpSync(join(SOURCE, 'src'), join(box.repo, 'src'), { recursive: true });cpSync(join(SOURCE, 'bin'), join(box.repo, 'bin'), { recursive: true });writeFileSync(join(box.repo, 'package.json'), JSON.stringify({ name: 'pullboard', version: '1.0.0', type: 'module' }) + '\n');- writeFileSync(join(box.repo, 'test', 'cpu-probe.test.js'), `import { test } from 'node:test';+ writeFileSync(join(box.repo, 'test', 'cpu-probe.test.js'), `import { test${binding === 'test' ? '' : ` as ${binding}`} } from 'node:test';import { DatabaseSync } from 'node:sqlite';// Example text is not a declaration: { cpuLoad: true }const example = '{ cpuLoad: true }';-test('declared load stand-in', ${declaration}, () => {+${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.jsindex 5bde3678..c9ce2911 100644--- a/test/cpu-load-tests.test.js+++ b/test/cpu-load-tests.test.js@@ -106,3 +106,18 @@ test('CPU-load syntax inside literal template text stays ordinary local-first woassert.equal(local.executor?.liveLease, true);assert.equal(local.executor?.runnerExecution, false);});+++// These conservative-placement controls were added after the coordinator sharpened the contract.+for (const [kind, declaration, binding] of [+ ['computed property', '{ [["cpu", "Load"].join("")]: true }', 'test'],+ ['spread property', '{ ...Object.fromEntries([[ ["cpu", "Load"].join(""), true ]]) }', 'test'],+ ['opaque options and an imported alias', 'Object.fromEntries([[ ["cpu", "Load"].join(""), true ]])', 'register'],+]) test(`unreadable ${kind} options conservatively use a registered runner [C7]`, async () => {+ const box = cpuLoadFixture(e2e, { declaration, binding });+ const remote = await box.runGate();+ assert.equal(remote.result.status, 0, remote.result.context);+ assert.equal(box.requestsMade().length, 1, 'unresolved executable options cannot start on the coordinator');+ assert.equal(remote.executor?.runnerExecution, true);+ assert.notEqual(remote.executor?.cwd, box.repo);+});