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(core): computed-import tests run only when they read the change [C7]

Corey Olson9ec668827162
diff --git a/src/affected-tests.js b/src/affected-tests.js
index af81fb1c..e8c165de 100644
--- a/src/affected-tests.js
+++ b/src/affected-tests.js
@@ -14,8 +14,44 @@ const DOC = /^docs\/.+\.md$/u;
const TEST_TREE_INPUT = '/** @pullboard-test-input test-tree */';
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; a comment anywhere in the file counts.
+const LOADS = /^\/\*\* @pullboard-test-loads (.+?) \*\/$/gmu;
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']);
+/** The repository modules a computed-import test declares it can load, normalized; anything outside the repository is ignored. */
+function declaredLoads(source) {
+ return [...source.matchAll(LOADS)].flatMap(match => match[1].trim().split(/\s+/u)).map(path => posix.normalize(path))
+ .filter(path => MODULE.test(path) && !path.startsWith('../') && !path.startsWith('/'));
+}
+
+/**
+ * The repository modules a computed import names by literal path, such as join(root, 'src/x.js'). Every computed
+ * import in the file must name at least one; a literal that matches no module, or a computed import with no
+ * literal, leaves the file unreadable, so the caller falls back to the whole suite. Matching by the path's tail
+ * can select a module too many, never too few.
+ */
+function literalLoads(source, path, modulePaths) {
+ const targets = new Set();
+ for (const call of source.matchAll(/\bimport\s*\(/gu)) {
+ const start = call.index + call[0].length;
+ if (/^\s*(?:'[^'\\\r\n]*'|"[^"\\\r\n]*")\s*\)/u.test(source.slice(start))) continue;
+ let depth = 1, end = start;
+ for (; end < source.length && depth; end += 1) depth += source[end] === '(' ? 1 : source[end] === ')' ? -1 : 0;
+ const argument = source.slice(start, end);
+ const values = [...argument.matchAll(/(['"`])((?:\\.|(?!\1)[^\\\r\n])*)\1/gu)].map(match => match[2].split(/[?#]/u)[0]);
+ const modules = values.filter(value => MODULE.test(value) && posix.basename(value).replace(MODULE, '') !== '');
+ if (!modules.length) return null;
+ for (const value of modules) {
+ const relative = posix.normalize(posix.join(posix.dirname(path), value));
+ const tail = posix.normalize(value).replace(/^(?:\.\.?\/)+/u, '');
+ const matches = modulePaths.filter(candidate => candidate === relative || candidate === tail || candidate.endsWith('/' + tail));
+ if (!matches.length) return null;
+ for (const match of matches) targets.add(match);
+ }
+ }
+ return [...targets];
+}
+
/** Read exact objects from this checkout, ignoring ambient Git selectors and replacement refs. */
function selectionGit(root, args) {
const result = spawnSync('git', ['--no-replace-objects', '-c', 'core.quotepath=false', ...args], {
@@ -166,7 +202,7 @@ function graphAt(root, commit, changedDocs = []) {
const synchronizers = knownBuiltinSynchronizers(sources, imports);
const reverse = new Map();
const unknown = new Map();
- const always = new Set();
+ const undeclared = new Map();
const testTreeReaders = new Set();
const sourceTreeReaders = new Set();
const docInputs = new Map();
@@ -186,7 +222,16 @@ function graphAt(root, commit, changedDocs = []) {
continue;
}
if (target.startsWith('node:')) continue;
- if (target === '(computed)' && TEST.test(path)) { always.add(path); continue; }
+ if (target === '(computed)' && TEST.test(path)) {
+ const declared = declaredLoads(modules.get(path));
+ const loads = declared.length ? declared : literalLoads(modules.get(path), path, paths) ?? [];
+ if (!loads.length) undeclared.set(path, 'a computed import declares no @pullboard-test-loads and names no module it can read');
+ for (const load of loads) {
+ if (!reverse.has(load)) reverse.set(load, new Set());
+ reverse.get(load).add(path);
+ }
+ continue;
+ }
if (!target.startsWith('.')) {
unknown.set(path, target === '(computed)' ? 'non-literal dynamic import' : 'unresolved package import');
continue;
@@ -203,7 +248,7 @@ function graphAt(root, commit, changedDocs = []) {
reverse.get('bin/pullboard.js').add(path);
}
});
- return { paths, reverse, unknown, always, testTreeReaders, sourceTreeReaders, docInputs };
+ return { paths, reverse, unknown, undeclared, testTreeReaders, sourceTreeReaders, docInputs };
}
/**
@@ -238,6 +283,8 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', change
const unsupported = changed.find(path => !MODULE.test(path) && !DOC.test(path));
if (unsupported) return { full: true, reason: `import selection cannot compute the effect of ${unsupported}`, files };
const before = graphAt(root, base, changedDocs);
+ const [unreadable] = [...before.undeclared, ...after.undeclared];
+ if (unreadable) return { full: true, reason: `${unreadable[0]}: ${unreadable[1]}`, files };
const reached = new Set(changed);
const queue = [...changed];
for (const doc of changed.filter(path => DOC.test(path))) {
@@ -260,7 +307,7 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', change
}
const changedTestInput = changed.some(path => path.startsWith('test/') || TEST.test(path) || /^test\.[cm]?js$/u.test(path));
const changedSourceInput = changed.some(path => path.startsWith('src/') || path.startsWith('bin/'));
- const selected = files.filter(path => reached.has(path) || before.always.has(path) || after.always.has(path)
+ const selected = files.filter(path => reached.has(path)
|| (changedTestInput && (before.testTreeReaders.has(path) || after.testTreeReaders.has(path)))
|| (changedSourceInput && (before.sourceTreeReaders.has(path) || after.sourceTreeReaders.has(path))));
if (selected.length === files.length) return { full: true, reason: 'the change reaches every test file', files };
diff --git a/test/affected-tests.test.js b/test/affected-tests.test.js
index 05267b99..b8d21877 100644
--- a/test/affected-tests.test.js
+++ b/test/affected-tests.test.js
@@ -211,3 +211,39 @@ test('the browser launch guard keeps affected selection exact [C7,O5]', (t) => {
assert.match(fallback.reason, /CommonJS/u, 'the fallback names the unresolved module-loader boundary');
}
});
+
+test('a change to one test file selects only what reads it [V4,C7]', (t) => {
+ const box = graph(t);
+ // A computed import whose target the file declares: it reads src/api.js and nothing else.
+ box.put('test/loader.test.js', "/** @pullboard-test-loads src/api.js */\nconst name = 'api';\nawait import(new URL(`../src/${name}.js`, import.meta.url).href);\n");
+ const base = box.commit();
+ box.put('test/api.test.js', "import '../src/api.js'; // one test file changed\n");
+ let commit = box.commit();
+ let selection = selectAffectedTests(box.root, { base, commit });
+ assert.equal(selection.full, false, 'a change to one test file keeps focused selection');
+ assert.deepEqual(selection.files, ['test/api.test.js'], 'an unrelated computed-import test is not selected');
+
+ box.put('src/api.js', 'export const version = 2;\n');
+ commit = box.commit();
+ selection = selectAffectedTests(box.root, { base, commit, changed: ['src/api.js'] });
+ assert.equal(selection.full, false);
+ assert.deepEqual(selection.files, ['test/api.test.js', 'test/loader.test.js'], 'the declared reader of a changed module is selected');
+
+ selection = selectAffectedTests(box.root, { base, commit, changed: ['src/labels.js'] });
+ assert.deepEqual(selection.files, ['test/unrelated.test.js'], 'a module it does not declare leaves the loader out');
+
+ // A computed import with no declaration still reads what its literal path names.
+ box.put('test/literal.test.js', "await import(new URL('../src/labels.js', import.meta.url).href);\n");
+ commit = box.commit();
+ selection = selectAffectedTests(box.root, { base, commit, changed: ['src/labels.js'] });
+ assert.deepEqual(selection.files, ['test/literal.test.js', 'test/unrelated.test.js'], 'a literal path names the module the import reads');
+ selection = selectAffectedTests(box.root, { base, commit, changed: ['src/api.js'] });
+ assert.deepEqual(selection.files, ['test/api.test.js', 'test/loader.test.js'], 'the literal reader is left out of an unrelated change');
+
+ // A computed import that declares nothing cannot be read, so the whole suite runs and says why.
+ box.put('test/guess.test.js', 'await import(process.env.GUESS);\n');
+ commit = box.commit();
+ selection = selectAffectedTests(box.root, { base, commit, changed: ['test/api.test.js'] });
+ assert.equal(selection.full, true, 'an undeclared computed import falls back to the whole suite');
+ assert.match(selection.reason, /test\/guess\.test\.js/u, 'the fallback names the file that cannot be read');
+});
diff --git a/test/board.test.js b/test/board.test.js
index 4a04893f..5ecc10d1 100644
--- a/test/board.test.js
+++ b/test/board.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/engine.js */
/**
* The board's rules on an in-memory board with a hand-turned clock (B4–B7, V1, V2, V5, V6, V8, R1,
* R2). The git-facing rules (V3, V4, V7) run against real repos in e2e.test.js.
diff --git a/test/checked-composition-resume.test.js b/test/checked-composition-resume.test.js
index 0ab2c9cb..5a6c697d 100644
--- a/test/checked-composition-resume.test.js
+++ b/test/checked-composition-resume.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads test/e2e-helpers.js */
/**
* Standalone regression for coordinator resume after a stale verdict is freshly reviewed.
* Run with PULLBOARD_409_CANDIDATE_ROOT pointing at the source checkout under test.
diff --git a/test/cli-help.test.js b/test/cli-help.test.js
index 64e44a42..e5f81eeb 100644
--- a/test/cli-help.test.js
+++ b/test/cli-help.test.js
@@ -1,4 +1,5 @@
/** @pullboard-test-input source-tree */
+/** @pullboard-test-loads src/cli.js */
/** The layered CLI help stays short, command-specific, and in parity with its declaration [N37,I1]. */
import assert from 'node:assert/strict';
import { chmodSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
diff --git a/test/engine-replay.test.js b/test/engine-replay.test.js
index 3d864ff1..8154a078 100644
--- a/test/engine-replay.test.js
+++ b/test/engine-replay.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/exchange.js src/machine.js */
/** Replay actual released-engine receipts against the current engine [V1,H3,H16]. */
import assert from 'node:assert/strict';
import {
diff --git a/test/engine.test.js b/test/engine.test.js
index 40b4dce7..fab5aa34 100644
--- a/test/engine.test.js
+++ b/test/engine.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/engine.js src/machine.js */
/** Real-SQLite tests for the deterministic, sequence-ordered move engine [H3,H16]. */
import assert from 'node:assert/strict';
import { mkdtempSync, rmSync } from 'node:fs';
diff --git a/test/gate-resource.test.js b/test/gate-resource.test.js
index cca8d2cf..e1bb97b0 100644
--- a/test/gate-resource.test.js
+++ b/test/gate-resource.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/browser-admission.js */
/** Real gates and item checks share the machine queue; landing priority and lease behavior stay intact [Q1,Q2,Q4,O5,O6,V18]. */
import assert from 'node:assert/strict';
import { startFixtureChild as spawn, runFixtureChild as spawnSync, runFixtureChild } from './fixture-child.js';
diff --git a/test/landing-waiver-replay.test.js b/test/landing-waiver-replay.test.js
index 245564f2..93c70908 100644
--- a/test/landing-waiver-replay.test.js
+++ b/test/landing-waiver-replay.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/exchange.js src/machine.js */
/** Preserve released person-waiver receipts on independent current replicas [B3,R3,H16]. */
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
diff --git a/test/machine.test.js b/test/machine.test.js
index 95e9a757..c7ae5673 100644
--- a/test/machine.test.js
+++ b/test/machine.test.js
@@ -1,4 +1,5 @@
/** @pullboard-test-input source-tree */
+/** @pullboard-test-loads src/board.js */
/**
* The item lifecycle's declaration (M1, M2, M4): sound on its own terms, each property shown
* failing on a broken copy, and in step with the refusals the board, CLI and spec parser raise today.
diff --git a/test/merged.test.js b/test/merged.test.js
index 5c983233..0093dc89 100644
--- a/test/merged.test.js
+++ b/test/merged.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/engine.js src/machine.js */
/** Merged receipts only record item work on the primary trunk, unless noted [R3,R1]. */
import { submitFixture } from './board-submit-fixture.js';
import assert from 'node:assert/strict';
diff --git a/test/needs.test.js b/test/needs.test.js
index f7564b01..a31a2a29 100644
--- a/test/needs.test.js
+++ b/test/needs.test.js
@@ -1,4 +1,5 @@
/** @pullboard-test-input source-tree */
+/** @pullboard-test-loads src/needs.js */
/** One person-facing obligation builder across sessions and transports [N26,A9]. */
import assert from 'node:assert/strict';
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
diff --git a/test/pending-refreeze.test.js b/test/pending-refreeze.test.js
index f121a1b2..2e981179 100644
--- a/test/pending-refreeze.test.js
+++ b/test/pending-refreeze.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/exchange.js src/machine.js */
/** Pending coordinator corrections keep a live claim until its frozen bar is adopted [V2,H16]. */
import assert from 'node:assert/strict';
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
diff --git a/test/relay-deploy.test.js b/test/relay-deploy.test.js
index beeb5b72..a58549e4 100644
--- a/test/relay-deploy.test.js
+++ b/test/relay-deploy.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads relay/client.js src/changelog.js */
/** Exercise the deploy smoke script against a private loopback relay [H5,H18]. */
import assert from 'node:assert/strict';
import { startFixtureChild as spawn, reportFixtureChildFailure, safeFixtureDiagnostic } from './fixture-child.js';
diff --git a/test/reopen.test.js b/test/reopen.test.js
index 70517ca7..0187ff5b 100644
--- a/test/reopen.test.js
+++ b/test/reopen.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/exchange.js src/machine.js */
/** Real Git, SQLite and ordered-engine coverage for coordinator criterion reopen [V2,V6,H16]. */
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
diff --git a/test/resources.test.js b/test/resources.test.js
index 400c729e..744d6c08 100644
--- a/test/resources.test.js
+++ b/test/resources.test.js
@@ -1,4 +1,5 @@
/** @pullboard-test-input source-tree */
+/** @pullboard-test-loads src/cli.js */
/** Real-process resource queue and lease coverage [Q1,Q2,Q3]. */
import assert from 'node:assert/strict';
import { startFixtureChild as spawn, runFixtureChild as spawnSync, reportFixtureChildFailure, runFixtureChild, runFixtureChildAsync, runFixtureGit } from './fixture-child.js';
diff --git a/test/rigor.test.js b/test/rigor.test.js
index f56f47e9..bc5ff1bb 100644
--- a/test/rigor.test.js
+++ b/test/rigor.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/machine.js */
/** Rigor: a repeated failure cause is noticed from structured fields, never from notes [D1,V1]. */
import { submitFixture } from './board-submit-fixture.js';
import assert from 'node:assert/strict';
diff --git a/test/seal.test.js b/test/seal.test.js
index f2637888..926fcee0 100644
--- a/test/seal.test.js
+++ b/test/seal.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/seal.js */
/** Device-side sealing is the same bytes and WebCrypto code in Node and Chrome (H15, H17). */
import assert from 'node:assert/strict';
import { runFixtureChild as spawnSync } from './fixture-child.js';
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index f2da2bc6..45c1f6ca 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -964,27 +964,26 @@ for (const mode of ['topic parent', 'merge commit']) {
});
}
-test('computed imports in test files are always selected in both graphs without forcing full [V4,C7]', (t) => {
+test('a computed-import test joins the selection only when it declares what it loads, and undeclared forces full [V4,C7]', (t) => {
const box = privateRepo(t);
const original = seedGraph(box);
put(box.root, 'test/c.test.js', "export const load = path => import(path);\n");
const base = commitAll(box);
const added = selectAffectedTests(box.root, { base: original, commit: base, changed: ['src/a.js'] });
- assert.equal(added.full, false);
- assert.deepEqual(added.files, ['test/a.test.js', 'test/c.test.js'], 'the new graph also always selects its computed-import test');
- put(box.root, 'src/a.js', 'export const value = 2;\n');
- let commit = commitAll(box, 'feat(core): source change [G1]');
- let selection = selectAffectedTests(box.root, { base, commit });
- assert.equal(selection.full, false);
- assert.deepEqual(selection.files, ['test/a.test.js', 'test/c.test.js'], 'an unrelated computed-import test is always selected');
- selection = selectAffectedTests(box.root, { base, commit, changed: ['test/c.test.js'] });
- assert.equal(selection.full, false, 'reaching a computed-import test does not force full');
- assert.deepEqual(selection.files, ['test/c.test.js']);
+ assert.equal(added.full, true, 'an undeclared computed import cannot be read, so the whole suite runs');
+ assert.match(added.reason, /test\/c\.test\.js/u, 'the reason names the undeclared file');
+ put(box.root, 'test/c.test.js', "/** @pullboard-test-loads src/a.js */\nexport const load = path => import(path);\n");
+ const declared = commitAll(box, 'test(core): declare what the loader reads [G1]');
+ put(box.root, 'src/a.js', 'export const value = 2;\n'); let commit = commitAll(box, 'feat(core): source change [G1]');
+ let selection = selectAffectedTests(box.root, { base: declared, commit }); assert.equal(selection.full, false);
+ assert.deepEqual(selection.files, ['test/a.test.js', 'test/c.test.js'], 'a declared loader of the changed module is selected');
+ selection = selectAffectedTests(box.root, { base: declared, commit, changed: ['test/c.test.js'] });
+ assert.equal(selection.full, false, 'reaching a computed-import test does not force full'); assert.deepEqual(selection.files, ['test/c.test.js']);
put(box.root, 'test/c.test.js', "import 'node:assert/strict';\n");
commit = commitAll(box, 'test(core): remove computed loader [G1]');
- selection = selectAffectedTests(box.root, { base, commit, changed: ['src/a.js'] });
+ selection = selectAffectedTests(box.root, { base: declared, commit, changed: ['src/a.js'] });
assert.equal(selection.full, false);
- assert.deepEqual(selection.files, ['test/a.test.js', 'test/c.test.js'], 'the old graph keeps its computed-import test selected');
+ assert.deepEqual(selection.files, ['test/a.test.js', 'test/c.test.js'], 'the old graph keeps its declared loader selected');
});
diff --git a/test/team-engine.test.js b/test/team-engine.test.js
index 00201ca9..46b4b276 100644
--- a/test/team-engine.test.js
+++ b/test/team-engine.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/exchange.js src/machine.js */
/** Sealed re-reviews bind the original work without changing released receipts [E8,H16,V8]. */
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, rmSync } from 'node:fs';
diff --git a/test/team.test.js b/test/team.test.js
index a59dc5ca..b917a268 100644
--- a/test/team.test.js
+++ b/test/team.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-loads src/board.js src/engine.js src/exchange.js */
/** Two independent Git/SQLite replicas derive verdict freshness without rewriting proof [E8]. */
import assert from 'node:assert/strict';
import childProcess from 'node:child_process';