Skip to content
Myr

loop.ts

This file

Path

scripts/lib/smoke/loop.ts

318 lines · 7.9 KiB · TypeScript

Last changed by

Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b

History of this file

Take it

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

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

line 1why, one step back
1import { Brand } from "@repo/brand";

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 2–3why, one step back
2import { keyOf, ProjectName } from "@repo/protocol/ids";
3import type { Handle, LandedSha } from "@repo/protocol/ids";

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 4–18why, one step back
4import {
5 Console,6 DateTime,7 Duration,8 Effect,9 FileSystem,10 Option,11 Schema,12} from "effect";13import type { Redacted } from "effect";14import type { ChildProcessSpawner } from "effect/process";1516import { recordCreated } from "../../../infra/created.ts";17import type { Created } from "../../../infra/created.ts";18import {

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

lines 19–23why, one step back
19 declaredStage,
20 publicStages,21 resources,22} from "../../../infra/stages.ts";23import {

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 24–28why, one step back
24 awaitLanding,
25 claimAsk,26 initProject,27 LoopFailed,28 openAsk,

Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b

line 29why, one step back
29 openDiscussion,

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

line 30why, one step back
30 personAt,

Merge build/1007oscabrielbefore adoption77fa97a

line 31why, one step back
31 projectIsFree,

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 32–40why, one step back
32 pushAnswer,
33 pushOutOfScope,34 readLanding,35 readVerdictNote,36} from "./core-loop.ts";37import type { LoopStep, Patience } from "./core-loop.ts";3839export { LoopFailed, LoopStep } from "./core-loop.ts";40

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

lines 41–43why, one step back
41// A throwaway project would show on a public stage's front page.
42export class PublicStageRefused extends Schema.TaggedError<PublicStageRefused>()(43 "PublicStageRefused",

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 44–126why, one step back
44 { stage: Schema.String }
45) {46 override get message() {47 return `--loop makes a throwaway project, which would show on ${this.stage}'s front page: run it on a dev stage`;48 }49}5051export interface StepTiming {52 readonly step: LoopStep;53 readonly ms: number;54}5556export interface SmokeLoopReport {57 readonly project: ProjectName;58 readonly refusedWith: readonly string[];59 readonly landed: LandedSha;60 readonly author: string;61 readonly committer: string;62 readonly trailers: readonly string[];63 readonly noteFound: boolean;64 readonly timings: readonly StepTiming[];65}6667export interface LoopInput {68 readonly stage: string;69 readonly run: string;70 readonly origin: string;71 readonly decider: Redacted.Redacted;72 readonly answerer: Redacted.Redacted;73 readonly patience?: Patience;74}7576const PATIENCE: Patience = {77 every: Duration.seconds(2),78 within: Duration.minutes(10),79};8081const timed =82 (stage: string, step: LoopStep) =>83 <A, R>(84 self: Effect.Effect<A, LoopFailed, R>85 ): Effect.Effect<readonly [A, StepTiming], LoopFailed, R> =>86 Effect.timed(self).pipe(87 Effect.map(([elapsed, value]) => {88 const ms = Math.round(Duration.toMillis(elapsed));8990 return [value, { ms, step }] as const;91 }),92 Effect.tap(([, { ms }]) =>93 Console.log(`smoke ${stage}: loop ${step} passed in ${ms} ms`)94 )95 );9697const recordThrowaway = (stage: string, kind: Created["kind"], name: string) =>98 Effect.gen(function* () {99 const namespace = Option.map(100 declaredStage(stage),101 (declared) => resources(declared).projects102 );103104 const entry: Created = {105 at: yield* DateTime.now,106 by: "smoke",107 kind,108 name,109 stage,110 };111112 yield* recordCreated(113 kind === "repo" && Option.isSome(namespace)114 ? { ...entry, namespace: namespace.value }115 : entry116 );117 }).pipe(118 Effect.mapError(119 ({ message }) =>120 new LoopFailed({121 reason: `the throwaway ledger: ${message}`,122 step: kind === "project" ? "init" : "claim",123 })124 )125 );126

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 127–128why, one step back
127const projectOf = (decider: Handle, run: string) =>
128 Schema.decodeEffect(ProjectName)(`${decider}/smoke-${run}`).pipe(

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 129–131why, one step back
129 Effect.mapError(
130 () =>131 new LoopFailed({

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

line 132why, one step back
132 reason: `${decider}/smoke-${run} is no project name: a run is lowercase words joined by dashes`,

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 133–141why, one step back
133 step: "init",
134 })135 )136 );137138export const smokeLoop = (139 input: LoopInput140): Effect.Effect<141 SmokeLoopReport,

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

line 142why, one step back
142 LoopFailed | PublicStageRefused,

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 143–147why, one step back
143 ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem
144> =>145 Effect.gen(function* () {146 const { origin, stage } = input;147

Add a prod stage served on the brand's own domainoscabrielbefore adoption78a5062

line 148why, one step back
148 if (publicStages.has(stage)) {

Merge infra/drop-demo into mainoscabrielbefore adoptionc49b6bf

line 149why, one step back
149 return yield* new PublicStageRefused({ stage });

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 150–183why, one step back
150 }
151152 const fs = yield* FileSystem.FileSystem;153154 const dir = yield* fs155 .makeTempDirectoryScoped({ prefix: `smoke-${input.run}-` })156 .pipe(157 Effect.mapError(158 ({ message }) =>159 new LoopFailed({160 reason: `a folder for the run: ${message}`,161 step: "people",162 })163 )164 );165166 const [{ answerer, decider }, people] = yield* timed(167 stage,168 "people"169 )(170 Effect.all({171 answerer: personAt({172 home: `${dir}/answerer`,173 origin,174 token: input.answerer,175 }),176 decider: personAt({177 home: `${dir}/decider`,178 origin,179 token: input.decider,180 }),181 })182 );183

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 184–185why, one step back
184 const project = yield* projectOf(decider.handle, input.run);
185

Merge build/comments-ops into mainoscabrielbefore adoptione4c407e

lines 186–188why, one step back
186 // Checked free, then recorded, then made: an init that makes the project
187 // and then fails still leaves it in the ledger, and a name someone else188 // holds never enters teardown's plan.

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 189–192why, one step back
189 const [, init] = yield* timed(
190 stage,191 "init"192 )(

Merge build/1007oscabrielbefore adoption77fa97a

lines 193–194why, one step back
193 Effect.gen(function* () {
194 yield* projectIsFree(decider, project);

Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8

lines 195–196why, one step back
195 yield* recordThrowaway(stage, "project", keyOf(project));
196 yield* recordThrowaway(stage, "repo", keyOf(project));

Merge build/1007oscabrielbefore adoption77fa97a

lines 197–204why, one step back
197
198 return yield* initProject({199 answerer: answerer.handle,200 decider,201 dir: `${dir}/start`,202 project,203 });204 })

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 205–206why, one step back
205 );
206

Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b

lines 207–211why, one step back
207 const [discussion, talked] = yield* timed(
208 stage,209 "discussion"210 )(openDiscussion(answerer, project));211

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 212–214why, one step back
212 const [, opened] = yield* timed(
213 stage,214 "open-ask"

Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b

line 215why, one step back
215 )(openAsk({ decider, discussion, project }));

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 216–295why, one step back
216
217 const [claim, claimed] = yield* timed(218 stage,219 "claim"220 )(221 claimAsk(answerer, project).pipe(222 Effect.tap(({ fork }) => recordThrowaway(stage, "repo", fork))223 )224 );225226 const work = `${answerer.home}/answer`;227228 const [refusedWith, refused] = yield* timed(229 stage,230 "out-of-scope"231 )(pushOutOfScope({ answerer, claim, dir: work }));232233 const [head, answered] = yield* timed(234 stage,235 "answer"236 )(pushAnswer(answerer, work));237238 const [{ landed, read }, landing] = yield* timed(239 stage,240 "landing"241 )(242 Effect.gen(function* () {243 const sha = yield* awaitLanding({244 answerer,245 head,246 patience: input.patience ?? PATIENCE,247 project,248 });249250 const found = yield* readLanding({251 answerer,252 dir: work,253 landed: sha,254 origin,255 project,256 });257258 const wanted = [259 ["author", found.author, answerer.handle],260 // The platform commits every landing under its own name.261 ["committer", found.committer, Brand.name],262 ] as const;263264 for (const [what, got, expected] of wanted) {265 if (got !== expected) {266 return yield* new LoopFailed({267 reason: `the landing ${sha}'s ${what} is ${got}, not ${expected}`,268 step: "landing",269 });270 }271 }272273 const missing = [274 `Asked-by: ${decider.handle} `,275 `Signed-off-by: ${answerer.handle} `,276 ].filter(277 (prefix) => !found.trailers.some((line) => line.startsWith(prefix))278 );279280 if (missing.length > 0) {281 return yield* new LoopFailed({282 reason: `the landing ${sha} lacks ${missing.map((prefix) => prefix.trim()).join(" and ")}: its trailers are ${found.trailers.join("; ") || "none"}`,283 step: "landing",284 });285 }286287 return { landed: sha, read: found };288 })289 );290291 const [, noted] = yield* timed(292 stage,293 "verdict-note"294 )(readVerdictNote({ answerer, dir: work, head }));295

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 296–298why, one step back
296 const timings = [
297 people,298 init,

Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b

line 299why, one step back
299 talked,

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

lines 300–307why, one step back
300 opened,
301 claimed,302 refused,303 answered,304 landing,305 noted,306 ];307

Merge project/drop-proposals into mainoscabrielbefore adoptionb4ed08b

line 308why, one step back
308 return {

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 309–314why, one step back
309 author: read.author,
310 committer: read.committer,311 landed,312 noteFound: true,313 project,314 refusedWith,

Merge branch 'build/910-draft-workflow'oscabrielbefore adoptiona0c8f4f

line 315why, one step back
315 timings,

Start the Checker's containers on standard-3, so burrow's lint lane runs, and record the dev stage's live core looposcabrielbefore adoptionc7b68ff

lines 316–318why, one step back
316 trailers: read.trailers,
317 };318 }).pipe(Effect.scoped);