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
feat(cache): replay recorded per-file TAP on reuse [C7]
Corey Olson4f5b61450ccd
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex aed6761e..45497fc8 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -304,7 +304,7 @@ function runTests(args, env, concurrency) {'--disable-warning=ExperimentalWarning','--test',`--test-concurrency=${files}`,- ...(!reporter ? ['--test-reporter=tap'] : []),+ ...(!reporter ? ['--test-reporter=tap', ...(env.PULLBOARD_TEST_ACTIONS ? ['--test-reporter-destination=stdout', `--test-reporter=${fileURLToPath(new URL('../src/test-action-reporter.js', import.meta.url))}`, '--test-reporter-destination=/dev/null'] : [])] : []),'--import',runner,...placed,@@ -890,6 +890,7 @@ async function runLandingTests(args, env, concurrency) {const selectedFiles = options.selectedFiles;delete options.selectedFiles;const reporterEntries = options.reporters;+ if (process.env.PULLBOARD_TEST_ACTIONS) reporterEntries.push({ reporter: fileURLToPath(new URL('../src/test-action-reporter.js', import.meta.url)), destination: '/dev/null' });delete options.reporters;const loadedReporters = [];for (const entry of reporterEntries) {diff --git a/src/test-action-cache.js b/src/test-action-cache.jsindex 39e017b8..0d1a2711 100644--- a/src/test-action-cache.js+++ b/src/test-action-cache.js@@ -38,7 +38,7 @@ export const TEST_ACTIONS_ENV = 'PULLBOARD_TEST_ACTIONS';export const TEST_STAGE_ENV = 'PULLBOARD_TEST_STAGE';const VERSION = 1;const MODULE = /\.[cm]?js$/u;-const RUNNER_INPUTS = ['bin/run-tests.js', 'package.json'];+const RUNNER_INPUTS = ['bin/run-tests.js', 'src/test-action-reporter.js', 'package.json'];// The environment a test's verdict may depend on; anything else in the environment is per-run noise.const DECLARED_ENVIRONMENT = ['NODE_OPTIONS', 'PULLBOARD_HOSTED_SHAPES', 'PULLBOARD_TEST_TIMEOUT_MS', 'PULLBOARD_TEST_FILE_TIMEOUT_MS', 'TZ', 'LANG', 'LC_ALL'];// Options that choose how a run reports or splits files, never what a file proves.@@ -248,10 +248,17 @@ export function reusableResult(store, key) {try { statSync(join(store, 'red', key)); return null; } catch { /* No red mark: the key never failed. */ }try {const entry = JSON.parse(readFileSync(join(store, 'green', `${key}.json`), 'utf8'));- return entry?.version === VERSION && entry.key === key && entry.status === 'pass' && typeof entry.commit === 'string' ? entry : null;+ return entry?.version === VERSION && entry.key === key && entry.status === 'pass' && typeof entry.commit === 'string' && validTap(entry.tap) ? entry : null;} catch { return null; }}+/** Incomplete reports rerun: an exit status alone cannot reproduce the file's recorded proof. */+function validTap(report) {+ return report && Array.isArray(report.lines) && report.lines.every(line => typeof line === 'string' && /^\s*(?:not )?ok \d+(?: |$)/u.test(line))+ && report.counts && ['passed', 'failed', 'skipped', 'tests'].every(name => Number.isSafeInteger(report.counts[name]) && report.counts[name] >= 0)+ && report.counts.failed === 0 && report.observedTests === report.counts.tests;+}+/*** The one rule for whether per-file results, fresh or reused, prove the whole suite: every file of the suite has a* result, every result passed, and every reused result was stored under the key the file has now. Pure: it reads@@ -300,7 +307,7 @@ function pruneRuns(store) {*/export async function planTestActions(root, args, { fullSuite, landing = false, listFiles, env = process.env, write = text => process.stdout.write(text) }) {const keep = { args, files: null, done: false };- if (env[TEST_ACTIONS_ENV] || env.PULLBOARD_TEST_REUSE === '0' || args.some(arg => FILTER_OPTION.test(arg))) return keep;+ if (env[TEST_ACTIONS_ENV] || env.PULLBOARD_TEST_REUSE === '0' || args.some(arg => FILTER_OPTION.test(arg) || /^--test[-_]reporter(?:[-_]destination)?(?:=|$)/u.test(arg))) return keep;let store, commit, keys, selectors;try {root = realpathSync(root);@@ -323,6 +330,7 @@ export async function planTestActions(root, args, { fullSuite, landing = false,if (!entry) { run.push(file); continue; }results.set(file.path, { status: 'pass', source: 'reused', key: entry.key, currentKey: file.key });write(`# reused ${entry.key} from ${entry.stage} ${entry.commit} (${file.path})\n`);+ write(`${entry.tap.lines.join('\n')}\n# pass ${entry.tap.counts.passed}\n# fail ${entry.tap.counts.failed}\n# skipped ${entry.tap.counts.skipped}\n`);}if (!run.length && suiteProven(selectors.map(file => file.path), results).proven) {write(`# all ${selectors.length} test files reused; none ran\n`);@@ -355,9 +363,12 @@ export function settleTestActions(runDir, { store, stage, commit, landing, codelet staged;try { staged = JSON.parse(readFileSync(join(runDir, 'green', name), 'utf8')); } catch { continue; }if (typeof staged?.key !== 'string' || !/^[0-9a-f]{64}$/u.test(staged.key)) continue;+ let tap;+ try { tap = JSON.parse(readFileSync(join(runDir, `${digest(staged.file)}.tap.json`), 'utf8')); } catch { continue; }+ if (!validTap(tap)) continue;try { statSync(join(store, 'red', staged.key)); continue; } catch { /* Never red: the green may be stored. */ }writeAtomic(join(store, 'green', `${staged.key}.json`), { version: VERSION, key: staged.key, file: staged.file,- status: 'pass', stage, commit, node: process.version, at: new Date().toISOString() });+ status: 'pass', stage, commit, node: process.version, at: new Date().toISOString(), tap });}}} catch (error) {diff --git a/src/test-action-reporter.js b/src/test-action-reporter.jsnew file mode 100644index 00000000..82fa7bf9--- /dev/null+++ b/src/test-action-reporter.js@@ -0,0 +1,45 @@+/** Record Node's actual per-file TAP outcomes alongside the public reporter [C7]. */+import { createHash } from 'node:crypto';+import {+ readFileSync,+ renameSync,+ writeFileSync,+} from 'node:fs';+import {+ join,+ relative,+ sep,+} from 'node:path';+import { tap } from 'node:test/reporters';++/** Consume the real event stream without adding output to the caller's selected reporter. */+export default async function* recordActionTap(events) {+ const directory = process.env.PULLBOARD_TEST_ACTIONS;+ const plan = JSON.parse(readFileSync(join(directory, 'keys.json'), 'utf8'));+ const reports = new Map();+ for await (const event of events) {+ const file = event.data?.file;+ if (!file) continue;+ const path = relative(plan.root, file).split(sep).join('/');+ if (!plan.files[path]) continue;+ if (!reports.has(path)) reports.set(path, { lines: [], counts: null, observedTests: 0 });+ const report = reports.get(path);+ if (event.type === 'test:pass' || event.type === 'test:fail') {+ if (event.data.details?.type !== 'suite') report.observedTests += 1;+ // Node supplies the escaping, nesting and numbering used by the public TAP reporter.+ for await (const chunk of tap([event])) {+ for (const line of chunk.split('\n')) if (/^\s*(?:not )?ok \d+(?: |$)/u.test(line)) report.lines.push(line);+ }+ }+ if (event.type === 'test:summary' && event.data.success) report.counts = event.data.counts;+ }+ for (const [file, report] of reports) {+ // A helper can register tests at another source location. Without every outcome's attribution, run fresh.+ if (!report.counts || report.observedTests !== report.counts.tests) continue;+ const name = createHash('sha256').update(file).digest('hex');+ const path = join(directory, `${name}.tap.json`);+ const temporary = `${path}.${process.pid}.tmp`;+ writeFileSync(temporary, JSON.stringify(report), { mode: 0o600 });+ renameSync(temporary, path);+ }+}