Skip to content
Myr

red-first.ts

This file

Path

packages/checks/src/red-first.ts

83 lines · 2.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// A check that fails to load fails because its subject is missing, and any
2// answer that exports the subject could pass it; a check that fails two3// different ways is flaky.

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–77why, one step back
4import type { LaneName } from "@repo/protocol/ids";
5import { NotRedFirst, WeakCheck } from "@repo/protocol/refusal";6import { Data, Option, Result } from "effect";78import type { CheckRun } from "./check-runner.ts";9import { diagnose, Diagnosis } from "./classify.ts";10import type { RunExit } from "./classify.ts";1112export interface RunEvidence {13 readonly lane: LaneName;14 readonly exit: RunExit;15}1617export interface RedSignature {18 readonly signature: string;19 readonly lane: LaneName;20}2122type Reading =23 | { readonly _tag: "Red"; readonly signature: string }24 | { readonly _tag: "NoTests" }25 | { readonly _tag: "NotRed" };2627const Reading = Data.taggedEnum<Reading>();2829const readExit = (exit: RunExit): Reading =>30 Diagnosis.$match(diagnose(exit), {31 Blocked: () => Reading.NotRed(),32 Failed: ({ signature }) =>33 Option.match(signature, {34 onNone: () => Reading.NotRed(),35 onSome: (text) => Reading.Red({ signature: text }),36 }),37 LoadError: () => Reading.NotRed(),38 NoTests: () => Reading.NoTests(),39 Passed: () => Reading.NotRed(),40 });4142const readRun = (run: CheckRun, lane: LaneName): Reading => {43 const result = run.lanes.find((each) => each.lane === lane)?.result;44 const evidence = run.evidence.find((each) => each.lane === lane);4546 if (evidence?.weakness === "no assertion") {47 return Reading.NoTests();48 }4950 return result === "failed" && evidence?.signature !== undefined51 ? Reading.Red({ signature: evidence.signature })52 : Reading.NotRed();53};5455const judge = (56 lane: LaneName,57 [first, second]: readonly [Reading, Reading]58): Result.Result<RedSignature, NotRedFirst | WeakCheck> => {59 if (Reading.$is("NoTests")(first) || Reading.$is("NoTests")(second)) {60 return Result.fail(new WeakCheck({ weakness: "no assertion" }));61 }6263 return Reading.$is("Red")(first) &&64 Reading.$is("Red")(second) &&65 first.signature === second.signature66 ? Result.succeed({ lane, signature: first.signature })67 : Result.fail(new NotRedFirst({}));68};6970export const redFirst = ([first, second]: readonly [71 RunEvidence,72 RunEvidence,73]): Result.Result<RedSignature, NotRedFirst | WeakCheck> =>74 first.lane === second.lane75 ? judge(first.lane, [readExit(first.exit), readExit(second.exit)])76 : Result.fail(new NotRedFirst({}));77

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

line 78why, one step back
78// The platform never sees a run's output, only its evidence signature.

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 79–83why, one step back
79export const redFirstOfRuns = (
80 [first, second]: readonly [CheckRun, CheckRun],81 lane: LaneName82): Result.Result<RedSignature, NotRedFirst | WeakCheck> =>83 judge(lane, [readRun(first, lane), readRun(second, lane)]);