Skip to content
Myr

Run an answer's comparisons on main at once and count its ratchets in the cheap stage's own job: each lane's comparison is its own step and container job, named by its lane, so they ran one after another for nothing; and the ratchet count was a container job of its own before the cheap lanes' job, so one answer paid two setups where one does, the count's lanes joined to the stage's unless a ratchet is named as a lane is, in which case it still runs apart; the answer test's Checker now prints a lane's stdout, and a test holds the cheap stage's one job to its lanes and the ratchet's together

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by oscabriel · committed by oscabriel · parent 081fd0f · Browse files · 4 files+148 added−33 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+148 added−33 removed

  • tests:+87 added−3 removed
  • other:+61 added−30 removed

4 files+148 added−33 removed

modified:apps/platform/src/workflows/answer/lanes.ts+48 added-22 removed
305 unmodified lines
306 readonly counts: readonly MeasuredCount[];307 readonly uncounted: Option.Option<RatchetName>;308}309310/** What the lane running a command printed, or nothing. */311const printedBy =312 (lanes: readonly CheckLane[], ran: CheckRun) => (command: string) =>313 Option.getOrElse(314 Option.flatMap(315 Option.fromUndefinedOr(lanes.find((lane) => lane.command === command)),316 ({ lane }) => outputOf(ran, lane)317 ),318 () => ""319 );320321/** The ratchets' counts, read from the lanes a run printed. */310const countRatchets = <E, R>(322const countRatchets = (323 run: AnswerRun,312 job: (lanes: readonly CheckLane[]) => Effect.Effect<CheckRun, E, R>313): Effect.Effect<Counted, E, R> =>324 lanes: readonly CheckLane[],325 ran: CheckRun326): Effect.Effect<Counted> =>327 Effect.gen(function* () {328 const specs = run.counts?.ratchets ?? [];329330 if (!Array.isReadonlyArrayNonEmpty(specs)) {331 return { counts: [], uncounted: Option.none() };332 }333321 const lanes = countLanes(specs);334 const printed = printedBy(lanes, ran);335323 const ran = yield* job(lanes);324325 const printed = (command: string) =>326 Option.getOrElse(327 Option.flatMap(328 Option.fromUndefinedOr(329 lanes.find((lane) => lane.command === command)330 ),331 ({ lane }) => outputOf(ran, lane)332 ),333 () => ""334 );335336 const counts = yield* Effect.forEach(specs, (spec) =>337 measure(338 spec,339 (command) => Effect.succeed({ code: 0, stdout: printed(command) }),
6 unmodified lines
346 onSuccess: (all) => ({ counts: all.flat(), uncounted: Option.none() }),347 });348 });349350/** The ratchets' lanes, counted in the cheap stage. */351const countingLanesOf = (run: AnswerRun, stage: Stage): readonly CheckLane[] =>352 stage === "cheap" && run.counts !== undefined353 ? countLanes(run.counts.ratchets)354 : [];355356const namesApart = (357 lanes: readonly CheckLane[],358 counting: readonly CheckLane[]359) => counting.every((count) => lanes.every(({ lane }) => lane !== count.lane));360361const countFields = (counted: Counted): Pick<Ran, "counts" | "uncounted"> =>362 Option.match(counted.uncounted, {363 onNone: () => ({ counts: counted.counts }),364 onSome: (uncounted) => ({ counts: counted.counts, uncounted }),
23 unmodified lines
388 const remerges = LandingState.guards.Checking(run.state)389 ? run.state.remerges390 : 0;391381 const counting = stage === "cheap" && run.counts !== undefined;392 const counting = countingLanesOf(run, stage);393383 if (!Array.isReadonlyArrayNonEmpty(lanes) && !counting) {394 if (395 !Array.isReadonlyArrayNonEmpty(lanes) &&396 !Array.isReadonlyArrayNonEmpty(counting)397 ) {398 return StageRun.cases.Ran.make({ checked, lanes: [] });399 }400401 const block = yield* runBlockOf(checked);
9 unmodified lines
411 run: block,412 })413 .pipe(Effect.flatMap((ran) => countedAskLane(run, ran)));414401 const counts = counting402 ? countFields(yield* countRatchets(run, job))415 // The ratchets are counted in the stage's own job, one container for416 // both, unless a ratchet is named as a lane is: then it runs apart.417 const together =418 !Array.isReadonlyArrayNonEmpty(lanes) || namesApart(lanes, counting);419420 const firstRun = yield* job(together ? [...lanes, ...counting] : lanes);421422 const counts = Array.isReadonlyArrayNonEmpty(counting)423 ? countFields(424 yield* countRatchets(425 run,426 counting,427 together ? firstRun : yield* job(counting)428 )429 )430 : {};431432 if (!Array.isReadonlyArrayNonEmpty(lanes)) {433 return StageRun.cases.Ran.make({
2 unmodified lines
436 ...counts,437 });438 }439413 const firstRun = yield* job(lanes);440 const first = byLane(firstRun);441442 const troubled = lanes.filter(({ lane }) =>443 isTrouble(first.results.get(lane)?.result ?? "blocked")
131 unmodified lines
modified:apps/platform/src/workflows/answer/program.ts+13 added-8 removed
243 unmodified lines
244 if (!StageRun.guards.Ran(ran)) {245 return { ran, refusals: [] };246 }247248 // Each lane's comparison is its own container job and its own step, so249 // they run at once: a step's name is its lane's, replayed or not.250 const onMain = yield* Effect.forEach(251 toCompareOnMain(ran),248 const onMain = yield* Effect.forEach(toCompareOnMain(ran), (lane) =>249 Effect.map(250 step(251 `main:${ran.checked.main}:${lane.lane}`,252 LaneOutcome,253 laneOnMain(ran.checked, lane)252 (lane) =>253 Effect.map(254 step(255 `main:${ran.checked.main}:${lane.lane}`,256 LaneOutcome,257 laneOnMain(ran.checked, lane)258 ),259 (outcome) => [lane.lane, outcome] as const260 ),255 (outcome) => [lane.lane, outcome] as const256 )261 { concurrency: "unbounded" }262 );263264 return {265 ran,
399 unmodified lines
modified:apps/platform/test/workflows/answer.fixtures.ts+37 added-2 removed
1import { RefName, RepoHost } from "@repo/artifacts/repo-host";2import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";3import { memoryFs } from "@repo/artifacts/repo-host/memory-fs";4import { CheckAt, CheckRunner, shaOf } from "@repo/checks/check-runner";5import type { CheckJob, LaneEvidence } from "@repo/checks/check-runner";5import type {6 CheckJob,7 LaneEvidence,8 LaneOutput,9} from "@repo/checks/check-runner";10import { EvidenceStoreMemory } from "@repo/checks/evidence-store/memory";11import { AlarmsMemory } from "@repo/project/alarms/memory";12import { AnswerRuns } from "@repo/project/answer-runs";13import type { AnswerReport } from "@repo/project/answer-runs";
134 unmodified lines
148 lane: LaneName,149 runs: readonly ScriptedRun[]150 ) => Effect.Effect<void>;151 readonly jobs: Effect.Effect<readonly CheckJob[]>;152 /** What a lane prints on its stdout at a tree, for a ratchet's count. */153 readonly print: (154 at: CheckAt,155 lane: LaneName,156 stdout: string157 ) => Effect.Effect<void>;158 }159>()("test/Checker") {}160161const keyOf = (at: CheckAt, lane: LaneName) => `${shaOf(at)}:${lane}`;
5 unmodified lines
167 >(new Map());168169 const served = yield* Ref.make<ReadonlyMap<string, number>>(new Map());170 const jobs = yield* Ref.make<readonly CheckJob[]>([]);171 const printed = yield* Ref.make<ReadonlyMap<string, string>>(new Map());172173 const next = (174 key: string,175 runs: Array.NonEmptyReadonlyArray<ScriptedRun>
49 unmodified lines
225 ? [{ lane: lane.lane }]226 : [{ lane: lane.lane, signature: one.signature }];227 });228218 return { durationMs: lanes.length, evidence, heldBack: [], lanes };229 const outputs = yield* Effect.map(Ref.get(printed), (texts) =>230 ran.flatMap(({ lane }): LaneOutput[] =>231 lane.output === "stdout"232 ? [233 {234 lane: lane.lane,235 stdout: texts.get(keyOf(job.at, lane.lane)) ?? "",236 },237 ]238 : []239 )240 );241242 const result = {243 durationMs: lanes.length,244 evidence,245 heldBack: [],246 lanes,247 };248249 return outputs.length === 0 ? result : { ...result, outputs };250 });251252 return Context.make(CheckRunner, { run }).pipe(253 Context.add(Checker, {254 jobs: Ref.get(jobs),255 print: (at, lane, stdout) =>256 Ref.update(printed, (texts) =>257 new Map(texts).set(keyOf(at, lane), stdout)258 ),259 script: (at, lane, runs) =>260 Ref.update(scripts, (known) =>261 new Map(known).set(keyOf(at, lane), runs)262 ),
347 unmodified lines
modified:apps/platform/test/workflows/answer.test.ts+50 added-1 removed
13 unmodified lines
14import type { Lander } from "@repo/project/lander";15import { LanderJob } from "@repo/project/lander/memory";16import { Projects } from "@repo/project/projects";17import { Verdict } from "@repo/protocol/domain/answer";18import { RatchetMeasure } from "@repo/protocol/domain/check";19import { Command, JsonPath } from "@repo/protocol/domain/common";20import { ProjectEvent } from "@repo/protocol/domain/event";21import { Outcome } from "@repo/protocol/domain/outcome";22import type { Policy } from "@repo/protocol/domain/policy";20import { keyOf, LaneName, RequestId } from "@repo/protocol/ids";23import { keyOf, LaneName, RatchetName, RequestId } from "@repo/protocol/ids";24import type { CommitSha, LandedSha } from "@repo/protocol/ids";25import {26 ChecksFailed,27 Flake,
136 unmodified lines
164 });165166const landedAt = (sha: LandedSha) => Outcome.cases.Landed.make({ sha });167168const sized = RatchetName.make("bundle-bytes");169170const sizedLane = LaneName.make(sized);171172/** The project's policy with one ratchet, read as a metric off a command's JSON. */173const withRatchet: Policy = {174 ...policy,175 ratchets: [176 {177 measure: RatchetMeasure.cases.Metric.make({178 command: Command.make("bun run size"),179 path: JsonPath.make("$.bytes"),180 }),181 name: sized,182 },183 ],184};185186const cleanAnswer = Effect.tap(admitted(), (answer) => allGreen(answer.merged));187188const withoutMessage = Layer.effect(189 Projects,
238 unmodified lines
428 }).pipe(Effect.provide(world))429 );430431 it.effect(432 "3. the cheap stage counts the policy's ratchets in its own job, one container for the lanes and the counts",433 () =>434 Effect.gen(function* () {435 const answer = yield* admitted();436437 yield* allGreen(answer.merged);438 yield* Checker.use((script) =>439 Effect.andThen(440 script.script(answer.merged, sizedLane, [{ result: "passed" }]),441 script.print(answer.merged, sizedLane, '{ "bytes": 0 }')442 )443 );444445 const outcome = yield* run(answer, yield* freshSteps());446447 expect(outcome).toStrictEqual(landedAt(yield* mainTip));448 expect(449 (yield* jobsOn(answer.merged)).map(({ lanes }) =>450 lanes.map(({ lane }) => lane)451 )452 ).toStrictEqual([453 [lint, "types", sizedLane],454 [askLane, unit],455 ]);456 }).pipe(Effect.provide(worldWith(withRatchet)))457 );458459 it.effect(460 "3. a lane that never got going and then fails on its fresh run is the answer's failure",461 () =>462 Effect.gen(function* () {463 const answer = yield* admitted();
585 unmodified lines