Skip to content
Myr

admission-steps.ts

This file

Path

apps/platform/src/workflows/admission-steps.ts

179 lines · 4.9 KiB · TypeScript

Last changed by

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

History of this file

Take it

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

Merge build/comments-platform into mainoscabrielbefore adoptionddf09e8

lines 1–2why, one step back
1// Steps record only the plan's outline and each run's area bits, never a check's
2// file, path or name: the sealed files go from the project to the Checker alone.

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 3–8why, one step back
3import { CheckAt, CheckRunner } from "@repo/checks/check-runner";
4import { noRunEnv } from "@repo/project/env-port";5import { Projects } from "@repo/project/projects";6import { AdmissionRun } from "@repo/project/visibility-port";7import type { AdmissionPlan } from "@repo/project/visibility-port";8import { HeldBackResult } from "@repo/protocol/domain/answer";

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 9–15why, one step back
9import {
10 AreaName,11 CommitSha,12 keyOf,13 LandedSha,14 RepoName,15} from "@repo/protocol/ids";

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

line 16why, one step back
16import { Array as Arr, Effect, Option, Schema } from "effect";

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 17–19why, one step back
17
18import type { AdmissionParams } from "../answer-runs.ts";19import { StepRunner } from "./step.ts";

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

line 20why, one step back
20import type { StepRetry } from "./step.ts";

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

line 21why, one step back
21

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 22–61why, one step back
22const RunRef = Schema.TaggedUnion({
23 OnKnownBad: { area: AreaName, tree: CommitSha },24 OnMain: { area: AreaName, attempt: Schema.Int },25});2627type RunRef = typeof RunRef.Type;2829const Outline = Schema.Struct({30 main: LandedSha,31 runs: Schema.Array(RunRef),32});3334type Outline = typeof Outline.Type;3536const Ran = Schema.TaggedUnion({37 Bits: { areas: Schema.Array(HeldBackResult) },38 Gone: {},39});4041type Ran = typeof Ran.Type;4243const admissionRetry: StepRetry = {44 backoff: "exponential",45 delayMs: 10_000,46 limit: 3,47};4849const RUNS_AT_ONCE = 4;5051const refOf = (run: AdmissionRun): RunRef =>52 AdmissionRun.guards.OnMain(run)53 ? RunRef.cases.OnMain.make({ area: run.area, attempt: run.attempt })54 : RunRef.cases.OnKnownBad.make({ area: run.area, tree: run.tree });5556const nameOf = (ref: RunRef) =>57 RunRef.match(ref, {58 OnKnownBad: ({ area, tree }) => `admission:${area}:known-bad:${tree}`,59 OnMain: ({ area, attempt }) => `admission:${area}:main#${attempt}`,60 });61

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 62–63why, one step back
62export const admissionSteps = (
63 params: AdmissionParams

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

line 64why, one step back
64): Effect.Effect<void, never, CheckRunner | Projects | StepRunner> =>

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 65–66why, one step back
65 Effect.gen(function* () {
66 const { step } = yield* StepRunner;

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 67–68why, one step back
67 const runner = yield* CheckRunner;
68 const projects = yield* Projects;

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

line 69why, one step back
69

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 70–79why, one step back
70 const planNow = projects.get(params.project).pipe(
71 Effect.flatMap((api) =>72 api.admissionPlan({ head: params.head, layer: params.layer })73 ),74 Effect.catchTag("UnknownProject", () =>75 Effect.succeed(Option.none<AdmissionPlan>())76 )77 );7879 const outline = yield* step(

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

line 80why, one step back
80 "admission:plan",

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 81–86why, one step back
81 Schema.Option(Outline),
82 Effect.map(planNow, (plan) =>83 Option.map(plan, ({ main, runs }): Outline => ({84 main,85 runs: runs.map(refOf),86 }))

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 87–89why, one step back
87 )
88 );89

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 90–118why, one step back
90 if (Option.isNone(outline)) {
91 yield* Effect.logInfo("nothing to admit");9293 return;94 }9596 const { main } = outline.value;9798 const runOne = (ref: RunRef) =>99 step(100 nameOf(ref),101 Ran,102 Effect.gen(function* () {103 const plan = yield* planNow;104105 const found = Option.flatMap(plan, ({ runs }) =>106 Arr.findFirst(runs, (run) => nameOf(refOf(run)) === nameOf(ref))107 );108109 if (Option.isNone(plan) || Option.isNone(found)) {110 return Ran.cases.Gone.make({});111 }112113 const ran = yield* runner.run({114 ...noRunEnv,115 at: CheckAt.cases.Commit.make({ commit: CommitSha.make(main) }),116 heldBack: found.value.job,117 lanes: [],118 project: params.project,

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 119why, one step back
119 repo: RepoName.make(keyOf(params.project)),

Merge build/615-admission-runs: a sealed check enters the suite only after it passes main three times, catches a known-bad tree, and cites its clauseoscabrielbefore adoptionc6defde

lines 120–179why, one step back
120 run: plan.value.run,
121 });122123 return Ran.cases.Bits.make({ areas: ran.heldBack });124 }),125 admissionRetry126 ).pipe(Effect.option);127128 const ran = yield* Effect.forEach(129 outline.value.runs,130 (ref) =>131 Effect.map(runOne(ref), (result) => [nameOf(ref), result] as const),132 { concurrency: RUNS_AT_ONCE }133 );134135 if (ran.some(([, result]) => Option.isNone(result))) {136 yield* Effect.logWarning(137 "the Checker could not run an admission's checks: the push stays proposed"138 );139140 return;141 }142143 const bits = new Map(144 ran.flatMap(([name, result]) =>145 Option.match(result, {146 onNone: () => [],147 onSome: (each) =>148 Ran.guards.Bits(each) ? [[name, each.areas] as const] : [],149 })150 )151 );152153 yield* step(154 "admission:judge",155 Schema.Boolean,156 Effect.gen(function* () {157 const plan = yield* planNow;158159 if (Option.isNone(plan)) {160 return false;161 }162163 const api = yield* Effect.orDie(projects.get(params.project));164165 yield* api.recordAdmission({166 head: params.head,167 layer: params.layer,168 results: plan.value.runs.flatMap((run) =>169 Option.match(Option.fromUndefinedOr(bits.get(nameOf(refOf(run)))), {170 onNone: () => [],171 onSome: (areas) => [{ areas, run }],172 })173 ),174 });175176 return true;177 })178 );179 }).pipe(Effect.annotateLogs({ head: params.head, layer: params.layer }));