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(runner): count native selected cases on canonical controls [C7]
Corey Olson28265d4404ed
diff --git a/bin/run-tests.js b/bin/run-tests.jsindex f17bbf94..565f190a 100644--- a/bin/run-tests.js+++ b/bin/run-tests.js@@ -16,6 +16,10 @@ import { after, afterEach, beforeEach } from 'node:test';import { Worker } from 'node:worker_threads';import { randomUUID } from 'node:crypto';import { channel } from 'node:diagnostics_channel';+import {+ selectedTestResult,+ testSelectionPatterns,+} from '../src/test-selection.js';import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';import { isLandingWorkerIdentityTimeout, landingWorkerIdentityQuery, parseLandingWorkerIdentity } from '../src/landing-worker-identity.js';import { foreignNodeOptions, isolateTestMachine } from '../src/test-isolation.js';@@ -303,6 +307,15 @@ function runTests(args, env, concurrency) {} else selectors.push(argument);}const reporter = args.some((argument) => argument === '--test-reporter' || argument.startsWith('--test-reporter='));+ const selectionReporter = [];+ if (env.PULLBOARD_TEST_SELECTION) {+ const reporters = placed.filter(argument => /^--test-reporter(?:=|$)/u.test(argument)).length;+ const destinations = placed.filter(argument => /^--test-reporter-destination(?:=|$)/u.test(argument)).length;+ if (destinations && destinations !== reporters) throw new Error('each --test-reporter requires a matching --test-reporter-destination');+ if (reporter && !destinations) for (let index = 0; index < reporters; index++) selectionReporter.push('--test-reporter-destination=stdout');+ if (!reporter && !env.PULLBOARD_TEST_ACTIONS) selectionReporter.push('--test-reporter-destination=stdout');+ selectionReporter.push(`--test-reporter=${fileURLToPath(new URL('../src/test-selection.js', import.meta.url))}`, `--test-reporter-destination=${devNull}`);+ }const nodeArgs = ['--disable-warning=ExperimentalWarning','--test',@@ -311,6 +324,7 @@ function runTests(args, env, concurrency) {'--import',runner,...placed,+ ...selectionReporter,...selectors,];return spawnSync(process.execPath, nodeArgs, { env, stdio: 'inherit' });@@ -894,6 +908,7 @@ async function runLandingTests(args, env, concurrency) {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: devNull });+ if (testEnv.PULLBOARD_TEST_SELECTION) reporterEntries.push({ reporter: fileURLToPath(new URL('../src/test-selection.js', import.meta.url)), destination: devNull });delete options.reporters;const loadedReporters = [];for (const entry of reporterEntries) {@@ -1384,6 +1399,9 @@ function shardArguments(args) {/** Run tests in the disposable environment, preserving a marker only when a parent holds the slot. */async function executeTests(args, sandbox, gateMarkers, fullSuite, concurrency) {const env = testEnvironment(sandbox, gateMarkers);+ const patterns = testSelectionPatterns(args);+ if (patterns.length) env.PULLBOARD_TEST_SELECTION = join(sandbox, 'selected-tests.json');+ else delete env.PULLBOARD_TEST_SELECTION;// This is an inner file limit; the real machine gate/browser lease remains unchanged.env.PULLBOARD_TEST_BROWSER_RESOURCE = 'test-browser-files:' + randomUUID();env.PULLBOARD_TEST_BROWSER_CAPACITY = String(concurrency.browser);@@ -1415,7 +1433,7 @@ async function executeTests(args, sandbox, gateMarkers, fullSuite, concurrency)? await runLandingTests(selectedArgs, env, concurrency): runTests(selectedArgs, env, concurrency);if (result.error) throw result.error;- return result;+ return selectedTestResult(result, env.PULLBOARD_TEST_SELECTION, patterns, explicitTestFiles(selectedArgs));}/**diff --git a/src/test-selection.js b/src/test-selection.jsnew file mode 100644index 00000000..c9f0c35f--- /dev/null+++ b/src/test-selection.js@@ -0,0 +1,39 @@+/** Count selected native cases independently of the caller's public reporter [C7,S13]. */+import {+ readFileSync,+ writeFileSync,+} from 'node:fs';++/** Read the same name-pattern spellings the ordinary runner accepts. */+export function testSelectionPatterns(args) {+ const patterns = [];+ for (let index = 0; index < args.length && args[index] !== '--'; index++) {+ if (!/^--test[-_]name[-_]pattern(?:=|$)/u.test(args[index])) continue;+ const value = args[index].includes('=') ? args[index].slice(args[index].indexOf('=') + 1) : args[++index];+ if (value !== undefined) patterns.push(value);+ }+ return patterns;+}++/** A successful Node process cannot turn missing native selection evidence into a green check. */+export function selectedTestResult(result, record, patterns, files) {+ if (result.status !== 0 || !patterns.length) return result;+ let cases = 0;+ try { cases = JSON.parse(readFileSync(record, 'utf8')).cases; }+ catch { /* A missing or malformed internal reporter result fails closed. */ }+ if (Number.isSafeInteger(cases) && cases > 0) return result;+ process.stderr.write(`run-tests: NO_TESTS_MATCHED: patterns ${JSON.stringify(patterns)} selected no proven test case in ${JSON.stringify(files)}\n`);+ return { ...result, status: 1 };+}++/** Only child-file summaries contain native case counts; the parent aggregate includes file wrappers. */+export default async function* recordSelectedTests(events) {+ let cases = 0;+ for await (const event of events) {+ if (event.type !== 'test:summary' || !event.data.file) continue;+ const count = event.data.counts?.tests;+ if (!Number.isSafeInteger(count) || count < 0 || !Number.isSafeInteger(cases + count)) throw new Error('native selected-test counts are unavailable');+ cases += count;+ }+ writeFileSync(process.env.PULLBOARD_TEST_SELECTION, JSON.stringify({ cases }), { mode: 0o600 });+}