Public: anyone can read this; the crew can change it.
A check's log says each step's time, and each part of the check step its own #17543
Merged 11h 52m ago, live in production
step-times → main 0 commits
10 files
changed +117
−3
scripts/design-drift.ts +2
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | import { existsSync, readFileSync, writeFileSync } from "node:fs"; |
| 19 | 19 | import { join, relative } from "node:path"; |
| 20 | 20 | import { sourceFiles } from "./design-lint.ts"; |
| 21 | import { sayTook } from "./took.ts"; | |
| 21 | 22 | |
| 22 | 23 | export type Duplicate = { file: string; line: number; cls: string; part: string }; |
| 23 | 24 | |
| @@ -78,6 +79,7 @@ export function report(found: readonly Duplicate[]): string { | ||
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | if (import.meta.main) { |
| 82 | sayTook("design-drift"); | |
| 81 | 83 | const root = process.cwd(); |
| 82 | 84 | const found = drift(root); |
| 83 | 85 | console.log(report(found)); |
scripts/gate.ts +5
| @@ -1076,6 +1076,11 @@ export function refusedSummary(refused: readonly string[]): string { | ||
| 1076 | 1076 | // `--fix` first rewraps the over-long comment lines of the files this pull changes (`--all`: of |
| 1077 | 1077 | // every file), then runs the same audit. |
| 1078 | 1078 | if (import.meta.main) { |
| 1079 | // What it took, on stderr as it ends (`took.ts` says why). Written here, not imported: the base's | |
| 1080 | // gate runs alone beside a pull's tree, and must not need a file the pull may not have. | |
| 1081 | // The base's own run (`--base-only`) is quiet unless it refuses, so it says nothing here. | |
| 1082 | if (!process.argv.includes("--base-only")) | |
| 1083 | process.on("exit", () => process.stderr.write(`gate: took ${(performance.now() / 1000).toFixed(1)}s\n`)); | |
| 1079 | 1084 | if (process.argv.includes("--fix")) { |
| 1080 | 1085 | const fixed = wrapFix(".", process.argv.includes("--all")); |
| 1081 | 1086 | if (fixed.length) console.error(`gate: rewrapped comments in ${fixed.length === 1 ? "1 file" : `${fixed.length} files`}; commit them`); |
scripts/test-shards.ts +2
| @@ -135,6 +135,7 @@ import { GATE_STEP_FILE, readGateStep, type Step } from "./step-times.ts"; | ||
| 135 | 135 | import { GATE_FILE, LOADS_ONLY, coverOf, executedFiles, formatImpact, gateListAdds, handedImpact, mergeImpact, packImpact, usedFiles, type Cover } from "../src/checks/impact.ts"; |
| 136 | 136 | import { importsReader, readImpact, scansIn } from "./tier-input.ts"; |
| 137 | 137 | import { changedLine, startChanged } from "./changed-pick.ts"; |
| 138 | import { sayTook } from "./took.ts"; | |
| 138 | 139 | import { ownTests, skipReport } from "../src/checks/own_skips.ts"; |
| 139 | 140 | import { docReadersIn, readersIn } from "./script-readers.ts"; |
| 140 | 141 | import { shardHome, spaceLine } from "../src/checks/disk_full.ts"; |
| @@ -167,6 +168,7 @@ const CACHED_TIMES = `${CHECK_CACHE}/test-times.json`; | ||
| 167 | 168 | // Beside it, each test's time from the same run (#1242). |
| 168 | 169 | const CACHED_TEST_TIMES = `${CHECK_CACHE}/test-times-tests.json`; |
| 169 | 170 | |
| 171 | if (import.meta.main) sayTook("test-shards"); | |
| 170 | 172 | const argv = process.argv.slice(2); |
| 171 | 173 | const record = argv.includes("--record"); |
| 172 | 174 | const gate = argv.includes("--gate"); |
scripts/took.ts added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | /** | |
| 2 | * One line when a script of the check ends: how long it ran, from its process's start (#16876). | |
| 3 | * The runner says each step's whole time (`runner: check took 52.3s`); these say the parts of | |
| 4 | * the check step (the gate, the design drift, the test run), and what is left of the step is the | |
| 5 | * type check between them. On stderr, so nothing that reads a script's stdout sees it. The shape | |
| 6 | * is `src/checks/took_line.ts`'s. | |
| 7 | */ | |
| 8 | import { tookLine } from "../src/checks/took_line.ts"; | |
| 9 | ||
| 10 | export function sayTook(name: string): void { | |
| 11 | process.on("exit", () => { | |
| 12 | process.stderr.write(`${tookLine(name, performance.now() / 1000)}\n`); | |
| 13 | }); | |
| 14 | } |
src/checks/summary.ts +5 −3
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * the run's log, and never a guess at *why* a test failed. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { STEP_TOOK_LINE, TOOK_LINE } from "./took_line.ts"; | |
| 10 | 11 | import type { CheckDetail, Run } from "../core/runs.ts"; |
| 11 | 12 | import { parseBunTestFailure } from "./bun-test.ts"; |
| 12 | 13 | import { fullShard, OUT_OF_ROOM, TEMP_FULL } from "./disk_full.ts"; |
| @@ -29,11 +30,12 @@ const UNNAMED_SHARD = | ||
| 29 | 30 | |
| 30 | 31 | /** |
| 31 | 32 | * The lines `scripts/test-shards.ts` prints after the tally about the records |
| 32 | * it kept (times, impacts, kept green results): bookkeeping, never why the | |
| 33 | * check is red (#12940). | |
| 33 | * it kept (times, impacts, kept green results), and the `took` line each step and script says | |
| 34 | * as it ends (#16876): bookkeeping, never why the check is red (#12940). | |
| 34 | 35 | */ |
| 35 | const RECORD_KEEPING = | |
| 36 | const SHARD_RECORDS = | |
| 36 | 37 | /^test-shards: (?:wrote [0-9]+ (?:times|test impacts) to |kept [0-9]+ green results in |not writing |not recording: )/; |
| 38 | const RECORD_KEEPING = { test: (line: string): boolean => SHARD_RECORDS.test(line) || TOOK_LINE.test(line) || STEP_TOOK_LINE.test(line) }; | |
| 37 | 39 | |
| 38 | 40 | /** |
| 39 | 41 | * A line only a test run prints: the gate's own, bun test's, or a file's time in a list of them. |
src/checks/took_line.ts added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | /** | |
| 2 | * The one shape of a check's took lines (#16876), read by the summary of a red check | |
| 3 | * (`summary.ts`) as bookkeeping and written by the runner (`runner/main.ts`, one a step) and by the | |
| 4 | * check step's scripts (`scripts/took.ts`; the gate writes its own copy, since the base's gate runs | |
| 5 | * alone beside a pull's tree). test/step-took.test.ts holds every writer to these patterns. | |
| 6 | */ | |
| 7 | ||
| 8 | /** A script of the check step: `gate: took 4.2s`. */ | |
| 9 | export const TOOK_LINE = /^(?:gate|design-drift|test-shards): took [0-9]+\.[0-9]s$/; | |
| 10 | ||
| 11 | /** A runner step: `runner: check took 52.3s`. */ | |
| 12 | export const STEP_TOOK_LINE = /^runner: [a-z]+ took [0-9]+\.[0-9]s$/; | |
| 13 | ||
| 14 | export const tookLine = (name: string, seconds: number): string => `${name}: took ${seconds.toFixed(1)}s`; |
src/runner/main.ts +5
| @@ -151,6 +151,9 @@ function fetchArgs(url: string, tip: MirrorTip, mode: "whole" | "shallow", shall | ||
| 151 | 151 | return ["fetch", "--quiet", "--no-tags", ...how, url, tip.oid]; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | /** A step's line: `runner: check took 52.3s`. */ | |
| 155 | export const stepTookLine = (name: string, ms: number): string => `runner: ${name} took ${(ms / 1000).toFixed(1)}s`; | |
| 156 | ||
| 154 | 157 | /** The checkout's line: the whole, then each part, in seconds. */ |
| 155 | 158 | export function checkoutLine(commit: string, started: number, fetched: number, exported: number, done: number): string { |
| 156 | 159 | const s = (ms: number): string => (ms / 1000).toFixed(1); |
| @@ -599,6 +602,8 @@ export async function runRunner(options: RunnerOptions): Promise<RunnerEnd> { | ||
| 599 | 602 | ...(ran.ok ? {} : { error: ran.error }), |
| 600 | 603 | ms: Date.now() - from, |
| 601 | 604 | }); |
| 605 | // Each step's whole time in the log (#16876): the check step's parts say their own. | |
| 606 | line("runner", stepTookLine(step.name, Date.now() - from)); | |
| 602 | 607 | if (!ran.ok) break; |
| 603 | 608 | } |
| 604 | 609 | if (stopping.aborted && !dropped) |
test/pin-refusal.test.ts +3
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import { afterAll, expect, test } from "bun:test"; |
| 2 | import { TOOK_LINE } from "../src/checks/took_line.ts"; | |
| 2 | 3 | import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | 4 | import { join } from "node:path"; |
| 4 | 5 | import { tmpdir } from "node:os"; |
| @@ -199,6 +200,8 @@ test("a migration added without its pin is named with the one-step fix, and the | ||
| 199 | 200 | expect(r.exitCode).toBe(2); |
| 200 | 201 | const lines = r.stderr.toString().split("\n"); |
| 201 | 202 | expect(lines).toContain(`gate: ${named}`); |
| 203 | // The gate says what it took, in the one shape every script of the check writes (`took.ts`). | |
| 204 | expect(lines.some((line) => TOOK_LINE.test(line))).toBe(true); | |
| 202 | 205 | // The fixture also trips "slow files" (it has no test files): the summary says both (#16325). |
| 203 | 206 | const summary = summariseCheckFailure(lines, "check exited with code 2").summary; |
| 204 | 207 | expect(summary).toStartWith("gate: refused by 2 rules: "); |
test/runner-seeds.test.ts +16
| @@ -217,6 +217,8 @@ describe("with a runner process connected", () => { | ||
| 217 | 217 | const log = logOf(run.id); |
| 218 | 218 | expect(log).toContain("runner seeds: impact map (2 tests)"); |
| 219 | 219 | expect(log).toContain("runner: seeded 4 of 4 files from the forge"); |
| 220 | // The runner says the check step's whole time when it ends (#16876). | |
| 221 | expect(log).toMatch(/^runner: check took [0-9]+\.[0-9]s$/m); | |
| 220 | 222 | // It wrote over all of them in its checkout; the forge's stores are as they were. |
| 221 | 223 | expect(stores()).toEqual(before); |
| 222 | 224 | expect(existsSync(seedsDir(f.dataDir, run.id))).toBe(false); |
| @@ -235,6 +237,20 @@ describe("with a runner process connected", () => { | ||
| 235 | 237 | renameSync(`${store("impact")}.aside`, store("impact")); |
| 236 | 238 | } |
| 237 | 239 | }); |
| 240 | ||
| 241 | test("the runner says each step's whole time: the install's and the check's", async () => { | |
| 242 | const withInstall = await commitToBranch(f.app, f.alice, f.repo, { | |
| 243 | message: "An install step", | |
| 244 | files: [{ path: "forge.json", content: `${JSON.stringify({ check: { run: checkOf(seen), install: "true" } })}\n` }], | |
| 245 | }); | |
| 246 | if (!withInstall.ok) throw new Error(JSON.stringify(withInstall.error)); | |
| 247 | await f.settled((r) => r.commitOid === withInstall.value.commitOid, 30_000); | |
| 248 | const oid = await pull("timed", "t.txt"); | |
| 249 | const run = await f.settled((r) => r.commitOid === oid, 30_000); | |
| 250 | const log = logOf(run.id); | |
| 251 | expect(log).toMatch(/^runner: install took [0-9]+\.[0-9]s$/m); | |
| 252 | expect(log).toMatch(/^runner: check took [0-9]+\.[0-9]s$/m); | |
| 253 | }); | |
| 238 | 254 | }); |
| 239 | 255 | |
| 240 | 256 | describe("a seed is read no further than the job named", () => { |
test/step-took.test.ts added +51
| @@ -0,0 +1,51 @@ | ||
| 1 | /** | |
| 2 | * A check's time, step by step, in its log (#16876): the runner says each step's whole time, and | |
| 3 | * the check step's scripts (the gate, the design drift, the test run) each say their own as they | |
| 4 | * end, on stderr; what is left of the check step is the type check between them. One shape | |
| 5 | * (`src/checks/took_line.ts`) holds every writer and the red check's summary, which skips them. | |
| 6 | * The runner's lines are proved through a real runner in test/runner-seeds.test.ts, the gate's | |
| 7 | * real line in test/pin-refusal.test.ts. | |
| 8 | */ | |
| 9 | import { expect, test } from "bun:test"; | |
| 10 | import { readFileSync } from "node:fs"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { summariseCheckFailure } from "../src/checks/summary.ts"; | |
| 13 | import { STEP_TOOK_LINE, TOOK_LINE, tookLine } from "../src/checks/took_line.ts"; | |
| 14 | import { stepTookLine } from "../src/runner/main.ts"; | |
| 15 | ||
| 16 | const ROOT = join(import.meta.dir, ".."); | |
| 17 | const stderrOf = (args: string[]): { code: number; err: string } => { | |
| 18 | const ran = Bun.spawnSync([process.execPath, ...args], { cwd: ROOT, stdout: "ignore", stderr: "pipe" }); | |
| 19 | return { code: ran.exitCode, err: ran.stderr.toString() }; | |
| 20 | }; | |
| 21 | ||
| 22 | test("a runner step's line, in the step shape", () => { | |
| 23 | expect(stepTookLine("install", 412)).toBe("runner: install took 0.4s"); | |
| 24 | expect(stepTookLine("check", 52_349)).toBe("runner: check took 52.3s"); | |
| 25 | expect(stepTookLine("check", 52_349)).toMatch(STEP_TOOK_LINE); | |
| 26 | }); | |
| 27 | ||
| 28 | test("design-drift says what it took as it ends", () => { | |
| 29 | const { err } = stderrOf(["scripts/design-drift.ts"]); | |
| 30 | expect(err.split("\n").filter((line) => TOOK_LINE.test(line))).toHaveLength(1); | |
| 31 | }); | |
| 32 | ||
| 33 | test("test-shards says what it took, even when it stops at its arguments", () => { | |
| 34 | const { code, err } = stderrOf(["scripts/test-shards.ts", "--tier", "bogus"]); | |
| 35 | expect(code).toBe(2); | |
| 36 | expect(err.split("\n").filter((line) => line.startsWith("test-shards: took ") && TOOK_LINE.test(line))).toHaveLength(1); | |
| 37 | }); | |
| 38 | ||
| 39 | test("the gate's own copy of the line writes the same shape (its real line: pin-refusal)", () => { | |
| 40 | const gate = readFileSync(join(ROOT, "scripts/gate.ts"), "utf8"); | |
| 41 | expect(gate).toContain("`gate: took ${(performance.now() / 1000).toFixed(1)}s\\n`"); | |
| 42 | expect(`gate: took ${(1234.5 / 1000).toFixed(1)}s`).toBe(tookLine("gate", 1.2345)); | |
| 43 | }); | |
| 44 | ||
| 45 | test("every took line has the one shape, and none is ever a red check's summary", () => { | |
| 46 | const lines = [...["gate", "design-drift", "test-shards"].map((name) => tookLine(name, 12.34)), stepTookLine("check", 9_000)]; | |
| 47 | for (const line of lines) { | |
| 48 | expect(TOOK_LINE.test(line) || STEP_TOOK_LINE.test(line)).toBe(true); | |
| 49 | expect(summariseCheckFailure(["the real reason", line], "check exited with code 1").summary).toBe("the real reason"); | |
| 50 | } | |
| 51 | }); |
new above
offline