diff --git a/scripts/test-group-report.mjs b/scripts/test-group-report.mjs index 67a35b16d9ff..793fd540f107 100644 --- a/scripts/test-group-report.mjs +++ b/scripts/test-group-report.mjs @@ -414,6 +414,19 @@ function readReportInput(entry) { }; } +export function readReportInputs(entries) { + const missing = []; + const reports = []; + for (const entry of entries) { + if (!fs.existsSync(entry.reportPath)) { + missing.push(entry); + continue; + } + reports.push(readReportInput(entry)); + } + return { missing, reports }; +} + function readGroupedReport(reportPath) { return JSON.parse(fs.readFileSync(reportPath, "utf8")); } @@ -666,9 +679,16 @@ async function main() { process.exit(exitCode); } - const reportInputs = runEntries - .filter((entry) => fs.existsSync(entry.reportPath)) - .map(readReportInput); + const reportInputsResult = readReportInputs(runEntries); + if (reportInputsResult.missing.length > 0) { + for (const entry of reportInputsResult.missing) { + console.error( + `[test-group-report] missing JSON report for ${entry.config}: ${entry.reportPath}`, + ); + } + process.exit(1); + } + const reportInputs = reportInputsResult.reports; const report = buildGroupedTestReport({ groupBy: args.groupBy, maxTestMs: args.maxTestMs, diff --git a/test/scripts/test-group-report.test.ts b/test/scripts/test-group-report.test.ts index c6084bad75fd..2ebb0be88422 100644 --- a/test/scripts/test-group-report.test.ts +++ b/test/scripts/test-group-report.test.ts @@ -1,4 +1,5 @@ // Test Group Report tests cover test group report script behavior. +import { spawnSync } from "node:child_process"; import fs from "node:fs"; import os from "node:os"; import path from "node:path"; @@ -94,6 +95,28 @@ describe("scripts/test-group-report aggregation", () => { }, ]); }); + + it("fails missing report inputs instead of writing an empty green report", () => { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-test-group-report-")); + const missingReport = path.join(tempDir, "missing.json"); + const output = path.join(tempDir, "group-report.json"); + try { + const result = spawnSync( + process.execPath, + ["scripts/test-group-report.mjs", "--report", missingReport, "--output", output], + { + cwd: process.cwd(), + encoding: "utf8", + }, + ); + + expect(result.status).toBe(1); + expect(result.stderr).toContain(`[test-group-report] missing JSON report for missing`); + expect(fs.existsSync(output)).toBe(false); + } finally { + fs.rmSync(tempDir, { recursive: true, force: true }); + } + }); }); describe("scripts/test-group-report comparison", () => {