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(tests): select tracked gate files [C7]
Corey Olsonec695119a914
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex 8f31cb55..13a53d0b 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -279,6 +279,44 @@ function hasTestFiles(args) {return false;}+/** Match Node's default test-file patterns against a Git path for this runtime. */+function isDefaultTestFile(path, includeTypeScript) {+ const normalized = path.replaceAll('\\', '/');+ const parts = normalized.split('/');+ if (parts.some(part => part === 'node_modules' || part.startsWith('.'))) return false;+ const basename = parts.at(-1);+ const extension = includeTypeScript ? /\.(?:cjs|mjs|js|cts|mts|ts)$/u : /\.(?:cjs|mjs|js)$/u;+ if (!extension.test(basename)) return false;+ return parts.slice(0, -1).includes('test') ||+ /^test(?:-|\.)/u.test(basename) ||+ (includeTypeScript+ ? /(?:\.test|-test|_test)\.(?:cjs|mjs|js|cts|mts|ts)$/u+ : /(?:\.test|-test|_test)\.(?:cjs|mjs|js)$/u).test(basename);+}++/** Probe the effective TypeScript mode of the Node child that will execute tests. */+function typeScriptTestDiscovery(args, env) {+ const typeFlags = args.filter(argument => [+ '--experimental-strip-types', '--strip-types', '--experimental-transform-types',+ '--no-experimental-strip-types', '--no-strip-types',+ ].includes(argument));+ const result = spawnSync(process.execPath, [...typeFlags, '-p', 'String(process.features?.typescript ?? false)'], {+ cwd: process.cwd(), encoding: 'utf8', env, timeout: 5_000,+ });+ if (result.error) throw result.error;+ if (result.status !== 0) {+ throw new Error(`Node could not report TypeScript test discovery mode (status ${result.status}, signal ${result.signal ?? 'none'}): ${result.stderr.trim()}`);+ }+ return !['false', 'undefined', ''].includes(result.stdout.trim());+}++/** List tracked files matching Node's runtime default patterns, excluding worktree copies. */+function trackedDefaultTestFiles(cwd = process.cwd(), includeTypeScript = false) {+ const output = execFileSync('git', ['ls-files', '-z'], { cwd, encoding: 'utf8' });+ return output.split('\0').filter(path => path && isDefaultTestFile(path, includeTypeScript)).sort()+ .map(path => `./${path}`);+}+/** Translate the runner's shard option to Node's native test-shard option, refusing malformed ranges. */function shardArguments(args) {const forwarded = [];@@ -308,10 +346,26 @@ function shardArguments(args) {}/** Run tests in the disposable environment, preserving a marker only when a parent holds the slot. */-function executeTests(args, sandbox, gateSlotHeld) {+function executeTests(args, sandbox, gateSlotHeld, fullSuite) {const env = testEnvironment(sandbox);if (gateSlotHeld) env.PULLBOARD_GATE_SLOT_HELD = '1';- const result = runTests(args, env);+ let selectedArgs = args;+ if (fullSuite) {+ let files;+ try { files = trackedDefaultTestFiles(process.cwd(), typeScriptTestDiscovery(args, env)); }+ catch (error) {+ process.stderr.write(`run-tests: could not list tracked test files: ${error.message}\n`);+ process.exitCode = 1;+ return { status: 1, signal: null };+ }+ if (files.length === 0) {+ process.stderr.write('run-tests: no tracked Node test files found; refusing filesystem discovery\n');+ process.exitCode = 1;+ return { status: 1, signal: null };+ }+ selectedArgs = [...args, ...files];+ }+ const result = runTests(selectedArgs, env);if (result.error) throw result.error;return result;}@@ -344,7 +398,7 @@ async function main(args) {const run = (gateSlotHeld) => {const sandbox = mkdtempSync(join(tmpdir(), 'pullboard-test-run-'));try {- const result = executeTests(args, sandbox, gateSlotHeld);+ const result = executeTests(args, sandbox, gateSlotHeld, fullSuite);signal = result.signal;process.exitCode = result.status ?? 1;} finally { rmSync(sandbox, { recursive: true, force: true }); }diff --git a/test/run-tests.test.js b/test/run-tests.test.jsindex eacd3317..acb8c8d9 100644--- a/test/run-tests.test.js+++ b/test/run-tests.test.js@@ -1,5 +1,6 @@/** Exercise native test-file sharding through the production test runner [C7]. */import assert from 'node:assert/strict';+import { execFileSync } from 'node:child_process';import { copyFileSync, cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';@@ -12,6 +13,12 @@ const shardFileCount = 9;const fixtureExitCeilingMs = '500';const fixtureCleanupMs = '100';+/** Initialize a private fixture repository and stage exactly its intended tests. */+function stageFixtureTests(root, paths) {+ execFileSync('git', ['init', '-q'], { cwd: root, stdio: 'ignore' });+ execFileSync('git', ['add', '--', ...paths], { cwd: root, stdio: 'ignore' });+}+/** Build a private runner checkout whose tests record the files Node actually selects. */function makeShardFixture(t) {const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-test-shards-')));@@ -35,6 +42,7 @@ function recordSelectedFile() { appendFileSync(process.env.PULLBOARD_SHARD_CAPTUtest('record ${name} [C7]', recordSelectedFile);`);}+ stageFixtureTests(root, expected.map(name => `test/${name}`));/** Remove the private runner tree after its child processes exit. */function cleanupFixture() {rmSync(root, { recursive: true, force: true });@@ -43,6 +51,118 @@ test('record ${name} [C7]', recordSelectedFile);return { root, capture, expected, runner: join(bin, 'run-tests.js') };}+/** Build a copied production runner with tracked, ignored, and untracked test files. */+function makeTrackedSelectionFixture(t) {+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-tracked-tests-')));+ const bin = join(root, 'bin');+ const source = join(root, 'src');+ const tests = join(root, 'test');+ const scratch = join(root, 'scratch');+ const expected = ['tracked', 'dot-suffix', 'dash-suffix', 'underscore-suffix', 'test-prefix', 'test-name'];+ mkdirSync(bin);+ mkdirSync(tests);+ mkdirSync(scratch);+ writeFileSync(join(root, 'package.json'), JSON.stringify({ type: 'module' }));+ writeFileSync(join(root, '.gitignore'), 'scratch/\n');+ copyFileSync(runner, join(bin, 'run-tests.js'));+ cpSync(fileURLToPath(new URL('../src', import.meta.url)), source, { recursive: true });+ const capture = join(root, 'selected-files.txt');+ const trackedSources = new Map([+ ['test/tracked.test.js', trackedFixtureSource('tracked')],+ ['prefix.test.js', trackedFixtureSource('dot-suffix')],+ ['prefix-test.cjs', trackedFixtureSource('dash-suffix')],+ ['prefix_test.mjs', trackedFixtureSource('underscore-suffix')],+ ['test-launch.js', trackedFixtureSource('test-prefix')],+ ['test.js', trackedFixtureSource('test-name')],+ ]);+ for (const [path, sourceText] of trackedSources) {+ writeFileSync(join(root, path), sourceText);+ }+ writeFileSync(join(root, 'tracked.spec.js'), `import { appendFileSync } from 'node:fs';+import { test } from 'node:test';+/** Fail if a tracked but non-default filename is selected. */+function failIfNonDefaultRuns() { appendFileSync(process.env.PULLBOARD_TRACKED_CAPTURE, 'non-default\\n'); throw new Error('non-default test was executed'); }+test('tracked spec file must not run [C7]', failIfNonDefaultRuns);+`);+ writeFileSync(join(tests, 'untracked.test.js'), `import { appendFileSync } from 'node:fs';+import { test } from 'node:test';+/** Fail if the runner discovers an untracked test from the worktree. */+function failIfUntrackedRuns() { appendFileSync(process.env.PULLBOARD_TRACKED_CAPTURE, 'untracked\\n'); throw new Error('untracked test was executed'); }+test('untracked test must not run [C7]', failIfUntrackedRuns);+`);+ writeFileSync(join(scratch, 'ignored.test.js'), `import { appendFileSync } from 'node:fs';+import { test } from 'node:test';+/** Fail if the runner discovers an ignored test from scratch storage. */+function failIfIgnoredRuns() { appendFileSync(process.env.PULLBOARD_TRACKED_CAPTURE, 'ignored\\n'); throw new Error('ignored test was executed'); }+test('ignored test must not run [C7]', failIfIgnoredRuns);+`);+ stageFixtureTests(root, ['.gitignore', ...trackedSources.keys(), 'tracked.spec.js']);+ t.after(() => rmSync(root, { recursive: true, force: true }));+ return { root, runner: join(bin, 'run-tests.js'), capture, expected };+}++/** Create a small ESM or CommonJS test that records its discovery-pattern label. */+function trackedFixtureSource(label) {+ if (label === 'dash-suffix') {+ return `const { appendFileSync } = require('node:fs');+const { test } = require('node:test');+/** Record one tracked default-pattern match. */+function recordTrackedMatch() { appendFileSync(process.env.PULLBOARD_TRACKED_CAPTURE, '${label}\\n'); }+test('tracked ${label} pattern ran [C7]', recordTrackedMatch);+`;+ }+ return `import { appendFileSync } from 'node:fs';+import { test } from 'node:test';+/** Record one tracked default-pattern match. */+function recordTrackedMatch() { appendFileSync(process.env.PULLBOARD_TRACKED_CAPTURE, '${label}\\n'); }+test('tracked ${label} pattern ran [C7]', recordTrackedMatch);+`;+}++/** Ensure default discovery runs tracked tests but never filesystem-only copies. */+function trackedSelectionTest(t) {+ const fixture = makeTrackedSelectionFixture(t);+ assert.equal(execFileSync('git', ['check-ignore', '-q', 'scratch/ignored.test.js'], { cwd: fixture.root }).length, 0,+ 'the failing scratch test is actually ignored by Git');+ const tracked = execFileSync('git', ['ls-files'], { cwd: fixture.root, encoding: 'utf8' }).trim().split(/\r?\n/u);+ assert.ok(tracked.includes('.gitignore') && tracked.includes('tracked.spec.js'), 'the non-default and ignore control files are tracked');+ assert.equal(tracked.length, fixture.expected.length + 2, 'all pattern cases and non-default controls are tracked');+ const result = runFixtureChild(process.execPath, [fixture.runner], {+ cwd: fixture.root,+ encoding: 'utf8',+ env: { ...process.env, PULLBOARD_TRACKED_CAPTURE: fixture.capture },+ });+ assert.equal(result.status, 0,+ `${result.context}\nexecuted files: ${readFileSync(fixture.capture, 'utf8')}`);+ for (const label of fixture.expected) assert.match(result.stdout, new RegExp(`ok [0-9]+ - tracked .*${label}.* pattern ran \\[C7\\]`, 'u'));+ assert.doesNotMatch(`${result.stdout}\n${result.stderr ?? ''}`, /ignored test was executed|untracked test was executed|non-default test was executed/u);+ assert.deepEqual(readFileSync(fixture.capture, 'utf8').trim().split(/\r?\n/u).sort(),+ ['tracked', 'dot-suffix', 'dash-suffix', 'underscore-suffix', 'test-prefix', 'test-name'].sort(),+ 'every default filename pattern runs exactly once');++ writeFileSync(fixture.capture, '');+ const filtered = runFixtureChild(process.execPath, [fixture.runner, '--test-name-pattern', 'dot-suffix'], {+ cwd: fixture.root,+ encoding: 'utf8',+ env: { ...process.env, PULLBOARD_TRACKED_CAPTURE: fixture.capture },+ });+ assert.equal(filtered.status, 0, filtered.context);+ assert.match(filtered.stdout, /ok [0-9]+ - tracked dot-suffix pattern ran \[C7\]/u,+ 'name filters still apply to the tracked default list');+ assert.equal(readFileSync(fixture.capture, 'utf8'), 'dot-suffix\n');++ const explicit = runFixtureChild(process.execPath, [fixture.runner, 'test/untracked.test.js'], {+ cwd: fixture.root,+ encoding: 'utf8',+ env: { ...process.env, PULLBOARD_TRACKED_CAPTURE: fixture.capture },+ });+ assert.equal(explicit.status, 1, explicit.context);+ assert.match(explicit.stdout, /not ok [0-9]+ - untracked test must not run \[C7\]/u,+ 'an explicitly named fixture remains runnable even though it is untracked');+}++test('the runner skips test files git does not track [C7]', trackedSelectionTest);+/** Run the copied production runner and return the test filenames it actually executed. */function runShardFixture(fixture, shard) {writeFileSync(fixture.capture, '');