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
Provenance
- Commit
8c56f70- Tree
5ae4382- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
081fd0f
4 files changed+148 added−33 removed
modified:apps/platform/src/workflows/answer/lanes.ts+48 added-22 removed
305 unmodified lines306 readonly counts: readonly MeasuredCount[];307 readonly uncounted: Option.Option<RatchetName>;308 }309 310+/** What the lane running a command printed, or nothing. */311+const 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+ );320+321+/** The ratchets' counts, read from the lanes a run printed. */310-const countRatchets = <E, R>(322+const 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 ?? [];329 330 if (!Array.isReadonlyArrayNonEmpty(specs)) {331 return { counts: [], uncounted: Option.none() };332 }333 321- const lanes = countLanes(specs);334+ const printed = printedBy(lanes, ran);335 323- const ran = yield* job(lanes);324-325- 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- );335-336 const counts = yield* Effect.forEach(specs, (spec) =>337 measure(338 spec,339 (command) => Effect.succeed({ code: 0, stdout: printed(command) }),6 unmodified lines346 onSuccess: (all) => ({ counts: all.flat(), uncounted: Option.none() }),347 });348 });349 350+/** The ratchets' lanes, counted in the cheap stage. */351+const countingLanesOf = (run: AnswerRun, stage: Stage): readonly CheckLane[] =>352+ stage === "cheap" && run.counts !== undefined353+ ? countLanes(run.counts.ratchets)354+ : [];355+356+const namesApart = (357+ lanes: readonly CheckLane[],358+ counting: readonly CheckLane[]359+) => counting.every((count) => lanes.every(({ lane }) => lane !== count.lane));360+361 const 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 lines388 const remerges = LandingState.guards.Checking(run.state)389 ? run.state.remerges390 : 0;391 381- const counting = stage === "cheap" && run.counts !== undefined;392+ const counting = countingLanesOf(run, stage);393 383- 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 }400 401 const block = yield* runBlockOf(checked);9 unmodified lines411 run: block,412 })413 .pipe(Effect.flatMap((ran) => countedAskLane(run, ran)));414 401- 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);419+420+ const firstRun = yield* job(together ? [...lanes, ...counting] : lanes);421+422+ const counts = Array.isReadonlyArrayNonEmpty(counting)423+ ? countFields(424+ yield* countRatchets(425+ run,426+ counting,427+ together ? firstRun : yield* job(counting)428+ )429+ )430 : {};431 432 if (!Array.isReadonlyArrayNonEmpty(lanes)) {433 return StageRun.cases.Ran.make({2 unmodified lines436 ...counts,437 });438 }439 413- const firstRun = yield* job(lanes);440 const first = byLane(firstRun);441 442 const troubled = lanes.filter(({ lane }) =>443 isTrouble(first.results.get(lane)?.result ?? "blocked")131 unmodified linesmodified:apps/platform/src/workflows/answer/program.ts+13 added-8 removed
243 unmodified lines244 if (!StageRun.guards.Ran(ran)) {245 return { ran, refusals: [] };246 }247 248+ // 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 );263 264 return {265 ran,399 unmodified linesmodified:apps/platform/test/workflows/answer.fixtures.ts+37 added-2 removed
1 import { RefName, RepoHost } from "@repo/artifacts/repo-host";2 import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";3 import { memoryFs } from "@repo/artifacts/repo-host/memory-fs";4 import { CheckAt, CheckRunner, shaOf } from "@repo/checks/check-runner";5-import type { CheckJob, LaneEvidence } from "@repo/checks/check-runner";5+import type {6+ CheckJob,7+ LaneEvidence,8+ LaneOutput,9+} from "@repo/checks/check-runner";10 import { EvidenceStoreMemory } from "@repo/checks/evidence-store/memory";11 import { AlarmsMemory } from "@repo/project/alarms/memory";12 import { AnswerRuns } from "@repo/project/answer-runs";13 import type { AnswerReport } from "@repo/project/answer-runs";134 unmodified lines148 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") {}160 161 const keyOf = (at: CheckAt, lane: LaneName) => `${shaOf(at)}:${lane}`;5 unmodified lines167 >(new Map());168 169 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());172 173 const next = (174 key: string,175 runs: Array.NonEmptyReadonlyArray<ScriptedRun>49 unmodified lines225 ? [{ lane: lane.lane }]226 : [{ lane: lane.lane, signature: one.signature }];227 });228 218- 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+ );241+242+ const result = {243+ durationMs: lanes.length,244+ evidence,245+ heldBack: [],246+ lanes,247+ };248+249+ return outputs.length === 0 ? result : { ...result, outputs };250 });251 252 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 linesmodified:apps/platform/test/workflows/answer.test.ts+50 added-1 removed
13 unmodified lines14 import type { Lander } from "@repo/project/lander";15 import { LanderJob } from "@repo/project/lander/memory";16 import { Projects } from "@repo/project/projects";17 import { Verdict } from "@repo/protocol/domain/answer";18+import { RatchetMeasure } from "@repo/protocol/domain/check";19+import { Command, JsonPath } from "@repo/protocol/domain/common";20 import { ProjectEvent } from "@repo/protocol/domain/event";21 import { Outcome } from "@repo/protocol/domain/outcome";22+import type { Policy } from "@repo/protocol/domain/policy";20-import { keyOf, LaneName, RequestId } from "@repo/protocol/ids";23+import { keyOf, LaneName, RatchetName, RequestId } from "@repo/protocol/ids";24 import type { CommitSha, LandedSha } from "@repo/protocol/ids";25 import {26 ChecksFailed,27 Flake,136 unmodified lines164 });165 166 const landedAt = (sha: LandedSha) => Outcome.cases.Landed.make({ sha });167 168+const sized = RatchetName.make("bundle-bytes");169+170+const sizedLane = LaneName.make(sized);171+172+/** The project's policy with one ratchet, read as a metric off a command's JSON. */173+const 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+};185+186 const cleanAnswer = Effect.tap(admitted(), (answer) => allGreen(answer.merged));187 188 const withoutMessage = Layer.effect(189 Projects,238 unmodified lines428 }).pipe(Effect.provide(world))429 );430 431 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();436+437+ 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+ );444+445+ const outcome = yield* run(answer, yield* freshSteps());446+447+ 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+ );458+459+ 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