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): select declared test-tree readers [C7,B3]

Corey Olsonf7833a6464b6
diff --git a/src/affected-tests.js b/src/affected-tests.js
index fef72f7c..65c27b5b 100644
--- a/src/affected-tests.js
+++ b/src/affected-tests.js
@@ -6,6 +6,8 @@ import { importsIn } from './module-imports.js';
const MODULE = /\.[cm]?js$/u;
const TEST = /\.(?:test|spec)\.[cm]?js$/u;
+// A scanner declares this header rather than executing code while the graph is read.
+const TEST_TREE_INPUT = '/** @pullboard-test-input test-tree */';
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']);
/** Read exact objects from this checkout, ignoring ambient Git selectors and replacement refs. */
@@ -63,7 +65,9 @@ function graphAt(root, commit) {
const reverse = new Map();
const unknown = new Map();
const always = new Set();
+ const testTreeReaders = new Set();
paths.forEach((path, index) => {
+ if (TEST.test(path) && modules.get(path).split(/\r?\n/u, 1)[0] === TEST_TREE_INPUT) testTreeReaders.add(path);
for (const target of imports[index]) {
if (target === 'node:module') { unknown.set(path, 'a reached module may create CommonJS imports'); continue; }
if (target.startsWith('node:')) continue;
@@ -78,12 +82,13 @@ function graphAt(root, commit) {
reverse.get(dependency).add(path);
}
});
- return { paths, reverse, unknown, always };
+ return { paths, reverse, unknown, always, testTreeReaders };
}
/**
* Select changed tests and every transitive importer in the old and new trees. Old edges cover
- * deletions and renames; process launches and filesystem reads are deliberately not import edges.
+ * deletions and renames; declared test-tree readers also cover changed test inputs. Other filesystem
+ * reads and process launches are deliberately not import edges.
*
* @param {string} root
* @param {{base:string|null, trunk?:string, commit?:string, changed?:string[]}} options
@@ -121,7 +126,9 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', change
}
}
}
- const selected = files.filter(path => reached.has(path) || before.always.has(path) || after.always.has(path));
+ const changedTestInput = changed.some(path => path.startsWith('test/') || TEST.test(path) || /^test\.[cm]?js$/u.test(path));
+ const selected = files.filter(path => reached.has(path) || before.always.has(path) || after.always.has(path)
+ || (changedTestInput && (before.testTreeReaders.has(path) || after.testTreeReaders.has(path))));
if (selected.length === files.length) return { full: true, reason: 'the change reaches every test file', files };
return { full: false, reason: '', files: selected };
} catch (error) {
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index df297f28..38a17d1d 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-input test-tree */
/**
* Submit proves its frozen item check and the import closure its change can reach; only a full
* selection can stand in for the project gate, which still runs at landing [V4,C7,V16].
@@ -448,6 +449,55 @@ test('computed imports in test files are always selected in both graphs without
assert.deepEqual(selection.files, ['test/a.test.js', 'test/c.test.js'], 'the old graph keeps its computed-import test selected');
});
+
+/** Test-tree readers are data dependencies even when no import reaches their scanner. */
+test('a changed test file selects the scanners that read test files [C7,B3]', (t) => {
+ const box = privateRepo(t);
+ seedGraph(box);
+ const declaration = '/** @pullboard-test-input test-tree */\n';
+ put(box.root, 'test/chrome-fixture.test.js', "import 'node:assert/strict';\n");
+ put(box.root, 'test/wall-clock-budgets.test.js', declaration + "import 'node:assert/strict';\n");
+ put(box.root, 'test/nested/reader.test.mjs', declaration + "import 'node:fs';\n");
+ put(box.root, 'test/comment-only.test.js', "const text = '/** @pullboard-test-input test-tree */';\n");
+ const base = commitAll(box);
+ put(box.root, 'test/chrome-fixture.test.js', "import 'node:assert/strict';\n// changed test behavior\n");
+ const commit = commitAll(box, 'test(core): change browser regression [G1]');
+ const expected = ['test/chrome-fixture.test.js', 'test/nested/reader.test.mjs', 'test/wall-clock-budgets.test.js'];
+ const selection = selectAffectedTests(box.root, { base, commit });
+ assert.equal(selection.full, false, 'declared scanners add their own files without selecting unrelated tests');
+ assert.deepEqual(selection.files, expected, 'a change only to the browser test selects the real scanner names');
+ assert.ok(readFileSync(join(import.meta.dirname, 'wall-clock-budgets.test.js'), 'utf8').startsWith(declaration),
+ 'the repository clock scanner declares its test-tree input');
+ for (const path of ['test/support.js', 'test/new.test.js', 'test.js']) {
+ assert.deepEqual(selectAffectedTests(box.root, { base, commit, changed: [path] }).files,
+ expected.filter(file => file !== 'test/chrome-fixture.test.js'), path + ' changes the scanner input tree');
+ }
+ assert.deepEqual(selectAffectedTests(box.root, { base, commit, changed: ['src/a.js'] }).files, ['test/a.test.js'],
+ 'a source-only change keeps the normal import closure');
+ put(box.root, 'test/wall-clock-budgets.test.js', "import 'node:assert/strict';\n");
+ const removed = commitAll(box, 'test(core): remove scanner declaration [G1]');
+ assert.deepEqual(selectAffectedTests(box.root, { base: commit, commit: removed, changed: ['test/chrome-fixture.test.js'] }).files,
+ expected, 'the old graph retains a scanner whose declaration was removed');
+
+ // Use committed repository sources so a real scanner cannot be replaced by a synthetic stand-in.
+ const repository = resolve(import.meta.dirname, '..');
+ const actual = privateRepo(t);
+ const tracked = execFileSync('git', ['ls-files', '-z', 'src/', 'test/'], {
+ cwd: repository, encoding: 'utf8',
+ }).split('\0').filter(path => /\.[cm]?js$/u.test(path));
+ for (const path of tracked) put(actual.root, path, readFileSync(join(repository, path), 'utf8'));
+ const actualBase = commitAll(actual);
+ appendFileSync(join(actual.root, 'test/cockpit/demo.test.js'), '\n// Only the cockpit input changes.\n');
+ const actualCommit = commitAll(actual, 'test(core): change cockpit input [G1]');
+ assert.deepEqual(actual.git('diff', '--name-only', actualBase, actualCommit).split('\n'),
+ ['test/cockpit/demo.test.js'], 'the real-source fixture changes only the cockpit test');
+ const actualSelection = selectAffectedTests(actual.root, { base: actualBase, commit: actualCommit });
+ assert.equal(actualSelection.full, false, 'a cockpit-only input keeps affected selection');
+ for (const scanner of ['test/wall-clock-budgets.test.js', 'test/submit-gate.test.js']) {
+ assert.ok(actualSelection.files.includes(scanner), 'actual test-tree reader selected: ' + scanner);
+ }
+});
+
test('affected selection says explicitly when no claim head was recorded [V4,C7]', (t) => {
const box = privateRepo(t);
seedGraph(box);
diff --git a/test/wall-clock-budgets.test.js b/test/wall-clock-budgets.test.js
index a4b7fa38..1e7b45a5 100644
--- a/test/wall-clock-budgets.test.js
+++ b/test/wall-clock-budgets.test.js
@@ -1,3 +1,4 @@
+/** @pullboard-test-input test-tree */
/** Keep test timing judgments accountable to their actual work [C7]. */
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';