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
test: restrict gate discovery to named test entries [C7]
Corey Olson405f1639ec7c
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex 019edcee..6f96baba 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -301,7 +301,7 @@ function explicitTestFiles(args) {function isDefaultTestFile(path) {const normalized = path.replaceAll('\\', '/');if (normalized.split('/').some(part => part === 'node_modules' || part.startsWith('.'))) return false;- return /^(?:test|docs)\/.+\.test\.(?:js|mjs)$/u.test(normalized);+ return /(?:^|\/)[^/]+\.test\.(?:js|mjs)$/u.test(normalized);}/** Preserve native discovery outside Git, but never hide a repository access failure. */diff --git a/src/affected-tests.js b/src/affected-tests.jsindex a4d238e8..b8cf8d89 100644--- a/src/affected-tests.js+++ b/src/affected-tests.js@@ -7,7 +7,6 @@ import { importsIn } from './module-imports.js';const MODULE = /\.[cm]?js$/u;const TEST = /\.(?:test|spec)\.[cm]?js$/u;const DOC = /^docs\/.+\.md$/u;-const TEST_README = /^test\/(?:.*\/)?README\.md$/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 SOURCE_TREE_INPUT = '/** @pullboard-test-input source-tree */';@@ -69,7 +68,7 @@ function modulesAt(root, commit) {* Computed Markdown names select the docs tree; opaque helpers declare DOCS_TREE_INPUT. The* landing gate remains complete and never uses this submit-only optimization.*/-function documentationInputs(path, source, imports, changedDocs = [], changedReadmes = []) {+function documentationInputs(path, source, imports, changedDocs = []) {const inputs = new Set();if (source.split(/\r?\n/u).includes(DOCS_TREE_INPUT)) inputs.add('docs');// Plain text is the required conservative rule: syntax, comments, and escapes do not matter.@@ -83,17 +82,6 @@ function documentationInputs(path, source, imports, changedDocs = [], changedReaif (wholeWord.test(source)) inputs.add(doc);}const markdownReader = imports.some(target => target === 'node:fs' || target === 'node:fs/promises');- if (changedReadmes.length) {- // Recognize literal join components without interpreting expressions or template interpolations.- const quoted = String.raw`(?:"(?:\\[\s\S]|[^"\\])*"|'(?:\\[\s\S]|[^'\\])*')`;- const joins = new RegExp(String.raw`\b(?:[A-Za-z_$][\w$]*\.)?join\s*\(\s*(${quoted}(?:\s*,\s*${quoted})*)\s*,?\s*\)`, 'gu');- for (const match of source.matchAll(joins)) {- try {- const parts = [...match[1].matchAll(new RegExp(quoted, 'gu'))].map(part => new Function(`return ${part[0]};`)());- addReadmeInput(inputs, path, posix.join(...parts), changedReadmes);- } catch { /* Only complete valid string literals supply path inputs. */ }- }- }const literals = /(['"])(?:\\[\s\S]|(?!\1)[^\\\r\n])*\1|`(?:\\[\s\S]|[^`\\])*`/uy;// Try every quote start: a quote in a comment or regular expression must not hide a later real path.for (const quote of source.matchAll(/['"`]/gu)) {@@ -144,21 +132,13 @@ function documentationInputs(path, source, imports, changedDocs = [], changedReafor (const candidate of [posix.normalize(value), posix.normalize(posix.join(posix.dirname(path),value))]) {if (candidate === 'docs' || candidate.startsWith('docs/')) inputs.add(candidate.replace(/\/$/u,''));}- addReadmeInput(inputs, path, value, changedReadmes);}}return inputs;}-/** Match a complete literal README path from the repository or the reader's own directory. */-function addReadmeInput(inputs, path, value, changedReadmes) {- for (const candidate of [posix.normalize(value), posix.normalize(posix.join(posix.dirname(path), value))]) {- if (changedReadmes.includes(candidate)) inputs.add(candidate);- }-}-/** Compile this tree's import edges, plus the literal child-CLI dependency used by fixture modules. */-function graphAt(root, commit, changedDocs = [], changedReadmes = []) {+function graphAt(root, commit, changedDocs = []) {const modules = modulesAt(root, commit);const paths = [...modules.keys()];const imports = importsIn([...modules.values()]);@@ -169,10 +149,7 @@ function graphAt(root, commit, changedDocs = [], changedReadmes = []) {const sourceTreeReaders = new Set();const docInputs = new Map();paths.forEach((path, index) => {- if (changedDocs.length || changedReadmes.length) {- const inputs = documentationInputs(path, modules.get(path), imports[index], changedDocs, changedReadmes);- docInputs.set(path, inputs);- }+ if (changedDocs.length) docInputs.set(path, documentationInputs(path, modules.get(path), imports[index], changedDocs));if (TEST.test(path)) {for (const line of modules.get(path).split(/\r?\n/u)) {if (line === TEST_TREE_INPUT) testTreeReaders.add(path);@@ -228,18 +205,17 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', change}changed ??= selectionGit(root, ['diff', '--no-renames', '--name-only', '-z', base, commit]).split('\0').filter(Boolean);const changedDocs = changed.filter(path => DOC.test(path));- const changedReadmes = changed.filter(path => TEST_README.test(path));- const after = graphAt(root, commit, changedDocs, changedReadmes);+ const after = graphAt(root, commit, changedDocs);files = after.paths.filter(path => TEST.test(path)).sort();const fallback = changed.find(path => GLOBAL.has(path) || path.startsWith('.githooks/'));if (fallback) return { full: true, reason: `${fallback} controls the gate or dependency selection`, files };if (!files.length) return { full: true, reason: 'no committed Node test files can be selected', files };- const unsupported = changed.find(path => !MODULE.test(path) && !DOC.test(path) && !TEST_README.test(path));+ 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, changedReadmes);+ const before = graphAt(root, base, changedDocs);const reached = new Set(changed);const queue = [...changed];- for (const doc of [...changedDocs, ...changedReadmes]) {+ for (const doc of changed.filter(path => DOC.test(path))) {for (const graph of [before, after]) {for (const [reader, inputs] of graph.docInputs) {if ([...inputs].some(input => input === doc || doc.startsWith(input + '/'))) {@@ -257,7 +233,7 @@ export function selectAffectedTests(root, { base, trunk, commit = 'HEAD', change}}}- const changedTestInput = changed.some(path => !TEST_README.test(path) && (path.startsWith('test/') || TEST.test(path) || /^test\.[cm]?js$/u.test(path)));+ 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)|| (changedTestInput && (before.testTreeReaders.has(path) || after.testTreeReaders.has(path)))diff --git a/test/run-tests.test.js b/test/run-tests.test.jsindex 891b3f2a..b9f3c71a 100644--- a/test/run-tests.test.js+++ b/test/run-tests.test.js@@ -8,7 +8,6 @@ import { fileURLToPath } from 'node:url';import { test } from 'node:test';import { startFixtureChild, runFixtureChild, runFixtureGit } from './fixture-child.js';import { listResources } from '../src/resources.js';-import { selectAffectedTests } from '../src/affected-tests.js';const runner = fileURLToPath(new URL('../bin/run-tests.js', import.meta.url));const shardFileCount = 9;@@ -60,7 +59,7 @@ function makeTrackedSelectionFixture(t) {const source = join(root, 'src');const tests = join(root, 'test');const scratch = join(root, 'scratch');- const expected = ['tracked', 'docs-esm'];+ const expected = ['tracked', 'docs-esm', 'dot-suffix'];mkdirSync(bin);mkdirSync(tests);mkdirSync(scratch);@@ -178,7 +177,7 @@ function onlyTestEntriesTest(t) {mkdirSync(dirname(join(fixture.root, path)), { recursive: true });writeFileSync(join(fixture.root, path), body);};- /** Commit the fixture graph so the selector reads immutable Git objects. */+ /** Commit the fixture entries in a real Git repository. */const commit = () => {runFixtureGit(['add', '-A'], { cwd: fixture.root, env });runFixtureGit(['commit', '-qm', 'chore: discovery fixture'], { cwd: fixture.root, env });@@ -205,7 +204,7 @@ test('perf helpers remain importable [C7]', importedHelpersWork);put('docs/guide.test.mjs', "import { test } from 'node:test';\nimport { appendFileSync } from 'node:fs';\n/** Exercise a named documentation test entry. */\nfunction guide() { appendFileSync(process.env.PULLBOARD_SHARD_CAPTURE, 'docs/guide.test.mjs\\n'); }\ntest('documentation test entry [C7]', guide);\n");put('test/tree-reader.test.js', "/** @pullboard-test-input test-tree */\nimport { appendFileSync } from 'node:fs';\nappendFileSync(process.env.PULLBOARD_SHARD_CAPTURE, 'tree-reader.test.js\\n');\n");put('test/cockpit/perf/README.md', '# Perf harness\n');- const base = commit();+ commit();const discovered = runFixtureChild(process.execPath, [fixture.runner], {cwd: fixture.root, encoding: 'utf8', env,});@@ -235,43 +234,6 @@ test('perf helpers remain importable [C7]', importedHelpersWork);assert.equal(beforeTotal, afterTotal + helpers.length,'only the standalone helper-file records disappear from the raw TAP total');process.stderr.write(`fixture declared cases: before=${expectedCases.length}, after=${expectedCases.length}; raw TAP: before=${beforeTotal}, after=${afterTotal}; helper records removed=${helpers.length}\n`);- put('test/cockpit/perf/README.md', '# Updated harness instructions\n');- const head = commit();- const readme = selectAffectedTests(fixture.root, { base, commit: head });- assert.equal(readme.full, false, 'an unread test README does not force the full gate');- assert.deepEqual(readme.files, [], 'an unread README does not activate the test-tree scanner');- assert.equal(selectAffectedTests(fixture.root, {- base, commit: head, changed: ['test/cockpit/perf/unknown.json'],- }).full, true, 'unknown test assets still require the full gate');- put('test/cockpit/readme-helper.js', "import { readFileSync } from 'node:fs';\nexport const instructions = readFileSync(new URL('./perf/README.md', import.meta.url), 'utf8');\n");- put('test/cockpit/readme-reader.test.js', "import './readme-helper.js';\n");- put('test/cockpit/joined-helper.js', "import { readFileSync } from 'node:fs';\nimport { join } from 'node:path';\nexport const instructions = readFileSync(join('test', 'cockpit', 'perf', 'README.md'), 'utf8');\n");- put('test/cockpit/escaped-helper.js', "import { readFileSync } from 'node:fs';\nexport const instructions = readFileSync(new URL('./perf/REA\\x44ME.md', import.meta.url), 'utf8');\n");- for (const name of ['joined', 'escaped']) {- put(`test/cockpit/${name}-reader.test.js`, `import assert from 'node:assert/strict';-import { test } from 'node:test';-import { instructions } from './${name}-helper.js';-/** Read and assert the actual fixture README through the helper. */-function readInstructions() { assert.match(instructions, /Updated harness instructions/u); }-test('${name} README reader [C7]', readInstructions);-`);- }- const readerBase = commit();- const readerRun = runFixtureChild(process.execPath, [fixture.runner,- 'test/cockpit/joined-reader.test.js', 'test/cockpit/escaped-reader.test.js'], {- cwd: fixture.root, encoding: 'utf8', env,- });- assert.equal(readerRun.status, 0, `${readerRun.context}\n${readerRun.stdout}`);- assert.match(readerRun.stdout, /^# tests 2$/mu, 'both literal readers actually execute their filesystem reads');- put('test/cockpit/readme-helper.js', "export const instructions = 'reader removed';\n");- put('test/cockpit/perf/README.md', '# Instructions after reader removal\n');- const readerHead = commit();- const readers = selectAffectedTests(fixture.root, {- base: readerBase, commit: readerHead, changed: ['test/cockpit/perf/README.md'],- });- assert.equal(readers.full, false);- assert.deepEqual(readers.files, ['test/cockpit/escaped-reader.test.js', 'test/cockpit/joined-reader.test.js', 'test/cockpit/readme-reader.test.js'],- 'real literal readers and the removed helper edge remain selected, without test-tree-wide widening');}test('the suite runs only test files, not helpers or the perf harness [C7]', onlyTestEntriesTest);