Public: anyone can read this; the crew can change it.
Move the accessors out of snapshot/service.ts (snapshotsOf) so it leaves the boot's static closure #17302
Merged 39h 40m ago, live in production
mason/forge:mason/17183-move-the-accessors-out-of-snapshot-servi → main 0 commits fork
17 files
changed +43
−23
- src/actions/backup_retry.ts
- src/actions/backups_now.ts
- src/actions/destination.ts
- src/actions/health.ts
- src/actions/mirror.ts
- src/actions/resilience.ts
- src/http/mcp/tools/backups.ts
- src/http/mcp/tools/mirror_set.ts
- src/http/mcp/tools/restore_drill.ts
- src/keeper/wire.ts
- src/snapshot/backups_line.ts
- src/snapshot/registry.ts
- src/snapshot/service.ts
- src/tui/screens/resilience.ts
- src/web/pages/backups.ts
- test/backup-truth.test.ts
- test/boot-lazy.test.ts
src/actions/backup_retry.ts +1 −1
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | import type { App } from "../app.ts"; |
| 9 | 9 | import type { User } from "../core/users.ts"; |
| 10 | 10 | import { isOffBox } from "../snapshot/off_box.ts"; |
| 11 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 11 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 12 | 12 | import { snapshotNow } from "./backups_now.ts"; |
| 13 | 13 | |
| 14 | 14 | export interface BackupRetry { |
src/actions/backups_now.ts +1 −1
| @@ -13,7 +13,7 @@ import { err, ok, type Result } from "../kernel/result.ts"; | ||
| 13 | 13 | import type { DrillStep } from "../snapshot/drill.ts"; |
| 14 | 14 | import { costLine } from "../snapshot/drill_cost.ts"; |
| 15 | 15 | import { lastDrill } from "../snapshot/drills.ts"; |
| 16 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 16 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 17 | 17 | import { fileSize } from "../web/ui.ts"; |
| 18 | 18 | |
| 19 | 19 | const isAdmin = (actor: User | undefined): boolean => actor?.isAdmin === true; |
src/actions/destination.ts +1 −1
| @@ -18,7 +18,7 @@ import { | ||
| 18 | 18 | } from "../snapshot/destination.ts"; |
| 19 | 19 | import { kitIdentity, kitText, makeKit, recordDownload } from "../snapshot/kit.ts"; |
| 20 | 20 | import { s3FromEnv, type S3Target } from "../blob/store.ts"; |
| 21 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 21 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 22 | 22 | import type { User } from "../core/users.ts"; |
| 23 | 23 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 24 | 24 | import { NOT_SEALED } from "../kernel/seal_words.ts"; |
src/actions/health.ts +1 −1
| @@ -35,7 +35,7 @@ import { | ||
| 35 | 35 | type Vitals, |
| 36 | 36 | type VitalsInput, |
| 37 | 37 | } from "../kernel/vitals.ts"; |
| 38 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 38 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 39 | 39 | import { optionals, type Optional } from "../system/footprint.ts"; |
| 40 | 40 | import { forgesMemory, memoryOverLine } from "../spawn/memory_fit.ts"; |
| 41 | 41 | import { releaseOf } from "../kernel/version.ts"; |
src/actions/mirror.ts +1 −1
| @@ -14,7 +14,7 @@ import { | ||
| 14 | 14 | MIRROR_SEALED, |
| 15 | 15 | recordMirror, |
| 16 | 16 | } from "../snapshot/mirror.ts"; |
| 17 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 17 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 18 | 18 | import type { User } from "../core/users.ts"; |
| 19 | 19 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 20 | 20 | import { NOT_SEALED } from "../kernel/seal_words.ts"; |
src/actions/resilience.ts +1 −1
| @@ -11,7 +11,7 @@ import type { User } from "../core/users.ts"; | ||
| 11 | 11 | import { drillCommand } from "../kernel/domain_drill.ts"; |
| 12 | 12 | import { DOMAINS } from "../kernel/domains.ts"; |
| 13 | 13 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 14 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 14 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 15 | 15 | import { forgeNeeds } from "./health.ts"; |
| 16 | 16 | |
| 17 | 17 | export interface ResilienceRow { |
src/http/mcp/tools/backups.ts +1 −1
| @@ -1,4 +1,4 @@ | ||
| 1 | import { snapshotsOf } from "../../../snapshot/service.ts"; | |
| 1 | import { snapshotsOf } from "../../../snapshot/registry.ts"; | |
| 2 | 2 | import { resolveSnapshots, scrubReason, sealedTarget } from "../../../snapshot/destination.ts"; |
| 3 | 3 | import { bodiesOf } from "../../../blob/store.ts"; |
| 4 | 4 | import { mirrorNeed } from "../../../snapshot/mirror.ts"; |
src/http/mcp/tools/mirror_set.ts +1 −1
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | import { forgetMirror, saveMirror } from "../../../actions/mirror.ts"; |
| 2 | import { snapshotsOf } from "../../../snapshot/service.ts"; | |
| 2 | import { snapshotsOf } from "../../../snapshot/registry.ts"; | |
| 3 | 3 | import { good, bad, type Tool } from "../shared.ts"; |
| 4 | 4 | |
| 5 | 5 | export const tool: Tool = { |
src/http/mcp/tools/restore_drill.ts +2 −1
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import { scopeAllows } from "../../../core/tokens.ts"; |
| 2 | 2 | import { costLine } from "../../../snapshot/drill_cost.ts"; |
| 3 | 3 | import { lastDrill } from "../../../snapshot/drills.ts"; |
| 4 | import { snapshotsOf, type SnapshotsHandle } from "../../../snapshot/service.ts"; | |
| 4 | import { snapshotsOf } from "../../../snapshot/registry.ts"; | |
| 5 | import type { SnapshotsHandle } from "../../../snapshot/service.ts"; | |
| 5 | 6 | import { good, bad, type Tool, mayBoards } from "../shared.ts"; |
| 6 | 7 | |
| 7 | 8 | const phaseWords = (st: ReturnType<SnapshotsHandle["startDrill"]>["state"]): Record<string, string | number> => |
src/keeper/wire.ts +1 −1
| @@ -34,7 +34,7 @@ import { readTags, recordFor } from "../release/shipped.ts"; | ||
| 34 | 34 | import { checkoutRelease, preflightRelease } from "../release/checkout.ts"; |
| 35 | 35 | import { handover } from "../release/swap.ts"; |
| 36 | 36 | import { runningChildren } from "../boards/sampler.ts"; |
| 37 | import { snapshotsOf } from "../snapshot/service.ts"; | |
| 37 | import { snapshotsOf } from "../snapshot/registry.ts"; | |
| 38 | 38 | import { kubeDeployer } from "./deploy.ts"; |
| 39 | 39 | import { inFlight, keepInterrupted, keepRollback, keepTimings } from "./record.ts"; |
| 40 | 40 | import { runningAgentRuns } from "../crew/running.ts"; |
src/snapshot/backups_line.ts +1 −1
src/snapshot/registry.ts added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | /** | |
| 2 | * Where the running snapshot service is found. The service fills this when it starts | |
| 3 | * (`service.ts`); pages, actions and tools ask here, so none of them loads the service itself and | |
| 4 | * the boot's static imports leave it out (#17183). | |
| 5 | */ | |
| 6 | import type { App } from "../app.ts"; | |
| 7 | import type { SnapshotsHandle } from "./service.ts"; | |
| 8 | ||
| 9 | const handles = new WeakMap<App, SnapshotsHandle>(); | |
| 10 | ||
| 11 | export const snapshotsOf = (app: App): SnapshotsHandle | undefined => handles.get(app); | |
| 12 | ||
| 13 | /** | |
| 14 | * Record the service started for `app`; the returned function forgets it when it is still the one. | |
| 15 | */ | |
| 16 | export function registerSnapshots(app: App, handle: SnapshotsHandle): () => void { | |
| 17 | handles.set(app, handle); | |
| 18 | return () => { | |
| 19 | if (handles.get(app) === handle) handles.delete(app); | |
| 20 | }; | |
| 21 | } |
src/snapshot/service.ts +3 −6
| @@ -43,6 +43,7 @@ import { remakeOf, s3FromEnv, type Store } from "../blob/store.ts"; | ||
| 43 | 43 | import { verifySnapshot } from "./verify.ts"; |
| 44 | 44 | import { during } from "../perf/jobs.ts"; |
| 45 | 45 | import { limitValue } from "../settings/limits.ts"; |
| 46 | import { registerSnapshots } from "./registry.ts"; | |
| 46 | 47 | |
| 47 | 48 | const log = createLog("snapshots"); |
| 48 | 49 | |
| @@ -126,10 +127,6 @@ export interface SnapshotsHandle { | ||
| 126 | 127 | readonly stop: () => Promise<void>; |
| 127 | 128 | } |
| 128 | 129 | |
| 129 | const handles = new WeakMap<App, SnapshotsHandle>(); | |
| 130 | export const snapshotsOf = (app: App): SnapshotsHandle | undefined => | |
| 131 | handles.get(app); | |
| 132 | ||
| 133 | 130 | /** The weekly restore drill: Sunday, an hour after the nightly snapshot. */ |
| 134 | 131 | const DRILL_DAY_UTC = 0; |
| 135 | 132 | const DRILL_HOUR_UTC = 9; |
| @@ -795,10 +792,10 @@ export function startSnapshots( | ||
| 795 | 792 | bucket.stop(); |
| 796 | 793 | if (mirroring !== undefined) await mirroring.catch(() => {}); |
| 797 | 794 | if (inFlight !== undefined) await inFlight.catch(() => {}); |
| 798 | if (handles.get(app) === handle) handles.delete(app); | |
| 795 | forget(); | |
| 799 | 796 | }, |
| 800 | 797 | }; |
| 801 | handles.set(app, handle); | |
| 798 | const forget = registerSnapshots(app, handle); | |
| 802 | 799 | log.info("snapshots on", { |
| 803 | 800 | where: current()?.where ?? "nowhere", |
| 804 | 801 | keep: KEEP, |
src/tui/screens/resilience.ts +1 −1
| @@ -46,7 +46,7 @@ import { lastDrill } from "../../snapshot/drills.ts"; | ||
| 46 | 46 | import { hostedDrillWords } from "../../snapshot/drill_hosted_words.ts"; |
| 47 | 47 | import { resolveSnapshots } from "../../snapshot/destination.ts"; |
| 48 | 48 | import { bodiesOf } from "../../blob/store.ts"; |
| 49 | import { snapshotsOf } from "../../snapshot/service.ts"; | |
| 49 | import { snapshotsOf } from "../../snapshot/registry.ts"; | |
| 50 | 50 | import type { Ctx, Screen } from "../app/app.ts"; |
| 51 | 51 | import { binding } from "../app/keys.ts"; |
| 52 | 52 | import type { Session } from "../session.ts"; |
src/web/pages/backups.ts +2 −1
| @@ -36,7 +36,8 @@ import { backupVerdict } from "../../snapshot/bucket.ts"; | ||
| 36 | 36 | import { bodiesOf, type Store } from "../../blob/store.ts"; |
| 37 | 37 | import { hostedWords } from "../../snapshot/hosted.ts"; |
| 38 | 38 | import { hostedDrillWords } from "../../snapshot/drill_hosted_words.ts"; |
| 39 | import { snapshotsOf, type SnapshotsHandle } from "../../snapshot/service.ts"; | |
| 39 | import { snapshotsOf } from "../../snapshot/registry.ts"; | |
| 40 | import type { SnapshotsHandle } from "../../snapshot/service.ts"; | |
| 40 | 41 | import { drillStatus, mirrorNow, snapshotNow, startDrillNow } from "../../actions/backups_now.ts"; |
| 41 | 42 | import { lastSnapshotOutcome } from "../../snapshot/outcome.ts"; |
| 42 | 43 | import type { Ctx } from "../../http/context.ts"; |
test/backup-truth.test.ts +2 −1
| @@ -16,7 +16,8 @@ import { vitals } from "../src/kernel/vitals.ts"; | ||
| 16 | 16 | import { backupVerdict, CHECK_LOG, CHECK_LOG_KEEP, CHECK_STALE_MS, recordRun, judge, keepReads, LATE_MS, readLane, watchBucket, type LaneRead } from "../src/snapshot/bucket.ts"; |
| 17 | 17 | import type { DrillResult } from "../src/snapshot/drill.ts"; |
| 18 | 18 | import { lastNightly, snapshotDue } from "../src/snapshot/due.ts"; |
| 19 | import { snapshotsOf, startSnapshots } from "../src/snapshot/service.ts"; | |
| 19 | import { snapshotsOf } from "../src/snapshot/registry.ts"; | |
| 20 | import { startSnapshots } from "../src/snapshot/service.ts"; | |
| 20 | 21 | import { listSnapshots } from "../src/snapshot/snapshot.ts"; |
| 21 | 22 | import { dirStore } from "../src/blob/store.ts"; |
| 22 | 23 | import { verdictLines } from "../src/tui/screens/resilience.ts"; |
test/boot-lazy.test.ts +2 −3
| @@ -24,11 +24,10 @@ test("the terminal's server is imported dynamically by the boot", () => { | ||
| 24 | 24 | // #17021: the services only the boot starts are not in its static closure; that each still starts |
| 25 | 25 | // is proved on a real boot (boot-production.test.ts, "background service started service=<name>"). |
| 26 | 26 | // The heavier ones are still reached by pages and actions, each its own follow-up: #17179, |
| 27 | // #17180, #17181, #17182, #17183 (apps/runtime, checks/service, crew/dispatch, looks/service, | |
| 28 | // snapshot/service). | |
| 27 | // #17180, #17181, #17182 (apps/runtime, checks/service, crew/dispatch, looks/service). | |
| 29 | 28 | test("the boot's static imports do not reach the services only it starts", () => { |
| 30 | 29 | const closure = [...staticClosure(resolve("src/main.ts"))]; |
| 31 | const only = ["maintain/runner.ts", "nightly/service.ts", "keeper/keeper.ts", "keeper/wire.ts", "crew/routines.ts"]; | |
| 30 | const only = ["maintain/runner.ts", "nightly/service.ts", "keeper/keeper.ts", "keeper/wire.ts", "crew/routines.ts", "snapshot/service.ts"]; | |
| 32 | 31 | for (const file of only) expect(closure.some((f) => f.endsWith(`/src/${file}`)), file).toBe(false); |
| 33 | 32 | }); |
| 34 | 33 |
new above
offline