Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(ci): record nextest elapsed time in coverage report

Steven Enamakel293d498503ef
diff --git a/scripts/ci/nextest-coverage.sh b/scripts/ci/nextest-coverage.sh
index f78b2eb6f4..fd6fe62dad 100644
--- a/scripts/ci/nextest-coverage.sh
+++ b/scripts/ci/nextest-coverage.sh
@@ -22,10 +22,11 @@ for arg in "$@"; do
args+=("$arg")
if [ "$arg" = nextest ]; then args+=(--config-file "$config"); fi
done
+started=$SECONDS
rc=0
bash scripts/ci-cancel-aware.sh "${args[@]}" || rc=$?
report_rc=0
-node scripts/ci/nextest-report.mjs "$report" "${report_dir}/${suite}.json" ${NEXTEST_EXPECTED_TARGETS:+"${NEXTEST_EXPECTED_TARGETS}"} || report_rc=$?
+NEXTEST_ELAPSED_SECONDS="$((SECONDS - started))" node scripts/ci/nextest-report.mjs "$report" "${report_dir}/${suite}.json" ${NEXTEST_EXPECTED_TARGETS:+"${NEXTEST_EXPECTED_TARGETS}"} || report_rc=$?
# A report/inventory failure must not hide the test runner's actual failure or
# cancellation. Successful executions must also produce nonempty reports.
[ "$rc" != 0 ] || rc="$report_rc"
diff --git a/scripts/ci/nextest-report.mjs b/scripts/ci/nextest-report.mjs
index c05d97dc60..634ff804e0 100644
--- a/scripts/ci/nextest-report.mjs
+++ b/scripts/ci/nextest-report.mjs
@@ -4,18 +4,57 @@ import fs from "node:fs";
const [report, output, expectedFile] = process.argv.slice(2);
const xml = fs.readFileSync(report, "utf8");
-const decode = (value) => value.replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
+const decode = (value) =>
+ value
+ .replace(/&quot;/g, '"')
+ .replace(/&apos;/g, "'")
+ .replace(/&lt;/g, "<")
+ .replace(/&gt;/g, ">")
+ .replace(/&amp;/g, "&");
const suites = [...xml.matchAll(/<testsuite\s+([^>]+)>/g)].map((match) => {
- const attributes = Object.fromEntries([...match[1].matchAll(/([\w-]+)="([^"]*)"/g)].map((entry) => [entry[1], decode(entry[2])]));
- return { name: attributes.name, tests: Number(attributes.tests ?? 0), failures: Number(attributes.failures ?? 0), errors: Number(attributes.errors ?? 0), skipped: Number(attributes.skipped ?? 0) };
+ const attributes = Object.fromEntries(
+ [...match[1].matchAll(/([\w-]+)="([^"]*)"/g)].map((entry) => [
+ entry[1],
+ decode(entry[2]),
+ ]),
+ );
+ return {
+ name: attributes.name,
+ tests: Number(attributes.tests ?? 0),
+ failures: Number(attributes.failures ?? 0),
+ errors: Number(attributes.errors ?? 0),
+ skipped: Number(attributes.skipped ?? 0),
+ };
});
-const counts = { tests: 0, failures: 0, errors: 0, skipped: 0, suites };
-for (const suite of suites) for (const key of ["tests", "failures", "errors", "skipped"]) counts[key] += suite[key];
+const counts = {
+ elapsedSeconds: Number(process.env.NEXTEST_ELAPSED_SECONDS ?? 0),
+ tests: 0,
+ failures: 0,
+ errors: 0,
+ skipped: 0,
+ suites,
+};
+for (const suite of suites)
+ for (const key of ["tests", "failures", "errors", "skipped"])
+ counts[key] += suite[key];
fs.writeFileSync(output, `${JSON.stringify(counts, null, 2)}\n`);
-console.log(`[ci][nextest] ${report}: ${counts.tests} tests, ${counts.failures} failures, ${counts.errors} errors, ${counts.skipped} skipped`);
-const expected = expectedFile ? fs.readFileSync(expectedFile, "utf8").split(/\r?\n/).filter(Boolean) : [];
-const missing = expected.filter((target) => !suites.some((suite) => (suite.name === target || suite.name?.endsWith(`::${target}`)) && suite.tests > 0));
+console.log(
+ `[ci][nextest] ${report}: ${counts.tests} tests, ${counts.failures} failures, ${counts.errors} errors, ${counts.skipped} skipped`,
+);
+const expected = expectedFile
+ ? fs.readFileSync(expectedFile, "utf8").split(/\r?\n/).filter(Boolean)
+ : [];
+const missing = expected.filter(
+ (target) =>
+ !suites.some(
+ (suite) =>
+ (suite.name === target || suite.name?.endsWith(`::${target}`)) &&
+ suite.tests > 0,
+ ),
+);
if (counts.tests === 0 || missing.length > 0) {
- console.error(`[ci][nextest] expected nonempty suites; missing/empty: ${missing.join(", ") || "entire selection"}`);
+ console.error(
+ `[ci][nextest] expected nonempty suites; missing/empty: ${missing.join(", ") || "entire selection"}`,
+ );
process.exitCode = 1;
}