From 255a8271352bf1a28f7acba932a49cdbe848b343 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Fri, 29 May 2026 16:32:25 +0900 Subject: [PATCH] feat(script): add bun test summary detector Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- script/assert-test-summary.test.ts | 42 ++++++++++++++++++++++++++++++ script/assert-test-summary.ts | 25 ++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 script/assert-test-summary.test.ts create mode 100644 script/assert-test-summary.ts diff --git a/script/assert-test-summary.test.ts b/script/assert-test-summary.test.ts new file mode 100644 index 000000000..9211aa2f1 --- /dev/null +++ b/script/assert-test-summary.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, test } from "bun:test" +import { hasBunTestSummary } from "./assert-test-summary" + +describe("bun test summary detection", () => { + test("#given completed bun test output #when checking for a summary #then it is accepted", () => { + // given + const output = `bun test v1.3.12 (700fc117) + + 28 pass + 0 fail +Ran 28 tests across 1 file. [64.00ms] +` + + // when + const hasSummary = hasBunTestSummary(output) + + // then + expect(hasSummary).toBe(true) + }) + + test("#given banner-only bun test output #when checking for a summary #then it is rejected", () => { + // given + const output = "bun test v1.3.12 (700fc117)\n" + + // when + const hasSummary = hasBunTestSummary(output) + + // then + expect(hasSummary).toBe(false) + }) + + test("#given zero-count summary output #when checking for a summary #then it is rejected", () => { + // given + const output = "Ran 0 tests across 0 files. [1.00ms]\n" + + // when + const hasSummary = hasBunTestSummary(output) + + // then + expect(hasSummary).toBe(false) + }) +}) diff --git a/script/assert-test-summary.ts b/script/assert-test-summary.ts new file mode 100644 index 000000000..b9a71cd7d --- /dev/null +++ b/script/assert-test-summary.ts @@ -0,0 +1,25 @@ +/// + +export const bunTestSummaryPattern = /^Ran [1-9][0-9]* tests across [1-9][0-9]* files?\./m + +export function hasBunTestSummary(output: string): boolean { + return bunTestSummaryPattern.test(output) +} + +async function assertTestSummaryFromLog(logPath: string): Promise { + const output = await Bun.file(logPath).text() + + if (!hasBunTestSummary(output)) { + throw new Error(`Missing bun test completion summary in ${logPath}`) + } +} + +if (import.meta.main) { + const [logPath] = process.argv.slice(2) + + if (!logPath) { + throw new Error("Usage: bun run script/assert-test-summary.ts ") + } + + await assertTestSummaryFromLog(logPath) +}