phases.ts
This file
Path
packages/checks/src/phases.ts
96 lines · 2.6 KiB · TypeScript
Last changed by
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
lines 1–2why, one step back1// `Snapshot` must come before held-back files are written: a snapshot taken2// after them would carry them into the next Sandbox.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 3–44why, one step back3import type { RunBlock } from "@repo/protocol/domain/run";4import type { AreaName, EnvKey, LaneName } from "@repo/protocol/ids";5import { Data, Hash, Option } from "effect";67export interface PlannedLane {8 readonly lane: LaneName;9 readonly command: string;10}1112/**13 * One phase. This is the union `Data.TaggedEnum` would build; it is written14 * out because the lint refuses the `{}` members `EgressOff` and `Report`15 * would need there.16 */17export type Phase =18 | {19 readonly _tag: "Setup";20 readonly command: string;21 readonly egress: readonly string[];22 }23 | { readonly _tag: "Snapshot"; readonly key: string }24 | { readonly _tag: "EgressOff" }25 | { readonly _tag: "WriteHeldBack"; readonly areas: readonly AreaName[] }26 | {27 readonly _tag: "Run";28 readonly lanes: readonly PlannedLane[];29 readonly placeholders: readonly EnvKey[];30 }31 | { readonly _tag: "Report" };3233export const Phase = Data.taggedEnum<Phase>();3435export interface PlanInput {36 readonly run: RunBlock;37 readonly lanes: readonly PlannedLane[];38 readonly heldBack: Option.Option<{ readonly areas: readonly AreaName[] }>;39 readonly placeholders: readonly EnvKey[];40 readonly lockfileHash: string;41}4243const DEFAULT_IMAGE = "checker:default";44Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f
line 45why, one step back45// Reused only for the same image, setup command, setup hosts and lockfile.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 46–96why, one step back46const snapshotKey = (47 run: RunBlock,48 command: string,49 egress: readonly string[],50 lockfileHash: string51) => {52 const image = run.image ?? DEFAULT_IMAGE;5354 // Hash.string is a fixed function of its input (djb2), so the key is too.55 const setupHash = Math.abs(56 Hash.string(JSON.stringify([image, command, egress]))57 ).toString(16);5859 return `setup:${lockfileHash}:${setupHash}`;60};6162export const phasePlan = ({63 heldBack,64 lanes,65 lockfileHash,66 placeholders,67 run,68}: PlanInput): readonly Phase[] => {69 const install: readonly Phase[] =70 run.setup === undefined71 ? []72 : [73 Phase.Setup({ command: run.setup, egress: run.setupEgress ?? [] }),74 Phase.Snapshot({75 key: snapshotKey(76 run,77 run.setup,78 run.setupEgress ?? [],79 lockfileHash80 ),81 }),82 ];8384 const sealed: readonly Phase[] = Option.match(heldBack, {85 onNone: () => [],86 onSome: ({ areas }) => [Phase.WriteHeldBack({ areas })],87 });8889 return [90 ...install,91 Phase.EgressOff(),92 ...sealed,93 Phase.Run({ lanes, placeholders }),94 Phase.Report(),95 ];96};