Partial: warm a landing's setup snapshot with one Checker job per landing from the outbox of the commit that keeps it (WarmSetup row, warm:<sha>, only when the policy runs a setup), with its test; left: rename the test's shape helper for anti-slop/no-shape-in-symbol-names, then platform tests and typecheck
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by oscabriel · committed by oscabriel · parent 8c56f70 · Browse files · 3 files·+184 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+184 added−3 removed
- tests:+98 added−0 removed
- other:+86 added−3 removed
Provenance
- Commit
2f2c840- Tree
d42e4cf- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
8c56f70
3 files changed+184 added−3 removed
modified:packages/project/src/outbox.ts+48 added-2 removed
1 import { RefName, RepoHost } from "@repo/artifacts/repo-host";2+import { CheckAt, CheckRunner } from "@repo/checks/check-runner";3 import { Verdict } from "@repo/protocol/domain/answer";4 import type { ProjectEvent } from "@repo/protocol/domain/event";5+import { RunBlock } from "@repo/protocol/domain/run";6 import {7 CommitSha,8 Handle,9 LandedSha,10+ ProjectName,11 RepoName,12 RequestId,13 TreeSha,14 } from "@repo/protocol/ids";12-import type { ProjectName } from "@repo/protocol/ids";15 import { Array, DateTime, Effect, Option, Order, Schema, Struct } from "effect";16 17 import { AnswerRuns } from "./answer-runs.ts";18 import type { AnswerQueue } from "./answer-runs.ts";19 import { DraftParams, DraftRuns } from "./draft-runs.ts";20+import { noRunEnv } from "./env-port.ts";21 import { Lander, Rebuild } from "./lander.ts";22 import { backoff } from "./landing.ts";23 import { MetricPoint, Metrics } from "./metrics.ts";24 import type { OutboxRow } from "./project-store/rows.ts";26 unmodified lines51 Schema.TaggedStruct("StartDraft", DraftParams.fields),52 Schema.TaggedStruct("Measured", {53 points: Schema.NonEmptyArray(MetricPoint),54 }),55+ /**56+ * One Checker job with no lanes on a landed commit, so its setup snapshot57+ * is there before the next answer: the Checker keeps a snapshot only for58+ * the project's own commits, and an answer's tree alone never makes one.59+ */60+ Schema.TaggedStruct("WarmSetup", {61+ at: LandedSha,62+ project: ProjectName,63+ repo: RepoName,64+ run: RunBlock,65+ }),66 ]).pipe(Schema.toTaggedUnion("_tag"));67 68 export type OutboxBody = typeof OutboxBody.Type;69 63 unmodified lines133 Array.of134 )135 : Effect.succeed([]);136 137+/** Kept in the commit that keeps the landing, under the landing's SHA: one job per landing, however often it is heard. */138+export const warmRow = (139+ job: Omit<Extract<OutboxBody, { readonly _tag: "WarmSetup" }>, "_tag">,140+ at: DateTime.Utc141+) =>142+ outboxRow(`warm:${job.at}`, OutboxBody.cases.WarmSetup.make(job), at);143+144 export const isDue = (row: OutboxRow, now: DateTime.Utc) =>145 DateTime.isLessThanOrEqualTo(row.notBefore, now);146 147 export interface OutboxRun {70 unmodified lines218 claim: (ids: readonly string[]) => Effect.Effect<readonly string[]>219 ): Effect.Effect<220 OutboxRun,221 never,201- AnswerRuns | Lander | Projection | RepoHost222+ AnswerRuns | CheckRunner | Lander | Projection | RepoHost223 > =>224 Effect.gen(function* () {225 const decoded = yield* Effect.forEach(rows, (row) =>226 Effect.map(Effect.orDie(decodeBody(row.body)), (body) => ({ body, row }))62 unmodified lines289 ({ body, row }) =>290 Effect.as(metrics.write(body.points), ran(row, true, now))291 );292 293+ // Best effort, once: a setup the Checker could not keep is installed294+ // again by the next answer, as it would have been.295+ const warmed = yield* Effect.forEach(of("WarmSetup"), ({ body, row }) =>296+ Effect.as(297+ CheckRunner.use((runner) =>298+ runner.run({299+ ...noRunEnv,300+ at: CheckAt.cases.Commit.make({ commit: body.at }),301+ lanes: [],302+ project: body.project,303+ repo: body.repo,304+ run: body.run,305+ })306+ ).pipe(307+ Effect.catchTag("VerifierBlocked", () =>308+ Effect.logWarning("the setup snapshot was not warmed").pipe(309+ Effect.annotateLogs({ landed: body.at, project: body.project })310+ )311+ )312+ ),313+ ran(row, true, now)314+ )315+ );316+317 const runs = yield* Effect.forEach(of("StartAnswer"), ({ body, row }) =>318 Effect.as(319 AnswerRuns.use((answers) => answers.start(body.requestId, queue)),320 ran(row, true, now)6 unmodified lines327 ...kept,328 ...planned,329 ...drafts,330 ...measured,331+ ...warmed,332 ...runs,333 ]);334 });modified:packages/project/src/project.ts+38 added-1 removed
273 unmodified lines274 OutboxBody,275 projectedRows,276 runOutbox,277 startRow,278+ warmRow,279 } from "./outbox.ts";280 import { ProjectStore } from "./project-store.ts";281 import type { ProjectSnapshot, ProjectWrites } from "./project-store.ts";282 import type {1756 unmodified lines2039 withPorts(facts).pipe(2040 Effect.flatMap((found) => layered(snapshotNow(h, writes), found))2041 );2042 2043+ /**2044+ * One Checker job per landing whose policy has a setup, so the setup2045+ * snapshot for the landed lockfiles is there before the next answer;2046+ * nothing when the policy runs no setup, since no snapshot is kept then.2047+ */2048+ const warmRows = (h: Hydrated, writes: Writes, now: DateTime.Utc) =>2049+ Effect.gen(function* () {2050+ if (!Array.isReadonlyArrayNonEmpty(writes.landings)) {2051+ return [];2052+ }2053+2054+ const row = writes.project.get("row");2055+2056+ const policy =2057+ row?.policy === undefined2058+ ? h.policy2059+ : Option.some(yield* Effect.orDie(decodePolicy(row.policy)));2060+2061+ if (Option.isNone(policy) || policy.value.run.setup === undefined) {2062+ return [];2063+ }2064+2065+ const { run } = policy.value;2066+2067+ return yield* Effect.forEach(writes.landings, ({ sha }) =>2068+ warmRow({ at: sha, project: name, repo, run }, now)2069+ );2070+ });2071+2072 const commit = (h: Hydrated, writes: Writes, now: DateTime.Utc) =>2073 Effect.gen(function* () {2074 if (isEmpty(writes)) {2075 return [];10 unmodified lines2086 now2087 )2088 );2089 2060- const outbox = [...writes.outbox, ...landed.flat(), ...projected];2090+ const warmed = yield* warmRows(h, writes, now);2091 2092+ const outbox = [2093+ ...writes.outbox,2094+ ...landed.flat(),2095+ ...warmed,2096+ ...projected,2097+ ];2098+2099 const queue = yield* Effect.forEach(writes.queue.values(), (each) =>2100 storedQueue(each)2101 );2102 3465 unmodified linesadded:packages/project/test/warm-setup.test.ts+98 added
1+import { describe, expect, it } from "@effect/vitest";2+import { CheckAt } from "@repo/checks/check-runner";3+import type { CheckJob } from "@repo/checks/check-runner";4+import { Command } from "@repo/protocol/domain/common";5+import type { Policy } from "@repo/protocol/domain/policy";6+import { keyOf, RepoName } from "@repo/protocol/ids";7+import { Person } from "@repo/protocol/principal";8+import { advanceTo } from "@repo/testkit/clock";9+import type { Files } from "@repo/testkit/git-client";10+import { aProject } from "@repo/testkit/scenarios";11+import { Effect, Option } from "effect";12+13+import { projectService } from "../src/project.ts";14+import { CheckScript, Pusher, worldOf } from "./world.ts";15+16+const scenario = aProject();17+18+const repo = RepoName.make(keyOf(scenario.project));19+20+const alice = Person.make({ handle: scenario.initializer });21+22+const start: Files = [23+ ["package.json", '{ "name": "alice/datekit", "private": true }\n'],24+ ["bun.lock", "{}\n"],25+ ["src/trim.ts", "export const trim = (s) => s;\n"],26+];27+28+const installing: Policy = {29+ ...scenario.policy,30+ run: {31+ ...scenario.policy.run,32+ setup: Command.make("bun install --frozen-lockfile"),33+ },34+};35+36+const shape = ({ at, lanes, project, repo: on, run }: CheckJob) => ({37+ at,38+ lanes,39+ project,40+ repo: on,41+ setup: run.setup,42+});43+44+const firstLanding = Effect.gen(function* () {45+ yield* advanceTo("2026-10-07T12:00:00Z");46+47+ const api = yield* projectService(scenario.project);48+49+ yield* api.initProject(alice, {});50+51+ const first = yield* Pusher.use((pusher) =>52+ pusher.push(repo, Option.none(), start, "Start")53+ );54+55+ yield* api.recordFirstPush(alice, first);56+57+ return { api, first };58+});59+60+const jobs = CheckScript.use((script) => script.jobs);61+62+describe("a landing's setup snapshot", () => {63+ it.effect(64+ "is warmed by one Checker job with no lanes on the landed commit, once however often the outbox runs",65+ () =>66+ Effect.gen(function* () {67+ const { api, first } = yield* firstLanding;68+69+ const afterLanding = (yield* jobs).map(shape);70+71+ yield* api.onAlarm();72+ yield* api.onAlarm();73+74+ const afterAlarms = (yield* jobs).map(shape);75+76+ expect({ afterAlarms, afterLanding }).toStrictEqual({77+ afterAlarms: afterLanding,78+ afterLanding: [79+ {80+ at: CheckAt.cases.Commit.make({ commit: first }),81+ lanes: [],82+ project: scenario.project,83+ repo,84+ setup: "bun install --frozen-lockfile",85+ },86+ ],87+ });88+ }).pipe(Effect.provide(worldOf({ policy: installing }, "memory")))89+ );90+91+ it.effect("is not warmed when the policy runs no setup", () =>92+ Effect.gen(function* () {93+ yield* firstLanding;94+95+ expect(yield* jobs).toStrictEqual([]);96+ }).pipe(Effect.provide(worldOf({ policy: scenario.policy }, "memory")))97+ );98+});