diff --git a/bin/gstack-evidence b/bin/gstack-evidence index 49af08f54..ed83da0be 100755 --- a/bin/gstack-evidence +++ b/bin/gstack-evidence @@ -148,18 +148,30 @@ const TAIL_MAX_BYTES = 64 * 1024; * Ring of the last TAIL_MAX_BYTES of each child stream, kept per stream: the * pumps interleave by arrival, so a stderr summary read while stdout still has * pipe-buffered bytes behind it would otherwise be pushed out of a shared ring. + * Lines leaving the ring that bun's shard sum reads (a "--shard=i/N: running" + * line, " N pass", " N fail", "Ran N tests across") are kept in order ahead of + * the tail, so every shard of a long sharded run still counts (GBEV-3). */ class OutputTail { private readonly decoders = { stdout: new TextDecoder("utf-8"), stderr: new TextDecoder("utf-8") }; private readonly text = { stdout: "", stderr: "" }; + private readonly kept = { stdout: [] as string[], stderr: [] as string[] }; + private trim(origin: "stdout" | "stderr", text: string): string { + const cut = text.lastIndexOf("\n", text.length - TAIL_MAX_BYTES); + if (cut < 0) return text.slice(-TAIL_MAX_BYTES); + const lines = text.slice(0, cut).split("\n").filter((l) => /^(?:--shard=\d+\/\d+: running |\s*\d+ (?:pass|fail)\s*$|Ran \d+ tests? across )/.test(strip(l))); + this.kept[origin] = [...this.kept[origin], ...lines].slice(-4096); + return text.slice(cut + 1); + } push(chunk: Uint8Array, origin: "stdout" | "stderr"): void { this.text[origin] += this.decoders[origin].decode(chunk, { stream: true }); - if (this.text[origin].length > TAIL_MAX_BYTES * 2) this.text[origin] = this.text[origin].slice(-TAIL_MAX_BYTES); + if (this.text[origin].length > TAIL_MAX_BYTES * 2) this.text[origin] = this.trim(origin, this.text[origin]); } end(): string { const tails = (["stdout", "stderr"] as const).map((origin) => { const text = this.text[origin] + this.decoders[origin].decode(); - return text.length > TAIL_MAX_BYTES ? text.slice(-TAIL_MAX_BYTES) : text; + const tail = text.length > TAIL_MAX_BYTES ? this.trim(origin, text) : text; + return [...this.kept[origin], tail].join("\n"); }); return tails.join("\n"); } @@ -172,9 +184,9 @@ const count = (text: string, word: string): number => Number(new RegExp(`(\\d+) /** * Bun: the last "Ran N tests across M files" block; executed = its " N pass" + * " N fail" lines. When that block ends a `bun test --shard=i/N` process (bun's - * "--shard=i/N: running" line since the previous block), the blocks of the N - * distinct shards that end the log are summed (a sharded runner prints every - * shard, GBEV-3); an incomplete or repeated shard set counts the last block alone. Bun always prints that counts block (" 0 pass" / " 0 fail" + * "--shard=i/N: running" line since the previous block), the blocks of shards + * 1/N to N/N, in that order, that end the log are summed (a sharded runner prints + * every shard, GBEV-3); any other shard set counts the last block alone. Bun always prints that counts block (" 0 pass" / " 0 fail" * even for an all-skip or empty run), so a terminal line with no " N pass" * above it is a line gstack's quiet shard runner forwarded (it forwards the * terminal line without the " N pass" line), not a bun summary: @@ -213,7 +225,7 @@ async function bunTestsRan(lines: string[]): Promise<{ at: number; ran: number } if (!last) return null; const total = Number(last.shard?.split("/")[1] ?? 1); const set = blocks.slice(-total); - const complete = total > 1 && set.length === total && new Set(set.map((b) => b.shard)).size === total && set.every((b) => b.shard?.endsWith(`/${total}`)); + const complete = total > 1 && set.length === total && set.every((b, k) => b.shard === `${k + 1}/${total}`); return { at: last.at, ran: complete ? set.reduce((n, b) => n + b.ran, 0) : last.ran }; } diff --git a/changelog.d/gsta258-l6-carry-followup.md b/changelog.d/gsta258-l6-carry-followup.md index 68fdcc712..8270a7ada 100644 --- a/changelog.d/gsta258-l6-carry-followup.md +++ b/changelog.d/gsta258-l6-carry-followup.md @@ -1,6 +1,6 @@ -- A lane whose command runs several `bun test --shard=i/N` processes now records the sum of the shards' counts, not the last shard's (GBEV-3, gbrain-evals#317: 3336 recorded against 6,095 run across 2 shards). The sum needs one block from each of the N distinct shards at the end of the log; an incomplete or repeated set records the last summary as before, so a command that runs a suite twice still reports its last run. +- A lane whose command runs several `bun test --shard=i/N` processes now records the sum of the shards' counts, not the last shard's (GBEV-3, gbrain-evals#317: 3336 recorded against 6,095 run across 2 shards). The sum needs shards 1/N to N/N, in order, at the end of the log; any other set records the last summary as before, so a command that runs a suite twice, or reruns one shard, still reports its last run. The shard lines and count lines that scroll out of the 64 KiB output tail are kept for this, so a long shard run still sums (a real 2-shard, 2000-test bun run recorded 1000 before and 2000 after). - docs/pregate.md#dispatch-carry warns that a `workflow_dispatch` run reports under the same job names on the head commit, so without strict branch protection a green dispatch run can hide a red merge-commit check. It recommends strict protection or distinct job names for dispatch runs, and notes that gstack's own merge trains test the merged tree. - docs/pregate.md#skipped-files names the order of record-ci's checks after a skipped-file remainder, including the final `tree_changed` recheck. ### Tests -- `test/evidence.test.ts`: two `--shard=i/2` processes in one log record 6095, and an incomplete or repeated shard set records the last summary. The sum case fails without the change (it recorded 3336). +- `test/evidence.test.ts`: two `--shard=i/2` processes in one log record 6095, two shards with more than 64 KiB of per-test lines record 4000, and an incomplete, repeated or rerun shard set records the last summary. The sum cases fail without the change (3336 and 2000). diff --git a/docs/pregate.md b/docs/pregate.md index b3e78f48b..b138aeb2c 100644 --- a/docs/pregate.md +++ b/docs/pregate.md @@ -1021,9 +1021,9 @@ obligations still clear with `gstack-pregate clear --remote --run-url **A dispatched run can hide a red merge commit.** A `workflow_dispatch` run reports its checks on the head commit under the same -job names as the `pull_request` run, and GitHub counts the newest check of a -name. So a green dispatch run of HEAD's own tree can satisfy a required check -whose `pull_request` run failed on the merge commit, and without strict branch +job names as the `pull_request` run. So a green dispatch run of HEAD's own tree +can stand in for a required check whose `pull_request` run failed on the merge +commit, and without strict branch protection ("Require branches to be up to date before merging") the pull request can merge with that failure hidden (GBEV-3). Turn on strict protection for the base branch, or give dispatch runs distinct job names (for example a diff --git a/test/evidence.test.ts b/test/evidence.test.ts index 42c8c9206..4497f6a81 100644 --- a/test/evidence.test.ts +++ b/test/evidence.test.ts @@ -506,6 +506,11 @@ describe('gstack-evidence tests_ran — zero-run green is a third state, never m expect(records().pop().tests_ran).toBe(3336); run(['run', '--label', 'tests', '--', log('again.out', shard(2, 9, 0) + shard(2, 3336, 18))]); expect(records().pop().tests_ran).toBe(3336); + run(['run', '--label', 'tests', '--', log('rerun.out', shard(1, 2759, 20) + shard(2, 3336, 18) + shard(1, 4, 0))]); + expect(records().pop().tests_ran).toBe(4); + const big = (i: number) => `bun test v1\n--shard=${i}/2: running 20/40 test files\n` + Array.from({ length: 2000 }, (_, k) => `(pass) case ${k} padded test name for size [0.01ms]`).join('\n') + '\n\n 2000 pass\n 0 fail\nRan 2000 tests across 20 files. [10.00ms]\n'; + run(['run', '--label', 'tests', '--', log('big.out', big(1) + big(2))]); + expect(records().pop().tests_ran).toBe(4000); }); test('an unrecognised runner is unknown: non-blocking, labelled in the detail', () => {