Skip to content
Myr

check-runner-memory.test.ts

This file

Path

packages/checks/test/check-runner-memory.test.ts

141 lines · 4.2 KiB · TypeScript

Last changed by

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

History of this file

Take it

The walk stopped after 200 commits: lines older than 678c8b8 point at it.

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 1–34why, one step back
1import { describe, expect, it } from "@effect/vitest";
2import type { LaneResult } from "@repo/protocol/domain/answer";3import { Command } from "@repo/protocol/domain/common";4import {5 CommitSha,6 LaneName,7 ProjectName,8 RepoName,9 TreeSha,10} from "@repo/protocol/ids";11import { VerifierBlocked } from "@repo/protocol/refusal";12import { Effect, Result } from "effect";1314import { CheckAt, CheckRunner } from "../src/check-runner.ts";15import type { CheckJob } from "../src/check-runner.ts";16import { CheckRunnerMemory } from "../src/check-runner/memory.ts";17import { redFirstOfRuns } from "../src/red-first.ts";1819const tree = TreeSha.make("1".repeat(40));2021const main = CommitSha.make("2".repeat(40));2223const unit = LaneName.make("unit");2425const lint = LaneName.make("lint");2627const onTree = CheckAt.cases.Tree.make({ tree });2829const onMain = CheckAt.cases.Commit.make({ commit: main });3031const job = (at: CheckAt, ...lanes: readonly LaneName[]): CheckJob => ({32 at,33 lanes: lanes.map((lane) => ({ command: `bun run ${lane}`, lane })),34 placeholders: [],

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 35why, one step back
35 project: ProjectName.make("oscabriel/datekit"),

Merge build/614-env-service: deciders set write-only values for @sensitive items, the public sees the env shape, and checks see only placeholdersoscabrielbefore adoption678c8b8

lines 36–141why, one step back
36 proxies: [],
37 repo: RepoName.make("datekit"),38 run: { checks: {}, test: Command.make("bun test {path}") },39});4041const ran = (42 lane: LaneName,43 result: LaneResult["result"],44 durationMs: number45): LaneResult => ({ command: `bun run ${lane}`, durationMs, lane, result });4647const run = (each: CheckJob) =>48 Effect.flatMap(CheckRunner, (runner) => runner.run(each));4950describe(CheckRunnerMemory.layer, () => {51 it.effect(52 "returns the scripted results for a tree and lane in order, then repeats the last",53 () =>54 Effect.gen(function* () {55 const runs = yield* Effect.all(56 [57 run(job(onTree, unit)),58 run(job(onTree, unit)),59 run(job(onTree, unit)),60 ],61 { concurrency: 1 }62 );6364 expect(runs.map(({ lanes }) => lanes)).toStrictEqual([65 [ran(unit, "failed", 30)],66 [ran(unit, "passed", 20)],67 [ran(unit, "passed", 20)],68 ]);69 }).pipe(70 Effect.provide(71 CheckRunnerMemory.layer(72 new Map([73 [74 `${tree}:${unit}`,75 [ran(unit, "failed", 30), ran(unit, "passed", 20)],76 ],77 ])78 )79 )80 )81 );8283 it.effect(84 "keeps one script per tree or commit and lane, and totals the run's time",85 () =>86 Effect.gen(function* () {87 const onBoth = yield* run(job(onTree, unit, lint));88 const onMainAlone = yield* run(job(onMain, unit));8990 expect(onBoth).toStrictEqual({91 durationMs: 40,92 evidence: [{ lane: lint, signature: "lint: scripted failure" }],93 heldBack: [],94 lanes: [ran(unit, "passed", 30), ran(lint, "failed", 10)],95 });96 expect(onMainAlone.lanes).toStrictEqual([ran(unit, "loadError", 5)]);97 expect(onMainAlone.evidence).toStrictEqual([{ lane: unit }]);98 }).pipe(99 Effect.provide(100 CheckRunnerMemory.layer(101 new Map([102 [`${tree}:${unit}`, [ran(unit, "passed", 30)]],103 [`${tree}:${lint}`, [ran(lint, "failed", 10)]],104 [`${main}:${unit}`, [ran(unit, "loadError", 5)]],105 ])106 )107 )108 )109 );110111 it.effect("makes two scripted failures on main red first", () =>112 Effect.gen(function* () {113 const first = yield* run(job(onMain, unit));114 const second = yield* run(job(onMain, unit));115116 expect(redFirstOfRuns([first, second], unit)).toStrictEqual(117 Result.succeed({ lane: unit, signature: "unit: scripted failure" })118 );119 }).pipe(120 Effect.provide(121 CheckRunnerMemory.layer(122 new Map([[`${main}:${unit}`, [ran(unit, "failed", 30)]]])123 )124 )125 )126 );127128 it.effect("is VerifierBlocked for a tree and lane it has no script for", () =>129 Effect.gen(function* () {130 const blocked = yield* Effect.flip(run(job(onTree, unit, lint)));131132 expect(blocked).toStrictEqual(new VerifierBlocked({}));133 }).pipe(134 Effect.provide(135 CheckRunnerMemory.layer(136 new Map([[`${tree}:${unit}`, [ran(unit, "passed", 30)]]])137 )138 )139 )140 );141});