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(tests): resolve declared runner imports [C7,V4]

Corey Olsonae01a6adc16d
diff --git a/bin/run-tests.js b/bin/run-tests.js
index b87c82a3..f1d8c2ad 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -1,4 +1,6 @@
#!/usr/bin/env node
+/** @pullboard-module-loads ** */
+// Custom reporters are user-selected: ** covers every committed module, not a finite reporter list.
/**
* Run the test suite with a private home, no inherited Git identity or config, and a refusing CLI shim.
*/
@@ -12,7 +14,6 @@ import { Worker } from 'node:worker_threads';
import { randomUUID } from 'node:crypto';
import { channel } from 'node:diagnostics_channel';
import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
-
const runner = fileURLToPath(import.meta.url);
const LANDING_RUN_ENV = 'PULLBOARD_LANDING_RUN';
const LANDING_WORKER_STARTS_ENV = 'PULLBOARD_LANDING_WORKER_STARTS';
@@ -26,7 +27,6 @@ export const DEFAULT_TEST_FILE_TIMEOUT_MS = 30_000;
// Worker identity startup retries stay below the ordinary per-file ceiling even if ps is unavailable.
const LANDING_WORKER_IDENTITY_TIMEOUT_MS = 12_000;
const LANDING_CHILD_CUSTODY_TIMEOUT_MS = 12_000;
-
const watchdogSource = `
const { parentPort } = require('node:worker_threads');
const { writeSync } = require('node:fs');
@@ -1588,7 +1588,7 @@ if (process.argv[1] && resolve(process.argv[1]) === runner) {
// Any browser spawn from this file or a Node child it starts is refused by name (BROWSER_SLOT_REQUIRED).
process.env.PULLBOARD_TEST_BROWSER_SLOT = 'none';
const guard = new URL('../src/browser-slot-guard.js', import.meta.url);
- await import(guard.href);
+ await import('../src/browser-slot-guard.js');
process.env.NODE_OPTIONS = [process.env.NODE_OPTIONS, `--import=${guard.href}`].filter(Boolean).join(' ');
}
}
diff --git a/src/affected-tests.js b/src/affected-tests.js
index 4bd9c380..ab2e84f7 100644
--- a/src/affected-tests.js
+++ b/src/affected-tests.js
@@ -22,6 +22,7 @@ const SOURCE_TREE_INPUT = '/** @pullboard-test-input source-tree */';
const DOCS_TREE_INPUT = '/** @pullboard-test-input docs-tree */';
// A computed-import test may declare the repository modules it can load, in its leading comment header only.
const LOADS = /^\/\*\* @pullboard-test-loads (.+?) \*\/$/u;
+const SOURCE_LOADS = /^\/\*\* @pullboard-module-loads (.+?) \*\/$/u;
const COMMAND_REGISTRY = 'src/commands/index.js';
const GLOBAL = new Set(['bin/run-tests.js', 'package.json', 'package-lock.json', 'npm-shrinkwrap.json', 'yarn.lock', 'pnpm-lock.yaml', 'src/gate.js', 'src/cli.js', 'src/hooks.js', 'src/trusted-policy.js', 'src/affected-tests.js', 'src/module-imports.js']);
@@ -52,22 +53,31 @@ function globPattern(glob) {
}
/**
- * The repository modules a computed-import test declares in its header that it can load, normalized, with globs
- * expanded over the committed modules; anything outside the repository is ignored. A glob form this cannot expand
- * makes the whole declaration unusable (null), so the caller falls back to the whole suite (#803).
+ * The repository modules a computed loader declares in its leading header, with globs expanded over committed
+ * modules. Tests retain legacy outside-path filtering; strict source declarations require every target to exist
+ * and every glob to match. Invalid declarations return null so unknown imports still require the full suite.
*
* @returns {string[] | null}
*/
-function declaredLoads(source, modulePaths) {
- const declared = headerLines(source).map(line => LOADS.exec(line)).filter(Boolean)
- .flatMap(match => match[1].trim().split(/\s+/u)).map(path => posix.normalize(path))
- .filter(path => !path.startsWith('../') && !path.startsWith('/'));
+function declaredLoads(source, modulePaths, declaration = LOADS, strict = false) {
+ const header = headerLines(source);
+ if (strict && header.some(line => line.includes('@pullboard-module-loads') && !declaration.test(line))) return null;
+ const declared = header.map(line => declaration.exec(line)).filter(Boolean)
+ .flatMap(match => match[1].trim().split(/\s+/u)).map(path => posix.normalize(path));
+ if (strict && declared.some(path => path.startsWith('../') || path.startsWith('/'))) return null;
+ const inRepo = declared.filter(path => !path.startsWith('../') && !path.startsWith('/'));
const loads = [];
- for (const path of declared) {
- if (!/[*?[\]{}]/u.test(path)) { if (MODULE.test(path)) loads.push(path); continue; }
+ for (const path of inRepo) {
+ if (!/[*?[\]{}]/u.test(path)) {
+ if (strict && (!MODULE.test(path) || !modulePaths.includes(path))) return null;
+ if (MODULE.test(path)) loads.push(path);
+ continue;
+ }
const pattern = globPattern(path);
if (!pattern) return null;
- loads.push(...modulePaths.filter(module => pattern.test(module)));
+ const matches = modulePaths.filter(module => pattern.test(module));
+ if (strict && !matches.length) return null;
+ loads.push(...matches);
}
return loads;
}
@@ -286,6 +296,17 @@ function graphAt(root, commit, changedDocs = []) {
}
continue;
}
+ // Source loaders explicitly declare their committed module universe; unknown loaders still fail closed.
+ if (target === '(computed)' && !TEST.test(path)) {
+ const loads = declaredLoads(modules.get(path), paths, SOURCE_LOADS, true);
+ if (loads?.length) {
+ for (const load of loads) {
+ if (!reverse.has(load)) reverse.set(load, new Set());
+ reverse.get(load).add(path);
+ }
+ continue;
+ }
+ }
// The command registry loads its sibling modules by discovery; synthetic edges below stand for those imports (#804).
if (target === '(computed)' && path === COMMAND_REGISTRY) continue;
if (!target.startsWith('.')) {
diff --git a/test/affected-source-loads.test.js b/test/affected-source-loads.test.js
new file mode 100644
index 00000000..478754b4
--- /dev/null
+++ b/test/affected-source-loads.test.js
@@ -0,0 +1,66 @@
+/** Explicit source-loader declarations preserve conservative committed selection [V4,C7]. */
+import assert from 'node:assert/strict';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import { runFixtureChild, runFixtureGit } from './fixture-child.js';
+import { selectAffectedTests } from '../src/affected-tests.js';
+
+/** Make a real committed ES-module graph without executing any candidate source. */
+function graph(t) {
+ const root = mkdtempSync(join(tmpdir(), 'pullboard-doc-selection-'));
+ t.after(() => rmSync(root, { recursive:true, force:true }));
+ const env = { ...process.env, GIT_CONFIG_GLOBAL:'/dev/null', GIT_CONFIG_NOSYSTEM:'1',
+ GIT_AUTHOR_NAME:'Test Agent', GIT_AUTHOR_EMAIL:'[email protected]',
+ GIT_COMMITTER_NAME:'Test Agent', GIT_COMMITTER_EMAIL:'[email protected]' };
+ /** Run Git with the fixture's own identity and configuration. */
+ const git = (...args) => runFixtureGit(args, { cwd:root, env });
+ /** Write a fixture module or document, creating its parent directories. */
+ const put = (path, body) => { mkdirSync(dirname(join(root,path)), { recursive:true }); writeFileSync(join(root,path),body); };
+ /** Snapshot real Git objects so selection cannot read uncommitted working-tree bytes. */
+ const commit = () => { git('add','-A'); git('commit','-qm','chore: selection fixture'); return git('rev-parse','HEAD').trim(); };
+ git('init','-q','-b','main');
+ put('package.json','{"type":"module"}\n');
+ put('src/api.js','export const version = 1;\n');
+ put('test/api.test.js',"import '../src/api.js';\n");
+ put('src/labels.js',"import {readFileSync} from 'node:fs'; export const types=['feat','fix','docs','test']; export const config=()=>readFileSync('config.json'); export const isDoc=path=>path.startsWith('docs/');\n");
+ put('test/unrelated.test.js',"import '../src/labels.js'; import assert from 'node:assert/strict'; assert.ok(true);\n");
+ put('docs/api.md','# API\n');
+ put('docs/other.md','# Other\n');
+ put('docs/api.test.js',"import {readFileSync} from 'node:fs'; readFileSync(new URL('./api.md',import.meta.url),'utf8');\n");
+ return { root,git,put,commit };
+}
+
+test('source loader declarations resolve committed targets and reject unknown boundaries [V4,C7]', (t) => {
+ const headers = [
+ '/** @pullboard-module-loads src/api.js */',
+ '/** @pullboard-module-loads src/missing.js */',
+ '/** @pullboard-module-loads missing/*.js */',
+ '/** @pullboard-module-loads src/{api,labels}.js */',
+ '/** @pullboard-module-loads */',
+ '/** @pullboard-module-loads ../outside.js */',
+ "const fake = '/** @pullboard-module-loads src/api.js */';",
+ ];
+ for (const [index, header] of headers.entries()) {
+ const box = graph(t);
+ box.put('src/loader.js', header + "\nimport './api.js'; export const load = () => import(process.env.TARGET);\n");
+ box.put('test/loader.test.js', "import '../src/loader.js';\n");
+ const base = box.commit();
+ box.put('src/api.js', 'export const version = 2;\n');
+ const commit = box.commit();
+ const selection = selectAffectedTests(box.root, { base, commit });
+ if (index === 0) {
+ assert.equal(selection.full, false, selection.reason);
+ assert.deepEqual(selection.files, ['test/api.test.js', 'test/loader.test.js']);
+ } else {
+ assert.equal(selection.full, true, header);
+ assert.match(selection.reason, /non-literal dynamic import in reached file src\/loader\.js/u);
+ }
+ box.put('bin/run-tests.js', 'export const runner = true;\n');
+ const runnerChange = box.commit();
+ const global = selectAffectedTests(box.root, { base: commit, commit: runnerChange });
+ assert.equal(global.full, true);
+ assert.match(global.reason, /bin\/run-tests\.js controls the gate or dependency selection/u);
+ }
+});
diff --git a/test/affected-tests.test.js b/test/affected-tests.test.js
index f65512a4..b94568d8 100644
--- a/test/affected-tests.test.js
+++ b/test/affected-tests.test.js
@@ -1,9 +1,11 @@
+/** @pullboard-test-input source-tree */
/** Documentation input selection remains conservative across committed trees [V4,C7]. */
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { test } from 'node:test';
+import { fileURLToPath } from 'node:url';
import { runFixtureChild, runFixtureGit } from './fixture-child.js';
import { selectAffectedTests } from '../src/affected-tests.js';
@@ -358,3 +360,28 @@ test('runtime discovery and the selector agree on which files are engines and co
base = commit;
}
});
+
+
+test('a src change selects only its importers despite run-tests.js [V4,C7]', (t) => {
+ const box = graph(t);
+ const sourceRoot = fileURLToPath(new URL('../', import.meta.url));
+ const modules = runFixtureGit(['ls-files', '-z', '--', 'src', 'bin'], { cwd: sourceRoot })
+ .split('\0').filter(path => /\.[cm]?js$/u.test(path));
+ for (const path of modules) box.put(path, readFileSync(new URL('../' + path, import.meta.url), 'utf8'));
+ box.put('test/api.test.js', "import assert from 'node:assert/strict'; assert.ok(true);\n");
+ box.put('test/person.test.js', "import '../src/person.js';\n");
+ box.put('test/runner-reader.test.js', "import '../bin/run-tests.js';\n");
+ box.put('test/unrelated.test.js', "import assert from 'node:assert/strict'; assert.ok(true);\n");
+ const base = box.commit();
+ box.put('src/person.js', readFileSync(new URL('../src/person.js', import.meta.url), 'utf8') + '\n// ordinary source change\n');
+ const commit = box.commit();
+ const selected = selectAffectedTests(box.root, { base, commit, changed: ['src/person.js'] });
+ assert.equal(selected.full, false, selected.reason);
+ assert.deepEqual(selected.files, ['test/person.test.js', 'test/runner-reader.test.js']);
+ box.put('src/unresolved-reader.js', "import './person.js'; export const load = () => import(process.env.UNKNOWN_MODULE);\n");
+ box.put('test/unresolved-reader.test.js', "import '../src/unresolved-reader.js';\n");
+ const unresolved = box.commit();
+ const fallback = selectAffectedTests(box.root, { base: unresolved, commit: unresolved, changed: ['src/person.js'] });
+ assert.equal(fallback.full, true, 'a genuinely unresolved reached helper still requires the full suite');
+ assert.match(fallback.reason, /non-literal dynamic import in reached file src\/unresolved-reader\.js/u);
+});