Skip to content
Myr

local.ts

This file

Path

packages/checks/src/check-runner/local.ts

169 lines · 5.7 KiB · TypeScript

Last changed by

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

History of this file

Take 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–3why, one step back
1// Placeholders and proxies are the Checker's: here a lane sees the user's own
2// env. A sealed suite runs only in the Checker, so a job with one is3// `VerifierBlocked`.

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 4–78why, one step back
4import { VerifierBlocked } from "@repo/protocol/refusal";
5import { Duration, Effect, FileSystem, Layer, Option, Stream } from "effect";6import type { Scope } from "effect";7import { ChildProcess, ChildProcessSpawner } from "effect/process";89import { CheckRunner, evidenceFrom } from "../check-runner.ts";10import type { CheckAt, CheckLane, LaneOutput } from "../check-runner.ts";11import { classifyRun } from "../classify.ts";12import type { RunExit } from "../classify.ts";1314export interface LocalOptions {15 readonly checkout: (16 at: CheckAt17 ) => Effect.Effect<string, VerifierBlocked, Scope.Scope>;18}1920const DEFAULT_TIMEOUT = Duration.minutes(10);2122const FORCE_KILL_AFTER = Duration.seconds(2);2324// Fixed identity and dates, English messages, no prompts, no colours, and no25// git config from this machine. A git hook that runs the CLI exports where26// its own repo is and any `git -c` config; those are unset (an `undefined`27// value leaves a variable out), so a lane's git sees only the checkout.28const fixedEnv = {29 CI: "1",30 FORCE_COLOR: "0",31 GIT_ALTERNATE_OBJECT_DIRECTORIES: undefined,32 GIT_AUTHOR_DATE: "2026-10-06T12:00:00Z",33 GIT_AUTHOR_EMAIL: "answerer@example.com",34 GIT_AUTHOR_NAME: "Answerer",35 GIT_COMMITTER_DATE: "2026-10-06T12:00:00Z",36 GIT_COMMITTER_EMAIL: "answerer@example.com",37 GIT_COMMITTER_NAME: "Answerer",38 GIT_COMMON_DIR: undefined,39 GIT_CONFIG: undefined,40 GIT_CONFIG_COUNT: undefined,41 GIT_CONFIG_GLOBAL: "/dev/null",42 GIT_CONFIG_NOSYSTEM: "1",43 GIT_CONFIG_PARAMETERS: undefined,44 GIT_DIR: undefined,45 GIT_INDEX_FILE: undefined,46 GIT_NAMESPACE: undefined,47 GIT_OBJECT_DIRECTORY: undefined,48 GIT_PREFIX: undefined,49 GIT_TERMINAL_PROMPT: "0",50 GIT_WORK_TREE: undefined,51 LC_ALL: "C",52 NO_COLOR: "1",53};5455const text = <E>(bytes: Stream.Stream<Uint8Array, E>) =>56 bytes.pipe(Stream.decodeText(), Stream.mkString);5758const timedOut: RunExit = { code: -1, stderr: "", stdout: "", timedOut: true };5960const printed = (lane: CheckLane, exit: RunExit): readonly LaneOutput[] =>61 lane.output === "stdout" && exit.timedOut !== true62 ? [{ lane: lane.lane, stdout: exit.stdout }]63 : [];6465export const CheckRunnerLocal = {66 layer: (67 options: LocalOptions68 ): Layer.Layer<69 CheckRunner,70 never,71 ChildProcessSpawner.ChildProcessSpawner | FileSystem.FileSystem72 > =>73 Layer.effect(74 CheckRunner,75 Effect.gen(function* () {76 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;77 const fs = yield* FileSystem.FileSystem;78

Merge build/comments-cli-protocol-checks into mainoscabrielbefore adoptionc86204f

lines 79–80why, one step back
79 // A process a signal ended has no exit code: -1. The scope's close kills its
80 // process group.

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 81–169why, one step back
81 const exitOf = (cwd: string, home: string, lane: CheckLane) =>
82 Effect.scoped(83 Effect.gen(function* () {84 const child = yield* spawner.spawn(85 ChildProcess.make("sh", ["-c", lane.command], {86 cwd,87 env: { ...fixedEnv, HOME: home, TMPDIR: home },88 extendEnv: true,89 forceKillAfter: FORCE_KILL_AFTER,90 })91 );9293 const [stdout, stderr, code] = yield* Effect.all(94 [95 text(child.stdout),96 text(child.stderr),97 child.exitCode.pipe(98 Effect.map(Number),99 Effect.orElseSucceed(() => -1)100 ),101 ],102 { concurrency: "unbounded" }103 );104105 return { code, stderr, stdout } satisfies RunExit;106 })107 ).pipe(108 Effect.timeoutOption(109 lane.timeoutMs === undefined110 ? DEFAULT_TIMEOUT111 : Duration.millis(lane.timeoutMs)112 ),113 Effect.map(Option.getOrElse(() => timedOut)),114 Effect.mapError(() => new VerifierBlocked({}))115 );116117 const runLane = (cwd: string, home: string, lane: CheckLane) =>118 Effect.map(119 Effect.timed(exitOf(cwd, home, lane)),120 ([elapsed, exit]) => ({121 exit,122 outputs: printed(lane, exit),123 result: {124 command: lane.command,125 durationMs: Math.round(Duration.toMillis(elapsed)),126 lane: lane.lane,127 result: classifyRun(lane.lane, exit),128 },129 })130 );131132 return CheckRunner.of({133 run: (job) =>134 Effect.scoped(135 Effect.gen(function* () {136 if (job.heldBack !== undefined) {137 return yield* new VerifierBlocked({});138 }139140 const cwd = yield* options.checkout(job.at);141142 const home = yield* fs143 .makeTempDirectoryScoped({ prefix: "check-home-" })144 .pipe(Effect.mapError(() => new VerifierBlocked({})));145146 const [elapsed, ran] = yield* Effect.timed(147 Effect.forEach(job.lanes, (lane) => runLane(cwd, home, lane))148 );149150 const outputs = ran.flatMap((each) => each.outputs);151152 const done = {153 durationMs: Math.round(Duration.toMillis(elapsed)),154 evidence: ran.flatMap(({ exit, result }) =>155 result.result === "passed"156 ? []157 : [evidenceFrom(result.lane, exit)]158 ),159 heldBack: [],160 lanes: ran.map(({ result }) => result),161 };162163 return outputs.length === 0 ? done : { ...done, outputs };164 })165 ),166 });167 })168 ),169};