mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-17 05:41:50 +01:00
train S2: merge #3934 at 39b1c59bab v1.94.26.0
This commit is contained in:
commit
cc9df50170
10 files changed
+108
-25
No files matched your search
+34
-11
@@ -37,7 +37,9 @@
|
||||
* the tail is the stdout tail then the stderr tail, so a line's position says
|
||||
* nothing about when it was printed across streams, and bun's own counts (on
|
||||
* stderr) would otherwise outrank a 10k-test run whichever of the two ran
|
||||
* first. Any summary when it did not speak follows the last-summary-wins rule;
|
||||
* first. Any summary when it did not speak follows the last-summary-wins rule,
|
||||
* except that a complete set of `bun test --shard=i/N` processes ending the log
|
||||
* is summed (GBEV-3);
|
||||
* anything else is "unknown".
|
||||
* Three states, never merged:
|
||||
* a count, 0 (ZERO-RUN, graded like STALE by `check`) and unknown (non-blocking).
|
||||
@@ -146,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,7 +186,10 @@ 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. Bun always prints that counts block (" 0 pass" / " 0 fail"
|
||||
* " 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 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:
|
||||
@@ -189,7 +206,9 @@ async function bunTestsRan(lines: string[]): Promise<{ at: number; ran: number }
|
||||
} catch {
|
||||
warn("shard-engine classifier not importable; using the built-in bun summary parser");
|
||||
}
|
||||
for (let i = lines.length - 1; i >= 0; i--) {
|
||||
const blocks: { at: number; ran: number; shard?: string }[] = [];
|
||||
let since = 0;
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
if (!isTerminal(lines[i])) continue;
|
||||
let pass: number | null = null;
|
||||
let fail = 0;
|
||||
@@ -200,13 +219,17 @@ async function bunTestsRan(lines: string[]): Promise<{ at: number; ran: number }
|
||||
if (p) pass = Number(p[1]);
|
||||
if (f) fail = Number(f[1]);
|
||||
}
|
||||
if (pass === null) {
|
||||
if (/^Ran 0 tests? across/.test(lines[i])) return { at: i, ran: 0 };
|
||||
continue;
|
||||
}
|
||||
return { at: i, ran: pass + fail };
|
||||
const shard = lines.slice(since, i).map((l) => /^--shard=(\d+\/\d+): running /.exec(l)?.[1]).findLast(Boolean);
|
||||
since = i + 1;
|
||||
if (pass !== null) blocks.push({ at: i, ran: pass + fail, shard });
|
||||
else if (/^Ran 0 tests? across/.test(lines[i])) blocks.push({ at: i, ran: 0 });
|
||||
}
|
||||
return null;
|
||||
const last = blocks.at(-1);
|
||||
if (!last) return null;
|
||||
const total = Number(last.shard?.split("/")[1] ?? 1);
|
||||
const set = blocks.slice(-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 };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user