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(core): inspect bounded executable test import closures [C7]
Corey Olson497c9bd82bcf
diff --git a/docs/api.md b/docs/api.mdindex aa75747a..27c57444 100644--- a/docs/api.md+++ b/docs/api.md@@ -678,7 +678,7 @@ 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/template examples do not declare load. Options that cannot be read statically count as declared load: computed property names, object spreads, opaque option expressions, unresolved test-function uses and unreadable test-context member uses, unresolved CommonJS registration paths, dynamic imports, executable `eval`/`Function` references and `node:vm`/`node:module` imports require runner placement. Readable direct subtests and ordinary context lifecycle hooks retain their ordinary classification. V8 identifies imported modules without executing them; comments, quoted named imports and escaped module specifiers cannot hide registration aliases. A node:test binding that the bounded reader cannot understand is conservatively placed on runners. Discovery never evaluates those expressions. A directly readable literal `cpuLoad: false` remains ordinary work.+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, unresolved test-function uses and unreadable test-context member uses, unresolved CommonJS registration paths, dynamic imports, executable `eval`/`Function` references and `node:vm`/`node:module` imports require runner placement. Readable direct subtests and ordinary context lifecycle hooks retain their ordinary classification. V8 identifies imported modules without executing them; comments, quoted named imports and escaped module specifiers cannot hide registration aliases. A node:test binding that the bounded reader cannot understand is conservatively placed on runners. Discovery never evaluates those expressions. Discovery inspects the reachable local executable import/re-export closure, including wrappers and barrels. It follows at most 256 files, 4 MiB and 32 edges of depth, deduplicates cycles and resolves real paths inside the repository. Missing, escaping, unsupported, unreadable or unresolved executable closure nodes require conservative runner placement; no special parser or transport names are exempt. This is placement under uncertainty, not an inference that a file actually burns CPU. A directly readable literal `cpuLoad: false` remains ordinary work when its full inspected closure is also readable.`pullboard why <file>[:<line>] --json` uses the `why file` catalog shape; this names the file form, not a literal `file` argument. It traces commits on the repository's actual primary branch, then resolves their item trailers, served row IDs and answered decisions in one board query. The legacy `why <id>` shape is unchanged. Answered decisions carry their recorded origin, statement, rationale, decider and relayer; absent historical provenance remains `unknown`. Row and item origins are also `unknown` unless recorded, rather than inferred from a related decision. An agent may label a relayed or inherited answer but cannot use that label to mint a person-origin record. Unproven original decider identities remain unknown, with the answering relay seat recorded separately.diff --git a/src/cpu-load-admission.js b/src/cpu-load-admission.jsindex e542c0dd..e61bca7b 100644--- a/src/cpu-load-admission.js+++ b/src/cpu-load-admission.js@@ -1,12 +1,54 @@/** CPU-load declarations are source metadata; discovery never executes test code [C7]. */import { readFileSync } from 'node:fs';+import { realpathSync } from 'node:fs';+import { statSync } from 'node:fs';+import { isBuiltin } from 'node:module';+import { dirname } from 'node:path';+import { relative } from 'node:path';import { resolve } from 'node:path';+import { sep } from 'node:path';import { loadMachineSettings } from './settings.js';import { cpuLoadOptionsIn } from './module-imports.js';+import { importsIn } from './module-imports.js';-/** A selected file with a declared CPU-load option must be placed before any test body starts. */+const MAX_FILES = 256;+const MAX_BYTES = 4 * 1024 * 1024;+const MAX_DEPTH = 32;++/** Inspect a bounded executable module closure; uncertainty is conservative placement, never code evaluation. */export function testsNeedCpuRunner(root, files) {- return cpuLoadOptionsIn(files.map(file => readFileSync(resolve(root, file), 'utf8'))).some(Boolean);+ try {+ const boundary = realpathSync(root);+ const pending = files.map(file => ({ path: resolve(boundary, file), depth: 0 }));+ const seen = new Set();+ let bytes = 0;+ while (pending.length) {+ const { path, depth } = pending.pop();+ const actual = realpathSync(path);+ const within = relative(boundary, actual);+ if (within === '..' || within.startsWith(`..${sep}`) || resolve(boundary, within) !== actual) return true;+ if (seen.has(actual)) continue;+ if (depth > MAX_DEPTH) return true;+ seen.add(actual);+ const info = statSync(actual);+ bytes += info.size;+ if (!info.isFile() || seen.size > MAX_FILES || bytes > MAX_BYTES) return true;+ // JSON imports supply data without an executable registration body; still enforce closure containment.+ if (actual.endsWith('.json')) continue;+ if (!/\.(?:[cm]?js)$/u.test(actual)) return true;+ const source = readFileSync(actual, 'utf8');+ if (cpuLoadOptionsIn([source])[0]) return true;+ for (const name of importsIn([source])[0]) {+ if (isBuiltin(name)) continue;+ if (!name.startsWith('./') && !name.startsWith('../')) return true;+ pending.push({ path: resolve(dirname(actual), name), depth: depth + 1 });+ }+ }+ return false;+ } catch {+ // Missing, unreadable or unparseable closure metadata cannot prove ordinary local work.+ return true;+ }}/** Report the explicit no-runner fallback while keeping registered CPU work off the coordinator. */diff --git a/src/module-imports.js b/src/module-imports.jsindex 13627462..6dfddc8d 100644--- a/src/module-imports.js+++ b/src/module-imports.js@@ -90,7 +90,7 @@ function dynamicAt(source, at) {const after = pastGap(argument, literal[0].length)[0];if (after !== ')' && after !== ',') return COMPUTED;try {- return new Function(`return ${literal[0]};`)();+ return look([`import ${literal[0]};`])[0].imports[0] ?? COMPUTED;} catch {return COMPUTED;}diff --git a/test/cpu-load-test-fixture.js b/test/cpu-load-test-fixture.jsindex 2a0eb8c0..ad920865 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 }', binding = 'test', subtest = null, commonjs = false, dynamicImport = false, importBinding = null, moduleSpecifier = 'node:test', importedOptions = false, registrationHelper = false } = {}) {+export function cpuLoadFixture(e2e, { declaration = '{ cpuLoad: true }', binding = 'test', subtest = null, commonjs = false, dynamicImport = false, importBinding = null, moduleSpecifier = 'node:test', importedOptions = false, registrationHelper = false, lifecycleHelper = false } = {}) {const probeFile = `cpu-probe.test.${commonjs ? 'cjs' : 'js'}`;const box = e2e.project(`node bin/run-tests.js test/${probeFile}`);const bin = join(box.dir, 'ssh-bin');@@ -21,9 +21,12 @@ export function cpuLoadFixture(e2e, { declaration = '{ cpuLoad: true }', bindingcpSync(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');if (registrationHelper) {- writeFileSync(join(box.repo, 'test', 'registrations.js'), "export { test as launch, after } from 'node:test';\n");+ writeFileSync(join(box.repo, 'test', 'registrations.js'), registrationHelper === 'wrapper'+ ? "import { test, after } from 'node:test'; export { after }; export const launch = (...args) => test(...args);\n"+ : "export { test as launch, after } from 'node:test';\n");writeFileSync(join(box.repo, 'test', 'registration-barrel.js'), "export { launch, after } from './registrations.js';\n");}+ if (lifecycleHelper) writeFileSync(join(box.repo, 'test', 'lifecycle.js'), "import { after } from 'node:test'; after(() => {});\n// Text is not CPU load: { cpuLoad: true }\n");if (importedOptions) writeFileSync(join(box.repo, 'test', 'options.js'), 'export const options = { cpuLoad: true };\n');writeFileSync(join(box.repo, 'test', probeFile), `${commonjs? `const { test: ${binding}, after: finish } = require('node:test');\nconst { DatabaseSync } = require('node:sqlite');`@@ -31,6 +34,7 @@ export function cpuLoadFixture(e2e, { declaration = '{ cpuLoad: true }', binding? `const { default: ${binding}, after: finish } = await import('node:test');\nimport { DatabaseSync } from 'node:sqlite';`: `import { ${importBinding ?? `test${binding === 'test' ? '' : ` as ${binding}`}`}, after as finish } from '${moduleSpecifier}';\nimport { DatabaseSync } from 'node:sqlite';`}${importedOptions ? "import { options } from './options.js';" : ''}+${lifecycleHelper ? "import './lifecycle.js';" : ''}// Example text is not a declaration: { cpuLoad: true }const example = '{ cpuLoad: true }';finish(() => {});diff --git a/test/cpu-load-tests.test.js b/test/cpu-load-tests.test.jsindex 2b58a792..711e550d 100644--- a/test/cpu-load-tests.test.js+++ b/test/cpu-load-tests.test.js@@ -217,3 +217,27 @@ test('a registration re-export chain with imported opaque options uses its runneassert.equal(remote.executor?.runnerExecution, true);assert.notEqual(remote.executor?.cwd, box.repo);});+++// AFTER-only: wrapping a registration function does not make its executable provenance readable.+test('a local exported registration wrapper with opaque options uses its runner [C7]', async () => {+ const box = cpuLoadFixture(e2e, { registrationHelper: 'wrapper', importedOptions: true,+ binding: 'register', importBinding: 'launch as register', moduleSpecifier: './registration-barrel.js',+ declaration: 'options' });+ const remote = await box.runGate();+ assert.equal(remote.result.status, 0, remote.result.context);+ assert.equal(box.requestsMade().length, 1);+ assert.equal(remote.executor?.runnerExecution, true);+ assert.notEqual(remote.executor?.cwd, box.repo);+});++// AFTER-only: a fully readable lifecycle-only closure still proves ordinary work.+test('a readable false test with a local lifecycle helper stays local [C7]', async () => {+ const box = cpuLoadFixture(e2e, { lifecycleHelper: true, 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?.liveLease, true);+ assert.equal(local.executor?.runnerExecution, false);+ assert.equal(local.executor?.cwd, box.repo);+});