Public: anyone can read this; the crew can change it.
The restore drill's result keeps how long the hosted forge took to restore, in whole seconds #14189
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14184-the-restore-drill-s-result-keeps-how-lon → main 2 commits fork
5 files
changed +54
−7
src/snapshot/drill.ts +2 −2
| @@ -359,12 +359,12 @@ export async function runDrill(deps: DrillDeps): Promise<DrillResult> { | ||
| 359 | 359 | step = "forge"; |
| 360 | 360 | const from = tick(); |
| 361 | 361 | const proof = await within( |
| 362 | (deps.prove ?? proveHosted)(store, newest.name, pick, join(scratch, "forge"), { passphrase: deps.passphrase, of: held.length, leftMs: left }), | |
| 362 | (deps.prove ?? proveHosted)(store, newest.name, pick, join(scratch, "forge"), { passphrase: deps.passphrase, of: held.length, leftMs: left, ticks: tick }), | |
| 363 | 363 | left(), |
| 364 | 364 | budget, |
| 365 | 365 | ); |
| 366 | 366 | // Its restore and checks together, so the card can say it in seconds (#13919). |
| 367 | hosted = { ...proof, ms: Math.round(tick() - from) }; | |
| 367 | hosted = { ...proof, ms: proof.ms ?? Math.round(tick() - from) }; | |
| 368 | 368 | } else hostedSkipped = true; |
| 369 | 369 | } catch (error) { |
| 370 | 370 | reason = |
src/snapshot/drill_hosted.ts +10 −4
| @@ -29,8 +29,8 @@ export interface HostedProof { | ||
| 29 | 29 | /** The bytes its restore wrote. */ |
| 30 | 30 | readonly bytes: number; |
| 31 | 31 | /** |
| 32 | * Its restore and checks, wall time in ms, as the drill timed them (#13919); absent from a proof | |
| 33 | * before the drill times it, and on drills kept before that. | |
| 32 | * Its restore and checks, in whole ms of the monotonic clock: proveHosted times itself (#14184), | |
| 33 | * and the drill times a proof that did not (#13919). Absent on drills kept before that. | |
| 34 | 34 | */ |
| 35 | 35 | readonly ms?: number | undefined; |
| 36 | 36 | } |
| @@ -59,9 +59,15 @@ export async function proveHosted( | ||
| 59 | 59 | snapshot: string, |
| 60 | 60 | forge: HostedEntry, |
| 61 | 61 | dir: string, |
| 62 | options: { readonly passphrase?: string | undefined; readonly of: number; readonly leftMs?: (() => number) | undefined; readonly git?: typeof runGit | undefined }, | |
| 62 | options: { readonly passphrase?: string | undefined; readonly of: number; readonly leftMs?: (() => number) | undefined; | |
| 63 | readonly git?: typeof runGit | undefined; | |
| 64 | /** Test seam: the monotonic clock its time is read from (`performance.now`). */ | |
| 65 | readonly ticks?: (() => number) | undefined; | |
| 66 | }, | |
| 63 | 67 | ): Promise<HostedProof> { |
| 64 | 68 | const git = options.git ?? runGit; |
| 69 | const tick = options.ticks ?? (() => performance.now()); | |
| 70 | const start = tick(); | |
| 65 | 71 | const back = await restoreHosted(store, snapshot, forge.name, dir, { passphrase: options.passphrase, git }); |
| 66 | 72 | // Without its host's ledger of it, a host could not list it or wake it. |
| 67 | 73 | let kept: { name?: unknown }; |
| @@ -98,5 +104,5 @@ export async function proveHosted( | ||
| 98 | 104 | repos++; |
| 99 | 105 | } |
| 100 | 106 | if (repos !== forge.repos) throw new Error(`hosted forge ${forge.name}: ${repos} repositories came back, its copy holds ${forge.repos}`); |
| 101 | return { name: forge.name, of: options.of, repos, bytes: forge.bytes }; | |
| 107 | return { name: forge.name, of: options.of, repos, bytes: forge.bytes, ms: Math.max(0, Math.round(tick() - start)) }; | |
| 102 | 108 | } |
src/snapshot/drills.ts +1
| @@ -68,6 +68,7 @@ export function parseHosted(raw: string | null): { hosted?: HostedProof } { | ||
| 68 | 68 | const whole = (v: unknown): v is number => typeof v === "number" && Number.isSafeInteger(v) && v >= 0; |
| 69 | 69 | const { name, of, repos, bytes, ms } = h; |
| 70 | 70 | if (typeof name !== "string" || name.length > 100 || !whole(of) || !whole(repos) || !whole(bytes)) return {}; |
| 71 | // A drill kept before its time was measured (#14184) has none; one that does not read is none. | |
| 71 | 72 | return { hosted: { name, of, repos, bytes, ...(whole(ms) ? { ms } : {}) } }; |
| 72 | 73 | } catch { |
| 73 | 74 | return {}; |
test/drill-hosted-ms.test.ts added +25
| @@ -0,0 +1,25 @@ | ||
| 1 | /** | |
| 2 | * A kept drill's hosted proof reads its restore time back, and a drill kept | |
| 3 | * before that time was measured still reads (#14184). | |
| 4 | */ | |
| 5 | import { describe, expect, test } from "bun:test"; | |
| 6 | import { parseHosted } from "../src/snapshot/drills.ts"; | |
| 7 | ||
| 8 | const row = (hosted: unknown): string => JSON.stringify({ phases: [], budgetMs: 1000, hosted }); | |
| 9 | ||
| 10 | describe("parseHosted and the hosted forge's restore time", () => { | |
| 11 | test("a stored drill with ms reads it back", () => { | |
| 12 | expect(parseHosted(row({ name: "alpha", of: 3, repos: 2, bytes: 4096, ms: 12_401 }))).toEqual({ hosted: { name: "alpha", of: 3, repos: 2, bytes: 4096, ms: 12_401 } }); | |
| 13 | }); | |
| 14 | ||
| 15 | test("a stored drill without ms still parses, with no ms", () => { | |
| 16 | const read = parseHosted(row({ name: "alpha", of: 3, repos: 2, bytes: 4096 })); | |
| 17 | expect(read).toEqual({ hosted: { name: "alpha", of: 3, repos: 2, bytes: 4096 } }); | |
| 18 | expect("ms" in read.hosted!).toBe(false); | |
| 19 | }); | |
| 20 | ||
| 21 | test("an ms that is not a whole non-negative number is left out, and the rest still reads", () => { | |
| 22 | for (const ms of [-1, 1.5, "12", null, Number.MAX_VALUE]) | |
| 23 | expect(parseHosted(row({ name: "alpha", of: 1, repos: 1, bytes: 1, ms }))).toEqual({ hosted: { name: "alpha", of: 1, repos: 1, bytes: 1 } }); | |
| 24 | }); | |
| 25 | }); |
test/snapshot-hosted-chunks.test.ts +16 −1
| @@ -30,7 +30,7 @@ import { repoDir } from "../src/git/repos.ts"; | ||
| 30 | 30 | import { judge, readLane, type LaneRead } from "../src/snapshot/bucket.ts"; |
| 31 | 31 | import { CHUNK_PREFIX, chunkKey } from "../src/snapshot/chunks.ts"; |
| 32 | 32 | import { runDrill } from "../src/snapshot/drill.ts"; |
| 33 | import { drillPick } from "../src/snapshot/drill_hosted.ts"; | |
| 33 | import { drillPick, proveHosted } from "../src/snapshot/drill_hosted.ts"; | |
| 34 | 34 | import { hostedDrillWords } from "../src/snapshot/drill_hosted_words.ts"; |
| 35 | 35 | import { restoreHosted } from "../src/snapshot/restore.ts"; |
| 36 | 36 | import { chunksNamed, pruneSnapshots, takeSnapshot, type Manifest } from "../src/snapshot/snapshot.ts"; |
| @@ -274,6 +274,21 @@ describe("two nights of a host with hosted forges", () => { | ||
| 274 | 274 | expect(judge({ lanes: [lane], checkedAt: new Date(now).toISOString() }, result, now).drill?.says).toBe("restore drill 2026-11-17 passed (1 h ago), with hosted forge alpha (1 of 1)"); |
| 275 | 275 | }); |
| 276 | 276 | |
| 277 | test("the proof keeps how long its restore and proof took, read from its clock, in whole ms (#14184)", async () => { | |
| 278 | // A fake monotonic clock: 1000 ms at the start, 13_400.6 ms at the end, whatever was read | |
| 279 | // between. | |
| 280 | const reads: number[] = []; | |
| 281 | const ticks = (): number => { | |
| 282 | const t = reads.length === 0 ? 1000 : 13_400.6; | |
| 283 | reads.push(t); | |
| 284 | return t; | |
| 285 | }; | |
| 286 | const proof = await proveHosted(store, m2.name, m2.hosted![0]!, join(fresh("prove"), "forge"), { passphrase: PASS, of: 1, ticks }); | |
| 287 | // 13_400.6 − 1000 = 12_400.6 ms, rounded to 12_401. | |
| 288 | expect(proof).toEqual({ name: "alpha", of: 1, repos: 1, bytes: m2.hosted![0]!.bytes, ms: 12_401 }); | |
| 289 | expect(reads.length).toBe(2); | |
| 290 | }); | |
| 291 | ||
| 277 | 292 | test("a hosted forge that does not come back whole fails the drill at its own step, by name", async () => { |
| 278 | 293 | // One chunk only that forge's database needs is gone from a store of its own. |
| 279 | 294 | const holed = copyOf(store); |
new above
offline