Public: anyone can read this; the crew can change it.
Health says whether the forge is serving; what it would like done is a separa… #12075
scout/forge:scout/12071-health-says-whether-the-forge-is-serving → main 3 commits fork
11 files
changed +234
−37
src/actions/health.ts +20 −2
| @@ -97,8 +97,26 @@ export function readHealth( | ||
| 97 | 97 | return { ok, version, commit, draining }; |
| 98 | 98 | } |
| 99 | 99 | if (!actor?.isAdmin) return forge; |
| 100 | const v = forgeVitals(app); | |
| 101 | return { ...v, ...forge, ok: forge.ok && v.ok }; | |
| 100 | return whole(forge, forgeVitals(app)); | |
| 101 | } | |
| 102 | ||
| 103 | /** | |
| 104 | * The admin's whole answer (#12071). `ok` is "serving and nothing broken now": | |
| 105 | * not draining, no platform incident, and no `broken` vital. What the forge | |
| 106 | * would like done is `todo`, and never makes `ok` false. | |
| 107 | */ | |
| 108 | export function whole(forge: ForgeHealth, v: Vitals): Vitals & ForgeHealth & { says: string } { | |
| 109 | const broken = [ | |
| 110 | ...(forge.draining ? ["The forge is draining: it is handing over and will stop serving."] : []), | |
| 111 | ...forge.incidents.map((i) => `${i.key}: ${i.message}`), | |
| 112 | ...v.broken, | |
| 113 | ]; | |
| 114 | const todo = [...(forge.stale ? [forge.rollout.reason] : []), ...v.todo]; | |
| 115 | const ok = broken.length === 0; | |
| 116 | const says = ok | |
| 117 | ? `The forge is serving and nothing is broken now${todo.length === 0 ? "" : `; ${todo.length} thing${todo.length === 1 ? "" : "s"} would like doing, under todo`}.` | |
| 118 | : `The forge is not well: ${broken.length} thing${broken.length === 1 ? " is" : "s are"} broken now, under broken${todo.length === 0 ? "" : `; ${todo.length} more would like doing, under todo`}.`; | |
| 119 | return { ...v, ...forge, ok, broken, todo, says }; | |
| 102 | 120 | } |
| 103 | 121 | |
| 104 | 122 | /** |
src/kernel/boots.ts +8
| @@ -152,3 +152,11 @@ export function uncleanInFirstMinutes(dataDir: string, windowMs = FIRST_MINUTES_ | ||
| 152 | 152 | if (firstAt === undefined) return null; |
| 153 | 153 | return ledger.starts.slice(0, -1).filter((s) => !s.clean && s.at - firstAt <= windowMs && now - s.at < memoryMs).length; |
| 154 | 154 | } |
| 155 | ||
| 156 | /** | |
| 157 | * Starts in the last `windowMs` that never exited cleanly, this process's own start left out; | |
| 158 | * 0 when there is no ledger. | |
| 159 | */ | |
| 160 | export function recentUncleanStarts(dataDir: string, windowMs: number, now = Date.now(), id = thisStart): number { | |
| 161 | return read(dataDir).starts.filter((s) => s.id !== id && !s.clean && now - s.at < windowMs).length; | |
| 162 | } |
src/kernel/vitals.ts +52 −13
| @@ -30,6 +30,7 @@ import { BUDGETS } from "./budgets.ts"; | ||
| 30 | 30 | import { openDbFiles } from "./file_modes.ts"; |
| 31 | 31 | import { dbFile, dbGrowth, dbSize, dbSizeNeed, fileBytes, type DbWalk } from "../system/db_size.ts"; |
| 32 | 32 | import { backupVerdict, isWatched } from "../snapshot/bucket.ts"; |
| 33 | import { recentUncleanStarts } from "./boots.ts"; | |
| 33 | 34 | import { lastDrill } from "../snapshot/drills.ts"; |
| 34 | 35 | import { lastMirror, mirrorNeed } from "../snapshot/mirror.ts"; |
| 35 | 36 | import { lastSnapshotOutcome, snapshotNeed } from "../snapshot/outcome.ts"; |
| @@ -38,11 +39,8 @@ import { proofNeed } from "../release/prove.ts"; | ||
| 38 | 39 | import { running as runningVersion } from "./version.ts"; |
| 39 | 40 | import { rollbackNeed } from "../release/launch.ts"; |
| 40 | 41 | import { behindStanding } from "../release/behind.ts"; |
| 41 | import { newestDrills } from "../core/domain_drills.ts"; | |
| 42 | 42 | import { capacityValue } from "../core/capacity.ts"; |
| 43 | 43 | import { unwrittenFor, SILENT_AFTER_S } from "../http/access_log.ts"; |
| 44 | import { DOMAINS } from "./domains.ts"; | |
| 45 | import { domainDrillNeeds } from "./domain_drill.ts"; | |
| 46 | 44 | import { freeChecks, heldChecks, redHref, redSentence } from "../checks/red_main.ts"; |
| 47 | 45 | import { diskRedSentence, diskReds } from "../checks/disk_red.ts"; |
| 48 | 46 | import { flakeList, type FlakeRow } from "../checks/flake.ts"; |
| @@ -100,8 +98,17 @@ export interface Lane { | ||
| 100 | 98 | } |
| 101 | 99 | |
| 102 | 100 | export interface Vitals { |
| 101 | /** True when nothing is broken now; a standing `todo` does not make it false (#12071). */ | |
| 103 | 102 | readonly ok: boolean; |
| 103 | /** Every sentence, `broken` then `todo` in the order found. */ | |
| 104 | 104 | readonly needs: string[]; |
| 105 | /** | |
| 106 | * Act now: the disk under its floor, a red main, a database that does not answer, memory gone, | |
| 107 | * a crash loop. | |
| 108 | */ | |
| 109 | readonly broken: string[]; | |
| 110 | /** Would like done: everything else that is off. Never makes `ok` false. */ | |
| 111 | readonly todo: string[]; | |
| 105 | 112 | readonly degraded: Degraded[]; |
| 106 | 113 | readonly disk: { freeBytes: number; totalBytes: number }; |
| 107 | 114 | readonly memory: { |
| @@ -319,10 +326,32 @@ export function laneSentence( | ||
| 319 | 326 | return `${head}; the longest running is ${name(longest)} at ${minutes(longest)} min (limit ${BUDGETS.gate / 60_000})${more}.`; |
| 320 | 327 | } |
| 321 | 328 | |
| 329 | /** Memory the host has left, under which the forge is broken: 64 MiB. */ | |
| 330 | export const MEMORY_FLOOR_BYTES = 64 * 1024 * 1024; | |
| 331 | ||
| 332 | /** Unclean starts in the quarter hour that make a crash loop. */ | |
| 333 | export const CRASH_LOOP = 3; | |
| 334 | ||
| 335 | /** Whether a cause is broken now (act) rather than a thing to do. */ | |
| 336 | export function isBroken(cause: string): boolean { | |
| 337 | return ( | |
| 338 | cause === "db-down" || | |
| 339 | cause === "disk" || | |
| 340 | cause === "disk-floor" || | |
| 341 | cause === "disk-red" || | |
| 342 | cause === "memory" || | |
| 343 | cause === "crash-loop" || | |
| 344 | cause.startsWith("red:") || | |
| 345 | cause.startsWith("file:") | |
| 346 | ); | |
| 347 | } | |
| 348 | ||
| 322 | 349 | export function vitals(input: VitalsInput): Vitals { |
| 323 | 350 | const now = input.now ?? Date.now(); |
| 324 | 351 | const at = new Date(now).toISOString(); |
| 325 | 352 | const needs: string[] = []; |
| 353 | const broken: string[] = []; | |
| 354 | const todo: string[] = []; | |
| 326 | 355 | const degraded: Degraded[] = []; |
| 327 | 356 | let firstSeen = firstSeenByForge.get(input.signals.errors); |
| 328 | 357 | if (!firstSeen) firstSeenByForge.set(input.signals.errors, (firstSeen = new Map())); |
| @@ -338,9 +367,17 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 338 | 367 | firstSeen.set(cause, since); |
| 339 | 368 | } |
| 340 | 369 | needs.push(sentence); |
| 370 | (isBroken(cause) ? broken : todo).push(sentence); | |
| 341 | 371 | degraded.push({ cause, sentence, since, href }); |
| 342 | 372 | }; |
| 343 | 373 | |
| 374 | // The database answers, or nothing else here is worth reading. | |
| 375 | try { | |
| 376 | input.db.query("select 1").get(); | |
| 377 | } catch { | |
| 378 | need("db-down", "The database does not answer.", undefined, "/system"); | |
| 379 | } | |
| 380 | ||
| 344 | 381 | const disk = (input.disk ?? readDisk)(input.dataDir); |
| 345 | 382 | // Room to spare (#11940): at 100 GiB free no share-of-the-disk guard speaks, |
| 346 | 383 | // the floor and the marks alike. |
| @@ -372,6 +409,13 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 372 | 409 | ); |
| 373 | 410 | } |
| 374 | 411 | |
| 412 | const hostFree = freemem(); | |
| 413 | if (hostFree < MEMORY_FLOOR_BYTES) | |
| 414 | need("memory", `The host has ${Math.round(hostFree / 1024 / 1024)} MiB of memory left (the floor is ${MEMORY_FLOOR_BYTES / 1024 / 1024} MiB).`, undefined, "/system"); | |
| 415 | const crashes = recentUncleanStarts(input.dataDir, 15 * 60_000, now); | |
| 416 | if (crashes >= CRASH_LOOP) | |
| 417 | need("crash-loop", `The forge started ${crashes} times in 15 minutes without exiting cleanly.`, undefined, "/system"); | |
| 418 | ||
| 375 | 419 | for (const file of openDbFiles(input.dataDir)) |
| 376 | 420 | need(`file:${file.name}`, file.sentence, undefined, "/settings/capacity"); |
| 377 | 421 | |
| @@ -520,15 +564,8 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 520 | 564 | if (owed !== undefined) |
| 521 | 565 | need("drill", owed.sentence, owed.since, "/settings/backups"); |
| 522 | 566 | |
| 523 | // A domain whose drill is red or eight days old is a card with the command that runs it. | |
| 524 | for (const owed of domainDrillNeeds( | |
| 525 | newestDrills(input.db), | |
| 526 | now, | |
| 527 | drillFirstSeen(input.dataDir), | |
| 528 | input.forgeUrl ?? "http://localhost", | |
| 529 | DOMAINS, | |
| 530 | )) | |
| 531 | need(owed.cause, owed.sentence, owed.since, "/"); | |
| 567 | // No domain-drill need (#12071): nothing runs a drill by itself yet, so "never drilled" was a | |
| 568 | // standing need no one could meet. | |
| 532 | 569 | |
| 533 | 570 | // A snapshot that failed is a card from that morning until one lands. |
| 534 | 571 | const failing = snapshotNeed(lastSnapshotOutcome(input.dataDir)); |
| @@ -596,8 +633,10 @@ export function vitals(input: VitalsInput): Vitals { | ||
| 596 | 633 | if (!degraded.some((d) => d.cause === cause)) firstSeen.delete(cause); |
| 597 | 634 | |
| 598 | 635 | return { |
| 599 | ok: needs.length === 0, | |
| 636 | ok: broken.length === 0, | |
| 600 | 637 | needs, |
| 638 | broken, | |
| 639 | todo, | |
| 601 | 640 | degraded, |
| 602 | 641 | disk, |
| 603 | 642 | memory: { |
src/release/journey.ts +11 −1
| @@ -39,6 +39,11 @@ export interface JourneyOptions { | ||
| 39 | 39 | readonly pollMs?: number; |
| 40 | 40 | /** Waits `ms`; `Bun.sleep` when left out. */ |
| 41 | 41 | readonly sleep?: (ms: number) => Promise<void>; |
| 42 | /** | |
| 43 | * The forge's probe header, sent to `base` only: the walk is the forge's own, not a stranger's, | |
| 44 | * and spends no stranger's allowance. | |
| 45 | */ | |
| 46 | readonly probe?: Readonly<Record<string, string>>; | |
| 42 | 47 | } |
| 43 | 48 | |
| 44 | 49 | export interface JourneyResult { |
| @@ -100,7 +105,12 @@ export async function walkJourney(options: JourneyOptions): Promise<JourneyResul | ||
| 100 | 105 | const hostUrl = host; |
| 101 | 106 | |
| 102 | 107 | const call = (url: URL, init: RequestInit = {}): Promise<Response> => |
| 103 | doFetch(url.href, { redirect: "manual", signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), ...init }); | |
| 108 | doFetch(url.href, { | |
| 109 | redirect: "manual", | |
| 110 | signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), | |
| 111 | ...init, | |
| 112 | ...(options.probe !== undefined && url.origin === hostUrl.origin ? { headers: { ...options.probe, ...(init.headers as Record<string, string> | undefined) } } : {}), | |
| 113 | }); | |
| 104 | 114 | const form = (url: URL, fields: Record<string, string>, extra: Record<string, string> = {}): Promise<Response> => |
| 105 | 115 | call(url, { |
| 106 | 116 | method: "POST", |
src/release/prove.ts +1 −1
| @@ -225,7 +225,7 @@ export async function proveRelease(o: ProveOptions): Promise<Proof | undefined> | ||
| 225 | 225 | if (failures[0] !== undefined || o.journey === undefined) |
| 226 | 226 | return finish(failures[0] === undefined ? undefined : checkLine(failures[0]), failures[0]?.slow === true || failures[0]?.empty === true || failures[0]?.hung === true); |
| 227 | 227 | // The stranger's journey, the last check: a failed walk is a failed proof, retried on `retryAfter` like any other (one card, paged once). |
| 228 | const walked = await o.journey({ base: o.url, fetch: doFetch, ...(o.token ? { adminToken: o.token } : {}) }); | |
| 228 | const walked = await o.journey({ base: o.url, fetch: doFetch, probe: ownProbeHeaders(o.dataDir), ...(o.token ? { adminToken: o.token } : {}) }); | |
| 229 | 229 | return finish(walked.ok ? undefined : `a stranger's journey failed: ${walked.failure ?? "it did not finish"}`, false, false, walked); |
| 230 | 230 | } catch (error) { |
| 231 | 231 | return finish(`the smoke checks could not run: ${String(error)}`); |
src/spawn/door.ts +7 −3
| @@ -35,6 +35,7 @@ import { dryRun, planSpawn, KEY_BUDGET_NOTE, MAX_APPS, type CatalogApp, type Cre | ||
| 35 | 35 | import { bootHostedChild } from "./host.ts"; |
| 36 | 36 | import { cellPlacement, ownsBody } from "./cell.ts"; |
| 37 | 37 | import { cellsAvailable } from "../apps/contain.ts"; |
| 38 | import { isProbe } from "../kernel/probe.ts"; | |
| 38 | 39 | import { ANON_SPAWNS_PER_DAY, checkAnonSpawn, noteAnonSpawn } from "./rate.ts"; |
| 39 | 40 | import { readdirSync, readFileSync } from "node:fs"; |
| 40 | 41 | import { readdir, stat } from "node:fs/promises"; |
| @@ -188,12 +189,15 @@ export async function spawnDoor( | ||
| 188 | 189 | ): Promise<Door> { |
| 189 | 190 | const paid = opts.paid === true; |
| 190 | 191 | const anon = user === undefined; |
| 192 | // The forge's own journey prober (#12071) is not a stranger: it spends neither the per-minute | |
| 193 | // plan limit nor the day's allowance. | |
| 194 | const prober = isProbe(ctx.request, ctx.app.config.dataDir); | |
| 191 | 195 | if (!anon && user.kind !== "user") return spawnWords({ kind: "forbidden" }); |
| 192 | 196 | // A forge asked for in order to contribute is never made: the fork path costs the host no cell. |
| 193 | 197 | if (wantsToContribute(raw)) return { status: 200, body: contributeAnswer() }; |
| 194 | 198 | // A plan is free of children but not of work — it reads every catalog |
| 195 | 199 | // app it names — so a stranger's are counted per address and per forge. |
| 196 | if (anon && !paid) { | |
| 200 | if (anon && !paid && !prober) { | |
| 197 | 201 | const verdict = takeDoor(ctx.app, "plan", ctx.request); |
| 198 | 202 | if (!verdict.allowed) |
| 199 | 203 | return { |
| @@ -341,7 +345,7 @@ export async function spawnDoor( | ||
| 341 | 345 | }; |
| 342 | 346 | } |
| 343 | 347 | // A stranger may start only a few children a day; the plan above is free. |
| 344 | if (anon && !paid) { | |
| 348 | if (anon && !paid && !prober) { | |
| 345 | 349 | const limit = checkAnonSpawn(ctx.app.db, ctx.request); |
| 346 | 350 | if (!limit.allowed) |
| 347 | 351 | return { |
| @@ -380,7 +384,7 @@ export async function spawnDoor( | ||
| 380 | 384 | if (gift !== undefined && !settled) unclaimGift(ctx.app, gift); |
| 381 | 385 | } |
| 382 | 386 | if (!made.ok) return spawnWords(made.error); |
| 383 | if (anon && !paid && !made.value.existed) noteAnonSpawn(ctx.app.db, ctx.request); | |
| 387 | if (anon && !paid && !prober && !made.value.existed) noteAnonSpawn(ctx.app.db, ctx.request); | |
| 384 | 388 | // The visitor who started (or was given) this forge becomes someone, on the host's side (#11265). |
| 385 | 389 | if (!made.value.existed && !paid) linkRequestVisitor(ctx.app, ctx.request, made.value.name, gift === undefined ? "started" : "paid"); |
| 386 | 390 | // Its apps come up now, so the first visit after a claim finds them awake. |
test/backup-truth.test.ts +1 −1
| @@ -295,7 +295,7 @@ test("the check records each run; stopped past its interval, the verdict, tile, | ||
| 295 | 295 | const card = vitals({ db: own.db, signals: own.signals, dataDir: dir, now: later }).degraded.find((d) => d.cause === "backup"); |
| 296 | 296 | expect(card?.sentence).toContain(`last ran ${ranAt}`); |
| 297 | 297 | const health = readHealth(own, { isAdmin: true } as User) as { ok: boolean; degraded: { cause: string; sentence: string }[] }; |
| 298 | expect(health.ok).toBe(false); | |
| 298 | expect(health.ok).toBe(true); // a backup that stopped is a thing to do (#12071), not a forge that is down | |
| 299 | 299 | expect(health.degraded.find((d) => d.cause === "backup")?.sentence).toContain(`last ran ${ranAt}`); |
| 300 | 300 | expect(verdictLines({ app: own } as never).join("\n")).toContain("runs on record"); |
| 301 | 301 | } finally { |
test/health-broken.test.ts added +109
| @@ -0,0 +1,109 @@ | ||
| 1 | /** | |
| 2 | * Health says whether the forge is serving (#12071): `ok` is false only for what is | |
| 3 | * broken now, and what the forge would like done is `todo`. | |
| 4 | */ | |
| 5 | import { beforeEach, describe, expect, test } from "bun:test"; | |
| 6 | import type { Database } from "bun:sqlite"; | |
| 7 | import { mkdtempSync } from "node:fs"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { migrations } from "../src/core/schema.ts"; | |
| 11 | import { openDb } from "../src/kernel/db.ts"; | |
| 12 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 13 | import { isBroken, vitals } from "../src/kernel/vitals.ts"; | |
| 14 | import { whole } from "../src/actions/health.ts"; | |
| 15 | import type { ForgeHealth } from "../src/kernel/guard.ts"; | |
| 16 | import { ErrorLedger } from "../src/kernel/log.ts"; | |
| 17 | import { RefusedLedger } from "../src/kernel/internal_refused.ts"; | |
| 18 | import { walkJourney } from "../src/release/journey.ts"; | |
| 19 | ||
| 20 | let db: Database; | |
| 21 | let dir: string; | |
| 22 | beforeEach(() => { | |
| 23 | db = openDb(":memory:", migrations); | |
| 24 | dir = mkdtempSync(join(tmpdir(), "hb-")); | |
| 25 | }); | |
| 26 | const read = (disk?: { freeBytes: number; totalBytes: number }) => | |
| 27 | vitals({ | |
| 28 | db, | |
| 29 | dataDir: dir, | |
| 30 | signals: { errors: new ErrorLedger(), refused: new RefusedLedger() }, | |
| 31 | ...(disk ? { disk: () => disk } : {}), | |
| 32 | }); | |
| 33 | const forge = (over: Partial<ForgeHealth> = {}): ForgeHealth => ({ | |
| 34 | ok: true, | |
| 35 | version: "1", | |
| 36 | commit: "abc", | |
| 37 | draining: false, | |
| 38 | rollout: { state: "ok", reason: "" }, | |
| 39 | incidents: [], | |
| 40 | stale: false, | |
| 41 | checkedAt: null, | |
| 42 | ...over, | |
| 43 | }); | |
| 44 | ||
| 45 | describe("ok is serving and nothing broken", () => { | |
| 46 | test("a well forge is ok, with a sentence that says so", () => { | |
| 47 | const h = whole(forge(), read()); | |
| 48 | expect(h.ok).toBe(true); | |
| 49 | expect(h.broken).toEqual([]); | |
| 50 | expect(h.says).toContain("serving and nothing is broken"); | |
| 51 | }); | |
| 52 | ||
| 53 | test("a draining forge is not ok, and says why under broken", () => { | |
| 54 | const h = whole(forge({ draining: true }), read()); | |
| 55 | expect(h.ok).toBe(false); | |
| 56 | expect(h.broken[0]).toContain("draining"); | |
| 57 | expect(h.says).toContain("not well"); | |
| 58 | }); | |
| 59 | ||
| 60 | test("a full disk is not ok, and is under broken", () => { | |
| 61 | const h = whole(forge(), read({ freeBytes: 5, totalBytes: 100 })); | |
| 62 | expect(h.ok).toBe(false); | |
| 63 | expect(h.broken.join(" ")).toContain("Disk is nearly full"); | |
| 64 | expect(h.todo.join(" ")).not.toContain("Disk is nearly full"); | |
| 65 | }); | |
| 66 | ||
| 67 | test("a red main is not ok, and is under broken", () => { | |
| 68 | db.run("INSERT INTO user (id, username, email, password_hash) VALUES ('u1', 'trevato', 't@x', '')"); | |
| 69 | db.run("INSERT INTO repo (id, owner_id, name) VALUES ('r1', 'u1', 'forge')"); | |
| 70 | db.run("INSERT INTO issue (id, repo_id, number, kind, title, author_id) VALUES ('i1', 'r1', 7, 'pull', 'p', 'u1')"); | |
| 71 | const run = createRun(db, { repoId: "r1", kind: "check", env: "main", commitOid: "b".repeat(40), reason: "push" }); | |
| 72 | claimRun(db, run.id); | |
| 73 | finishRun(db, run.id, { state: "failed", summary: "check failed", checkDetail: { passed: 1, failed: 1, names: ["one"] } }); | |
| 74 | createRun(db, { repoId: "r1", kind: "check", env: "pull-7", issueId: "i1", commitOid: "a".repeat(40), reason: "push" }); | |
| 75 | const h = whole(forge(), read()); | |
| 76 | expect(h.ok).toBe(false); | |
| 77 | expect(h.broken.join(" ")).toContain("main is red"); | |
| 78 | }); | |
| 79 | ||
| 80 | test("a platform incident is broken; a stale view and the database size are todo", () => { | |
| 81 | const h = whole(forge({ incidents: [{ key: "stuck", message: "x" }] }), read()); | |
| 82 | expect(h.ok).toBe(false); | |
| 83 | const stale = whole(forge({ stale: true, rollout: { state: "ok", reason: "the platform's view is stale" } }), read()); | |
| 84 | expect(stale.ok).toBe(true); | |
| 85 | expect(stale.todo).toEqual(["the platform's view is stale"]); | |
| 86 | expect(isBroken("db-size")).toBe(false); | |
| 87 | expect(isBroken("db-growth")).toBe(false); | |
| 88 | expect(isBroken("release")).toBe(false); | |
| 89 | expect(isBroken("disk-floor")).toBe(true); | |
| 90 | }); | |
| 91 | ||
| 92 | test("no drill need is raised for a forge that never drilled", () => { | |
| 93 | db.run("INSERT INTO user (id, username, email, password_hash) VALUES ('u1', 'a', 'a@x', '')"); | |
| 94 | expect(read().needs.join(" ")).not.toContain("drill"); | |
| 95 | }); | |
| 96 | }); | |
| 97 | ||
| 98 | describe("the journey prober", () => { | |
| 99 | test("sends the probe header to the forge it walks, and to no other host", async () => { | |
| 100 | const seen: { url: string; probe: string | null }[] = []; | |
| 101 | const fake = (async (url: string, init?: RequestInit) => { | |
| 102 | const h = new Headers(init?.headers); | |
| 103 | seen.push({ url: String(url), probe: h.get("x-probe") }); | |
| 104 | return new Response("", { status: 500 }); | |
| 105 | }) as unknown as typeof fetch; | |
| 106 | await walkJourney({ base: "https://forge.example", fetch: fake, probe: { "x-probe": "k" } }); | |
| 107 | expect(seen[0]).toEqual({ url: "https://forge.example/", probe: "k" }); | |
| 108 | }); | |
| 109 | }); |
test/spawn-anon.test.ts +12 −1
| @@ -18,6 +18,7 @@ import { createUser } from "../src/core/users.ts"; | ||
| 18 | 18 | import { serve, type Servers } from "../src/http/server.ts"; |
| 19 | 19 | import { childDirOf } from "../src/actions/spawn.ts"; |
| 20 | 20 | import { bootHostedChild } from "../src/spawn/host.ts"; |
| 21 | import { probeHeaders } from "../src/kernel/probe.ts"; | |
| 21 | 22 | import { ok } from "../src/kernel/result.ts"; |
| 22 | 23 | |
| 23 | 24 | describe("anonymous spawn", () => { |
| @@ -184,6 +185,16 @@ describe("anonymous spawn", () => { | ||
| 184 | 185 | // A dry run is free: the plan still comes back. |
| 185 | 186 | const dry = await post({ name: "kid5" }); |
| 186 | 187 | expect(dry.status).toBe(200); |
| 188 | // The forge's own journey prober is not a stranger (#12071): it passes the limit and is not | |
| 189 | // counted. | |
| 190 | const probe = await fetch(`${base}/api/v1/forges`, { | |
| 191 | method: "POST", | |
| 192 | headers: { "content-type": "application/json", ...probeHeaders(dataDir) }, | |
| 193 | body: JSON.stringify({ name: "kidp", dryRun: false }), | |
| 194 | }); | |
| 195 | expect(probe.status).toBe(201); | |
| 196 | await settle("kidp"); | |
| 197 | expect((await post({ name: "kidq", dryRun: false })).status).toBe(429); | |
| 187 | 198 | resetAnonSpawns(app.db); |
| 188 | 199 | }); |
| 189 | 200 | |
| @@ -221,6 +232,6 @@ describe("anonymous spawn", () => { | ||
| 221 | 232 | } finally { |
| 222 | 233 | child.close(); |
| 223 | 234 | } |
| 224 | expect(await readdir(join(dataDir, "children")).catch(() => [])).toHaveLength(4); | |
| 235 | expect(await readdir(join(dataDir, "children")).catch(() => [])).toHaveLength(5); | |
| 225 | 236 | }); |
| 226 | 237 | }); |
test/vitals-domain-drill.test.ts +3 −9
| @@ -68,19 +68,13 @@ test("a verdict that is not a quoted phrase is quoted whole, and bounded", () => | ||
| 68 | 68 | expect(n[0]!.sentence.length).toBeLessThan(400); |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | test("vitals raises them from the newest drill of each domain, in one query", async () => { | |
| 71 | test("vitals raises none of them: nothing runs a drill by itself yet (#12071)", async () => { | |
| 72 | 72 | const { vitals } = await import("../src/kernel/vitals.ts"); |
| 73 | const { newestDrills, recordDrill } = await import("../src/core/domain_drills.ts"); | |
| 73 | const { recordDrill } = await import("../src/core/domain_drills.ts"); | |
| 74 | 74 | const { createApp } = await import("../src/app.ts"); |
| 75 | 75 | const dir = mkdtempSync(join(tmpdir(), "vdd-")); |
| 76 | 76 | const app = createApp({ dataDir: dir, port: 0 }); |
| 77 | 77 | const seen = { health: "", board: "" }; |
| 78 | 78 | recordDrill(app.db, "u", "compute", seen, 1, { green: false, why: 'the forge never said "x"' }); |
| 79 | const sentence = () => | |
| 80 | vitals({ db: app.db, signals: app.signals, dataDir: dir, forgeUrl: URL_ }).needs.find((s) => s.includes("compute drill")); | |
| 81 | expect(sentence()).toContain(`bun scripts/drills/run.ts compute --forge ${URL_}`); | |
| 82 | app.db.query("UPDATE domain_drill SET at = '2020-01-01T00:00:00.000Z'").run(); | |
| 83 | recordDrill(app.db, "u", "compute", seen, 1, { green: true, why: "ok" }); | |
| 84 | expect(sentence()).toBeUndefined(); | |
| 85 | expect(newestDrills(app.db).length).toBe(1); | |
| 79 | expect(vitals({ db: app.db, signals: app.signals, dataDir: dir, forgeUrl: URL_ }).needs.join(" ")).not.toContain("drill"); | |
| 86 | 80 | }); |
test/vitals.test.ts +10 −6
| @@ -94,9 +94,9 @@ test("a site admin with a read-only token gets the shape; others get the short o | ||
| 94 | 94 | expect(Object.keys(v).sort()).toEqual( |
| 95 | 95 | [ |
| 96 | 96 | "accessLog", |
| 97 | "apps", "at", "checkedAt", "commit", "degraded", "disk", "draining", "errors", "flakes", | |
| 98 | "incidents", "lane", "memory", "needs", "ok", "queue", "rollout", "stale", "stuck", | |
| 99 | "version", | |
| 97 | "apps", "at", "broken", "checkedAt", "commit", "degraded", "disk", "draining", "errors", "flakes", | |
| 98 | "incidents", "lane", "memory", "needs", "ok", "queue", "rollout", "says", "stale", "stuck", | |
| 99 | "todo", "version", | |
| 100 | 100 | ].sort(), |
| 101 | 101 | ); |
| 102 | 102 | expect(v.disk.totalBytes).toBeGreaterThan(0); |
| @@ -129,7 +129,9 @@ test("a full queue shows in queue, and an old one in needs", async () => { | ||
| 129 | 129 | // Process-wide signals (errors, refused calls) from other suites may speak too. |
| 130 | 130 | expect(v.needs.join(" ")).not.toContain("queue"); |
| 131 | 131 | const later = vitals({ db: app.db, signals: app.signals, dataDir, disk: roomy, now: old + 2 * 3_600_000 + 3_600_000 }); |
| 132 | expect(later.ok).toBe(false); | |
| 132 | expect(later.ok).toBe(true); | |
| 133 | expect(later.broken).toEqual([]); | |
| 134 | expect(later.todo.join(" ")).toContain("queue"); | |
| 133 | 135 | expect(later.needs.join(" ")).toContain("agent queue"); |
| 134 | 136 | }); |
| 135 | 137 | |
| @@ -143,7 +145,8 @@ test("a running run with a lapsed lease is stuck, and needs says so", async () = | ||
| 143 | 145 | const v = (await (await health(admin)).json()) as ReturnType<typeof vitals>; |
| 144 | 146 | expect(v.stuck.map((s) => s.runId)).toEqual([run.id]); |
| 145 | 147 | expect(v.stuck[0]!.repo).toBe("alice/r"); |
| 146 | expect(v.ok).toBe(false); | |
| 148 | expect(v.ok).toBe(true); | |
| 149 | expect(v.todo.join(" ")).toContain("stuck"); | |
| 147 | 150 | expect(v.needs.some((n) => n.includes("stuck"))).toBe(true); |
| 148 | 151 | // A fresh heartbeat clears it. |
| 149 | 152 | app.db |
| @@ -466,7 +469,8 @@ test("a lane older than its budget is degraded with its cause; a silent run is s | ||
| 466 | 469 | expect(lane?.sentence).toMatch( |
| 467 | 470 | /^3 checks wait behind one lane; the oldest since \d\d:\d\d; the lane runs a check for 31 min \(limit 60\)\.$/, |
| 468 | 471 | ); |
| 469 | expect(v.ok).toBe(false); | |
| 472 | expect(v.ok).toBe(true); | |
| 473 | expect(v.todo.join(" ")).toContain("wait"); | |
| 470 | 474 | // Five minutes in, the oldest is under its budget: nothing to say. |
| 471 | 475 | app.db.query("UPDATE run SET created_at=?1 WHERE state='queued'").run(iso(now - 5 * 60_000)); |
| 472 | 476 | expect(vitals({ db: app.db, signals: app.signals, dataDir, disk: roomy, now }).degraded.map((d) => d.cause)).toEqual([]); |
new above
offline