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(submit): read Node 24 failure locations [V1]

Corey Olsonc6cf070ec55a
diff --git a/src/cli.js b/src/cli.js
index a5037c6a..3eaa98a4 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1711,7 +1711,7 @@ async function submitHere(ctx, id) {
if (!gate.isGreen) {
const message = `the submission proof is red at ${commit.slice(0, 12)}; fix it, commit, submit again. ${submitGateReport(gate)}`;
let comparison = { main: null, files: [], unavailable: 'main comparison could not be completed' };
- try { comparison = await compareMainFailures(root, gate.profile, gateWaitReporter(ctx.io)); } catch { /* Keep the original gate refusal if main evidence is unavailable. */ }
+ try { comparison = await compareMainFailures(root, gate.profile, gateWaitReporter(ctx.io), gate.output); } catch { /* Keep the original gate refusal if main evidence is unavailable. */ }
const mainNote = withBoard(ctx, board => mainRedMessage(root, board, gate.profile, comparison));
throw new Refused('GATE_RED', `${message}${mainNote ? `\n${mainNote}` : ''}`);
}
diff --git a/src/main-red.js b/src/main-red.js
index 10de4eac..9913327f 100644
--- a/src/main-red.js
+++ b/src/main-red.js
@@ -4,6 +4,8 @@ import { randomUUID } from 'node:crypto';
import { lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
import { join, relative, resolve, sep } from 'node:path';
import { tmpdir } from 'node:os';
+import { stripVTControlCharacters } from 'node:util';
+import { fileURLToPath } from 'node:url';
import { runProfiledShell, withGateSlot } from './gate.js';
import { cleanGitEnvironment, mainCheckout } from './git.js';
import { mainPolicy, policyAt } from './trusted-policy.js';
@@ -22,14 +24,17 @@ function shellWord(value) {
/** Resolve one test filename from runner output to a safe repository-relative path. */
function testPath(root, value) {
if (typeof value !== 'string' || !value) return null;
+ if (value.startsWith('file:')) {
+ try { value = fileURLToPath(value); } catch { return null; }
+ }
const absolute = resolve(root, value);
const path = relative(root, absolute);
if (!path || path === '..' || path.startsWith(`..${sep}`) || path.startsWith(sep)) return null;
return path.split(sep).join('/');
}
-/** Unique failed test files actually named by the runner profile. */
-function failingFiles(root, profile) {
+/** Unique failed files named by TAP/JUnit metadata or Node's native spec failure footer. */
+function failingFiles(root, profile, output) {
const files = new Set();
for (const test of profile?.tests ?? []) if (test.passed === false) {
const path = testPath(root, test.file);
@@ -43,6 +48,15 @@ function failingFiles(root, profile) {
if (path) files.add(path);
}
}
+ let specFailures = false;
+ for (const raw of String(output ?? '').split(/\r?\n/u)) {
+ const line = stripVTControlCharacters(raw).trim();
+ if (line === '✖ failing tests:') specFailures = true;
+ if (!specFailures) continue;
+ const location = /^test at (.+):\d+:\d+$/u.exec(line);
+ const path = location && testPath(root, location[1]);
+ if (path) files.add(path);
+ }
return [...files].sort();
}
@@ -126,17 +140,18 @@ function withMainCheckout(root, commit, run) {
* @param {string} root
* @param {object} profile
* @param {(state:object)=>void} [onWait]
+ * @param {string} [output] - The failed phase's unchanged reporter output.
* @returns {Promise<{ main: string|null, files: Array<{file:string,result:'red'|'green'}>, unavailable?: string }>}
*/
-export async function compareMainFailures(root, profile, onWait) {
+export async function compareMainFailures(root, profile, onWait, output = '') {
const main = mainCheckout(root);
if (!main?.commit) return { main: null, files: [], unavailable: 'the primary checkout has no committed main snapshot' };
const policy = policyAt(root, main.commit);
if (typeof policy.config.affectedTests !== 'string' || !policy.config.affectedTests.trim()) {
return { main: main.commit, files: [], unavailable: 'no focused test runner configured' };
}
- const files = failingFiles(root, profile);
- if (!files.length) return { main: main.commit, files: [], unavailable: 'the runner did not name failed test files' };
+ const files = failingFiles(root, profile, output);
+ if (!files.length) return { main: main.commit, files: [], unavailable: 'could not read which tests failed' };
const file = cacheFile(root);
const cacheLease = await takeResource({
name: 'main-red-cache', capacity: 1, scope: 'repo', root,
@@ -186,6 +201,9 @@ export function mainRedMessage(root, board, profile, comparison) {
if (comparison.unavailable === 'no focused test runner configured') {
return 'main not checked: no focused test runner configured (affectedTests)';
}
+ if (comparison.unavailable === 'could not read which tests failed') {
+ return 'main not checked: could not read which tests failed';
+ }
if (!comparison.files.length) return '';
const attribution = mainRedAttribution(root, board, comparison);
const names = (profile?.tests ?? []).filter(test => test.passed === false)
diff --git a/test/main-red.test.js b/test/main-red.test.js
index 0328dc0d..1e27c0de 100644
--- a/test/main-red.test.js
+++ b/test/main-red.test.js
@@ -37,7 +37,7 @@ function commit(root, env, subject = 'chore: fixture state') {
function shellWord(value) { return "'" + String(value).replaceAll("'", "'\\''") + "'"; }
/** Create a private real-Git board with a selected native Node test command. */
-function fixture(t, { spec, source, affectedTests = 'node test/runner.js' }) {
+function fixture(t, { spec, source, affectedTests = 'node test/runner.js', reporter }) {
const directory = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-main-red-')));
roots.push(directory);
t.after(() => rmSync(directory, { recursive: true, force: true }));
@@ -73,7 +73,7 @@ function fixture(t, { spec, source, affectedTests = 'node test/runner.js' }) {
"import { spawnSync } from 'node:child_process';",
"if (process.env.MAIN_RED_RUNS) appendFileSync(process.env.MAIN_RED_RUNS, `${process.cwd()}\\n`);",
"const files = process.argv.slice(2).length ? process.argv.slice(2) : ['test/inherited.test.js'];",
- "const result = spawnSync(process.execPath, ['--test', ...files], { cwd: process.cwd(), env: process.env, encoding: 'utf8' });",
+ `const result = spawnSync(process.execPath, ['--test', ...${JSON.stringify(reporter ? [`--test-reporter=${reporter}`] : [])}, ...files], { cwd: process.cwd(), env: process.env, encoding: 'utf8' });`,
"if (result.stdout) process.stdout.write(result.stdout);",
"if (result.stderr) process.stderr.write(result.stderr);",
'process.exitCode = result.status ?? 1;',
@@ -128,6 +128,51 @@ const FAILING_TEST = [
"test('the inherited behavior remains broken [V1]', () => assert.equal(1, 2));",
].join('\n') + '\n';
+test('an inherited red reads native spec reporter failure locations [V1]', t => {
+ const box = fixture(t, { spec: RED_SPEC, source: FAILING_TEST, reporter: 'spec' });
+ delete box.env.NO_COLOR;
+ box.env.FORCE_COLOR = '1';
+ const [rework, submitItem] = addItems(box, [
+ { title: 'Repair spec-reported failure', specId: 'G1' },
+ { title: 'Unrelated submit', specId: 'G2' },
+ ]);
+ const submitter = builder(box);
+ assert.equal(submitter.run('claim', String(submitItem)).code, 0);
+ put(submitter.root, 'test/inherited.test.js', `${FAILING_TEST}// candidate-only comment\n`);
+ commit(submitter.root, box.env, 'test(core): select spec-reported red [G2]');
+ const red = submitter.run('submit', String(submitItem));
+ inheritedMessage(red, { row: 'G1', item: rework });
+ assert.equal(readFileSync(box.env.MAIN_RED_RUNS, 'utf8').trim().split('\n').length, 2,
+ 'the unchanged spec reporter command runs once on the candidate and once on exact main');
+});
+
+test('a red with unreadable failure files says why main was not checked [V1]', t => {
+ const box = fixture(t, { spec: RED_SPEC, source: FAILING_TEST });
+ put(box.root, 'test/runner.js', [
+ "import { appendFileSync } from 'node:fs';",
+ "appendFileSync(process.env.MAIN_RED_RUNS, `${process.cwd()}\\n`);",
+ "console.error('A runner failed without a failure-file report.');",
+ "console.error('test at test/inherited.test.js:3:1');",
+ 'process.exitCode = 1;',
+ ].join('\n') + '\n');
+ commit(box.root, box.env);
+ const [, submitItem] = addItems(box, [
+ { title: 'Repair unknown runner failure', specId: 'G1' },
+ { title: 'Unrelated submit', specId: 'G2' },
+ ]);
+ const submitter = builder(box);
+ assert.equal(submitter.run('claim', String(submitItem)).code, 0);
+ put(submitter.root, 'test/inherited.test.js', `${FAILING_TEST}// candidate-only comment\n`);
+ commit(submitter.root, box.env, 'test(core): select unreadable runner red [G2]');
+ const red = submitter.run('submit', String(submitItem));
+ assert.equal(red.code, 1, red.out || red.err);
+ assert.match(red.err, /\[GATE_RED\]/u);
+ assert.match(red.err, /main not checked: could not read which tests failed/u);
+ assert.doesNotMatch(red.err, /also red on main|inherited main red/u);
+ assert.equal(readFileSync(box.env.MAIN_RED_RUNS, 'utf8').trim().split('\n').length, 1,
+ 'a location outside the spec reporter failure footer is not guessed to be a failed file');
+});
+
test('an inherited red names the rework that owns it [V1]', async (t) => {
await t.test('a prioritized rework already first in its tier stays first [V1]', (sub) => {
const box = fixture(sub, { spec: RED_SPEC, source: FAILING_TEST });