Skip to content
Myr

push-check.ts

This file

Path

apps/cli/src/hook/push-check.ts

152 lines · 4.4 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–2why, one step back
1// A port, so the hook never imports the check command's modules. Offline, the check cannot read the
2// claim's base itself, so it is passed: main would be the wrong start for work committed on main.

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–28why, one step back
3import { Envelope } from "@repo/protocol/envelope";
4import type { Refusal } from "@repo/protocol/refusal";5import {6 Context,7 Duration,8 Effect,9 Layer,10 Option,11 Schema,12 Stream,13} from "effect";14import { ChildProcess, ChildProcessSpawner } from "effect/process";1516export class PushCheckFailed extends Schema.TaggedError<PushCheckFailed>()(17 "PushCheckFailed",18 { reason: Schema.String }19) {20 override get message() {21 return `the local check gave no answer: ${this.reason}`;22 }23}2425export class PushCheck extends Context.Service<26 PushCheck,27 {28 readonly run: (

Close W7: cross-compile the release again, guard pi's edits, and keep the swarm out of this checkoutoscabrielbefore adoption842f042

lines 29–30why, one step back
29 root: string,
30 base: string

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 31–45why, one step back
31 ) => Effect.Effect<readonly Refusal[], PushCheckFailed>;
32 }33>()("cli/PushCheck") {}3435const CHECK = ["check", "--shape-only", "--offline", "--json"] as const;3637const LIMIT = Duration.minutes(1);3839const decodeEnvelope = Schema.decodeUnknownEffect(40 Schema.fromJsonString(Envelope(Schema.Unknown))41);4243const text = <E>(bytes: Stream.Stream<Uint8Array, E>) =>44 bytes.pipe(Stream.decodeText(), Stream.mkString);45

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

line 46why, one step back
46/** A refusal ends with the refusal's exit code, but the envelope says all, so only the envelope is read. */

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 47–55why, one step back
47export const pushCheckWith = (
48 command: readonly [string, ...string[]]49): Layer.Layer<PushCheck, never, ChildProcessSpawner.ChildProcessSpawner> =>50 Layer.effect(51 PushCheck,52 Effect.gen(function* () {53 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;54 const [executable, ...leading] = command;55

Close W7: cross-compile the release again, guard pi's edits, and keep the swarm out of this checkoutoscabrielbefore adoption842f042

line 56why, one step back
56 const run = (root: string, base: string) =>

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 57–59why, one step back
57 Effect.scoped(
58 Effect.gen(function* () {59 const child = yield* spawner.spawn(

Close W7: cross-compile the release again, guard pi's edits, and keep the swarm out of this checkoutoscabrielbefore adoption842f042

lines 60–68why, one step back
60 ChildProcess.make(
61 executable,62 [...leading, ...CHECK, "--base", base],63 {64 cwd: root,65 stderr: "ignore",66 stdin: "ignore",67 }68 )

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 69–116why, one step back
69 );
7071 const [stdout] = yield* Effect.all(72 [text(child.stdout), child.exitCode],73 { concurrency: "unbounded" }74 );7576 return stdout;77 })78 ).pipe(79 Effect.timeoutOrElse({80 duration: LIMIT,81 orElse: () =>82 Effect.fail(83 new PushCheckFailed({84 reason: `it ran past ${Duration.format(LIMIT)}`,85 })86 ),87 }),88 Effect.catchTag("PlatformError", (failure) =>89 Effect.fail(new PushCheckFailed({ reason: failure.message }))90 ),91 Effect.flatMap((stdout) =>92 decodeEnvelope(stdout.trim()).pipe(93 Effect.mapError(94 () =>95 new PushCheckFailed({96 reason: "it printed no envelope on stdout",97 })98 )99 )100 ),101 Effect.map((envelope): readonly Refusal[] =>102 envelope.ok ? [] : envelope.refusals103 )104 );105106 return { run };107 })108 );109110const Started = Schema.Struct({111 argv: Schema.Array(Schema.String),112 execPath: Schema.NonEmptyString,113});114115const GlobalScope = Schema.Struct({ process: Started });116

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

line 117why, one step back
117/** A compiled binary is its own executable: its entry lives in Bun's embedded `/$bunfs/` or `B:/~BUN/`. */

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 118–152why, one step back
118export const selfCommand = (
119 started: typeof Started.Type120): readonly [string, ...string[]] => {121 const [, entry] = started.argv;122123 return entry === undefined ||124 entry.startsWith("/$bunfs/") ||125 entry.startsWith("B:/~BUN/")126 ? [started.execPath]127 : [started.execPath, entry];128};129130export const PushCheckChild: Layer.Layer<131 PushCheck,132 never,133 ChildProcessSpawner.ChildProcessSpawner134> = Layer.unwrap(135 Effect.sync(() => {136 // Unknown on purpose: the runtime is whatever started this process.137 const scope: unknown = globalThis;138139 return Option.match(Schema.decodeUnknownOption(GlobalScope)(scope), {140 onNone: () =>141 Layer.succeed(PushCheck)({142 run: () =>143 Effect.fail(144 new PushCheckFailed({145 reason: "this runtime does not say how the CLI was started",146 })147 ),148 }),149 onSome: ({ process }) => pushCheckWith(selfCommand(process)),150 });151 })152);