classify.ts
This file
Path
packages/gate/src/classify.ts
76 lines · 2.4 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
The walk stopped after 200 commits: lines older than 678c8b8 point at it.
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
line 1why, one step back1/**Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
line 2why, one step back2 * Only a lane that passes on main and fails on the merged tree, in a file theMerge 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–29why, one step back3 * answer changed or in none it can name, is the answer's failure.4 */5import type { LaneResult } from "@repo/protocol/domain/answer";6import type { CommitSha, LaneName, RepoPath } from "@repo/protocol/ids";7import {8 ChecksFailed,9 Flake,10 StaleBase,11 VerifierBlocked,12} from "@repo/protocol/refusal";13import { Option } from "effect";1415export interface LaneEvidence {16 readonly lane: LaneName;17 readonly onMain: LaneResult["result"];18 readonly onMerged: LaneResult["result"];19 readonly rerun: Option.Option<LaneResult["result"]>;20 readonly failingPaths: readonly RepoPath[];21 readonly logRef: string;22 readonly command: string;23 readonly isDoctor: boolean;24}2526const isTrouble = (result: LaneResult["result"]) =>27 result === "flaked" || result === "blocked";2829/**Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
lines 30–33why, one step back30 * A lane red on main too is `VerifierBlocked`. A checker that never started31 * on a tree whose main passes earns one fresh run (`Flake`); an identical32 * second failure means it was never a flake, so it counts as the answer's. A33 * failure only outside the diff is `StaleBase`.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 34–76why, one step back34 */35export const classifyFailure = (36 evidence: LaneEvidence,37 changedPaths: ReadonlySet<RepoPath>,38 merge: { readonly base: CommitSha; readonly main: CommitSha }39): Option.Option<ChecksFailed | Flake | VerifierBlocked | StaleBase> => {40 if (evidence.isDoctor && evidence.onMain !== "passed") {41 return Option.some(new VerifierBlocked({}));42 }4344 if (evidence.onMerged === "passed") {45 return Option.none();46 }4748 // The result that stands: the fresh run's, once there is one.49 const result = Option.getOrElse(evidence.rerun, () => evidence.onMerged);5051 if (Option.isSome(evidence.rerun) && result === "passed") {52 return Option.some(new Flake({ lane: evidence.lane }));53 }5455 if (evidence.onMain !== "passed") {56 return Option.some(new VerifierBlocked({}));57 }5859 if (isTrouble(result) && Option.isNone(evidence.rerun)) {60 return Option.some(new Flake({ lane: evidence.lane }));61 }6263 const outsideOnly =64 evidence.failingPaths.length > 0 &&65 evidence.failingPaths.every((path) => !changedPaths.has(path));6667 return Option.some(68 outsideOnly69 ? new StaleBase({ base: merge.base, conflicts: [], main: merge.main })70 : new ChecksFailed({71 lane: evidence.lane,72 logRef: evidence.logRef,73 next: evidence.command,74 })75 );76};