Skip to content
Myr

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

3 files+184 added−3 removed

modified:packages/project/src/outbox.ts+48 added-2 removed
1import { RefName, RepoHost } from "@repo/artifacts/repo-host";2import { CheckAt, CheckRunner } from "@repo/checks/check-runner";3import { Verdict } from "@repo/protocol/domain/answer";4import type { ProjectEvent } from "@repo/protocol/domain/event";5import { RunBlock } from "@repo/protocol/domain/run";6import {7 CommitSha,8 Handle,9 LandedSha,10 ProjectName,11 RepoName,12 RequestId,13 TreeSha,14} from "@repo/protocol/ids";12import type { ProjectName } from "@repo/protocol/ids";15import { Array, DateTime, Effect, Option, Order, Schema, Struct } from "effect";1617import { AnswerRuns } from "./answer-runs.ts";18import type { AnswerQueue } from "./answer-runs.ts";19import { DraftParams, DraftRuns } from "./draft-runs.ts";20import { noRunEnv } from "./env-port.ts";21import { Lander, Rebuild } from "./lander.ts";22import { backoff } from "./landing.ts";23import { MetricPoint, Metrics } from "./metrics.ts";24import type { OutboxRow } from "./project-store/rows.ts";
26 unmodified lines
51 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"));6768export type OutboxBody = typeof OutboxBody.Type;69
63 unmodified lines
133 Array.of134 )135 : Effect.succeed([]);136137/** Kept in the commit that keeps the landing, under the landing's SHA: one job per landing, however often it is heard. */138export 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);143144export const isDue = (row: OutboxRow, now: DateTime.Utc) =>145 DateTime.isLessThanOrEqualTo(row.notBefore, now);146147export interface OutboxRun {
70 unmodified lines
218 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 lines
289 ({ body, row }) =>290 Effect.as(metrics.write(body.points), ran(row, true, now))291 );292293 // 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 );316317 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 lines
327 ...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 lines
274 OutboxBody,275 projectedRows,276 runOutbox,277 startRow,278 warmRow,279} from "./outbox.ts";280import { ProjectStore } from "./project-store.ts";281import type { ProjectSnapshot, ProjectWrites } from "./project-store.ts";282import type {
1756 unmodified lines
2039 withPorts(facts).pipe(2040 Effect.flatMap((found) => layered(snapshotNow(h, writes), found))2041 );20422043 /**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 }20532054 const row = writes.project.get("row");20552056 const policy =2057 row?.policy === undefined2058 ? h.policy2059 : Option.some(yield* Effect.orDie(decodePolicy(row.policy)));20602061 if (Option.isNone(policy) || policy.value.run.setup === undefined) {2062 return [];2063 }20642065 const { run } = policy.value;20662067 return yield* Effect.forEach(writes.landings, ({ sha }) =>2068 warmRow({ at: sha, project: name, repo, run }, now)2069 );2070 });20712072 const commit = (h: Hydrated, writes: Writes, now: DateTime.Utc) =>2073 Effect.gen(function* () {2074 if (isEmpty(writes)) {2075 return [];
10 unmodified lines
2086 now2087 )2088 );20892060 const outbox = [...writes.outbox, ...landed.flat(), ...projected];2090 const warmed = yield* warmRows(h, writes, now);20912092 const outbox = [2093 ...writes.outbox,2094 ...landed.flat(),2095 ...warmed,2096 ...projected,2097 ];20982099 const queue = yield* Effect.forEach(writes.queue.values(), (each) =>2100 storedQueue(each)2101 );2102
3465 unmodified lines
added:packages/project/test/warm-setup.test.ts+98 added
1import { describe, expect, it } from "@effect/vitest";2import { CheckAt } from "@repo/checks/check-runner";3import type { CheckJob } from "@repo/checks/check-runner";4import { Command } from "@repo/protocol/domain/common";5import type { Policy } from "@repo/protocol/domain/policy";6import { keyOf, RepoName } from "@repo/protocol/ids";7import { Person } from "@repo/protocol/principal";8import { advanceTo } from "@repo/testkit/clock";9import type { Files } from "@repo/testkit/git-client";10import { aProject } from "@repo/testkit/scenarios";11import { Effect, Option } from "effect";1213import { projectService } from "../src/project.ts";14import { CheckScript, Pusher, worldOf } from "./world.ts";1516const scenario = aProject();1718const repo = RepoName.make(keyOf(scenario.project));1920const alice = Person.make({ handle: scenario.initializer });2122const 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];2728const installing: Policy = {29 ...scenario.policy,30 run: {31 ...scenario.policy.run,32 setup: Command.make("bun install --frozen-lockfile"),33 },34};3536const shape = ({ at, lanes, project, repo: on, run }: CheckJob) => ({37 at,38 lanes,39 project,40 repo: on,41 setup: run.setup,42});4344const firstLanding = Effect.gen(function* () {45 yield* advanceTo("2026-10-07T12:00:00Z");4647 const api = yield* projectService(scenario.project);4849 yield* api.initProject(alice, {});5051 const first = yield* Pusher.use((pusher) =>52 pusher.push(repo, Option.none(), start, "Start")53 );5455 yield* api.recordFirstPush(alice, first);5657 return { api, first };58});5960const jobs = CheckScript.use((script) => script.jobs);6162describe("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;6869 const afterLanding = (yield* jobs).map(shape);7071 yield* api.onAlarm();72 yield* api.onAlarm();7374 const afterAlarms = (yield* jobs).map(shape);7576 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 );9091 it.effect("is not warmed when the policy runs no setup", () =>92 Effect.gen(function* () {93 yield* firstLanding;9495 expect(yield* jobs).toStrictEqual([]);96 }).pipe(Effect.provide(worldOf({ policy: scenario.policy }, "memory")))97 );98});