Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve failure diagnostics when test runs stop early (#8699)
[._.]/ Adam Eivy93563a1b9a6b
diff --git a/scripts/run-ci-tests.js b/scripts/run-ci-tests.jsindex 646081714f..b8919cea3b 100644--- a/scripts/run-ci-tests.js+++ b/scripts/run-ci-tests.js@@ -1,6 +1,8 @@#!/usr/bin/env nodeimport { spawn } from 'child_process';+import { mkdtempSync, readFileSync, statSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';import { stripVTControlCharacters } from 'node:util';import { dirname, join } from 'path';import { fileURLToPath } from 'url';@@ -128,6 +130,42 @@ export function recordVitestDuration(scope, label, startedAt) {writeStepSummary(line);}+/**+ * Recover diagnostics independently of the terminal reporter. Bound both the+ * input and rendered output; diagnostic failures never change the exit status.+ */+export function structuredFailureDiagnostics(reportPath) {+ try {+ if (statSync(reportPath).size > 32 * 1024 * 1024) throw new Error('report exceeds 32 MiB');+ const report = JSON.parse(readFileSync(reportPath, 'utf8'));+ if (!Array.isArray(report?.testResults)) throw new Error('invalid report schema');+ const lines = [];+ for (const suite of report.testResults) {+ if (typeof suite?.name !== 'string' || !Array.isArray(suite.assertionResults)) {+ throw new Error('invalid suite schema');+ }+ for (const assertion of suite.assertionResults) {+ if (assertion.status !== 'failed') continue;+ if (typeof assertion.fullName !== 'string' || !Array.isArray(assertion.failureMessages)+ || !assertion.failureMessages.every(message => typeof message === 'string')) {+ throw new Error('invalid assertion schema');+ }+ lines.push(`FAIL ${suite.name} > ${assertion.fullName}\n${assertion.failureMessages.join('\n')}`.slice(0, 8000));+ if (lines.length === 10) break;+ }+ if (suite.status === 'failed' && suite.message) {+ lines.push(`FAIL ${suite.name}\n${String(suite.message)}`.slice(0, 8000));+ }+ if (lines.length >= 10) break;+ }+ return lines.length+ ? `Structured Vitest failure diagnostics (up to 10 failures):\n${lines.slice(0, 10).join('\n')}`+ : 'Inconclusive Vitest diagnostics: structured report contains no failed assertion or suite message.';+ } catch {+ return 'Inconclusive Vitest diagnostics: structured report is missing, malformed, or exceeds 32 MiB.';+ }+}+/*** Run `npm run <script> --prefix <scope> [-- extraArgs]`, streaming stdout and* stderr live (so a long CI job keeps showing progress) while also retaining@@ -135,9 +173,19 @@ export function recordVitestDuration(scope, label, startedAt) {** @returns {Promise<{status: number, output: string, error?: Error}>}*/-function runNpm(scope, script, extraArgs) {+export async function runNpm(scope, script, extraArgs) {+ const reportDir = mkdtempSync(join(tmpdir(), 'portos-vitest-'));+ const reportPath = join(reportDir, 'failures.json');+ try {+ return await runNpmWithReport(scope, script, extraArgs, reportPath);+ } finally {+ rmSync(reportDir, { recursive: true, force: true });+ }+}++function runNpmWithReport(scope, script, extraArgs, reportPath) {const args = ['run', script, '--prefix', scope];- if (extraArgs.length > 0) args.push('--', ...extraArgs);+ args.push('--', ...extraArgs, '--reporter=json', `--outputFile.json=${reportPath}`);// Wrapped, not a bare `npm.cmd`: Node refuses to spawn a `.cmd` under// `shell:false` and throws EINVAL, so this script could never run on a// Windows checkout. See server/lib/bufferedSpawn.js.@@ -152,7 +200,10 @@ function runNpm(scope, script, extraArgs) {child.stdout.on('data', (chunk) => tee(process.stdout, chunk));child.stderr.on('data', (chunk) => tee(process.stderr, chunk));child.on('error', (error) => resolve({ status: 1, output, error }));- child.on('close', (code) => resolve({ status: code ?? 1, output }));+ child.on('close', (code) => {+ if (code !== 0) console.error(structuredFailureDiagnostics(reportPath));+ resolve({ status: code ?? 1, output });+ });});}diff --git a/scripts/run-ci-tests.test.js b/scripts/run-ci-tests.test.jsindex 2b46a42527..c0ed12ef37 100644--- a/scripts/run-ci-tests.test.js+++ b/scripts/run-ci-tests.test.js@@ -1,9 +1,11 @@-import { mkdtempSync, readFileSync, rmSync } from 'fs';+import { spawnSync } from 'node:child_process';+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';import { tmpdir } from 'os';import { join } from 'path';import { afterEach, describe, expect, it } from 'vitest';import {+ structuredFailureDiagnostics,extractCrashedTestFile,hasOtherTestFailures,planCrashRetry,@@ -246,3 +248,38 @@ describe('relatedInputs', () => {]);});});+++describe('structured failure diagnostics', () => {+ it('recovers a real bail failure with default and GitHub reporters even if their summary is incomplete', () => {+ const fixture = mkdtempSync(join(tmpdir(), 'portos-diagnostics-'));+ try {+ const report = join(fixture, 'report.json');+ writeFileSync(join(fixture, 'fixture.test.js'),+ "test('synthetic assertion diagnostic', () => { expect(1, 'synthetic mismatch').toBe(2); });");+ writeFileSync(join(fixture, 'vitest.config.mjs'),+ 'export default { test: { globals: true, maxWorkers: 1 } };');+ const runnerUrl = new URL('./run-ci-tests.js', import.meta.url).href;+ const args = ['--config', join(fixture, 'vitest.config.mjs'), '--root', fixture, './fixture.test.js'];+ const result = spawnSync(process.execPath, ['--input-type=module', '-e',+ `import { runNpm } from ${JSON.stringify(runnerUrl)};+ const result = await runNpm('server', 'test:ci:related', ${JSON.stringify(args)});+ process.exitCode = result.status;`,+ ], { encoding: 'utf8', timeout: 30_000, env: { ...process.env, NODE_ENV: 'test' } });+ expect(result.error).toBeUndefined();+ expect(result.status).toBe(1);+ // Inspect only the structured fallback, independent of terminal summaries.+ const diagnostic = result.stderr.slice(result.stderr.indexOf('Structured Vitest'));+ expect(diagnostic).toContain('fixture.test.js > synthetic assertion diagnostic');+ expect(diagnostic).toContain('synthetic mismatch');+ expect(diagnostic).toContain('Structured Vitest failure diagnostics');+ writeFileSync(report, '{');+ expect(structuredFailureDiagnostics(report)).toContain('Inconclusive');+ writeFileSync(report, JSON.stringify({ testResults: [] }));+ expect(structuredFailureDiagnostics(report)).toContain('Inconclusive');+ expect(structuredFailureDiagnostics(join(fixture, 'missing.json'))).toContain('Inconclusive');+ } finally {+ rmSync(fixture, { recursive: true, force: true });+ }+ }, 35_000);+});