classify.test.ts
This file
Path
packages/gate/test/classify.test.ts
135 lines · 3.6 KiB · TypeScript
Last changed by
Merge build/comments-packages-rest into mainoscabrielbefore adoption38cd503
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136import { describe, expect, it } from "@effect/vitest";import { LaneName, RepoPath } from "@repo/protocol/ids";import { ChecksFailed, Flake, StaleBase, VerifierBlocked,} from "@repo/protocol/refusal";import type { Refusal } from "@repo/protocol/refusal";import { Option } from "effect";
import { classifyFailure } from "../src/classify.ts";import type { LaneEvidence } from "../src/classify.ts";import { base, main, wire } from "./facts.ts";
const unit = LaneName.make("unit");
const week = RepoPath.make("packages/parse/src/week.ts");
const pad = RepoPath.make("packages/format/src/pad.ts");
const changed: ReadonlySet<RepoPath> = new Set([week]);
const red: LaneEvidence = { command: "bun run test", failingPaths: [week], isDoctor: false, lane: unit, logRef: "logs/datekit/unit-2222222", onMain: "passed", onMerged: "failed", rerun: Option.none(),};
const rows: readonly { readonly name: string; readonly evidence: LaneEvidence; readonly refusal: Option.Option<Refusal>;}[] = [ { evidence: red, name: "passes on main, fails on merged inside the diff", refusal: Option.some( new ChecksFailed({ lane: unit, logRef: "logs/datekit/unit-2222222", next: "bun run test", }) ), }, { evidence: { ...red, rerun: Option.some("failed") }, name: "fails again the same way on a fresh run", refusal: Option.some( new ChecksFailed({ lane: unit, logRef: "logs/datekit/unit-2222222", next: "bun run test", }) ), }, { evidence: { ...red, failingPaths: [] }, name: "fails on merged with no file named", refusal: Option.some( new ChecksFailed({ lane: unit, logRef: "logs/datekit/unit-2222222", next: "bun run test", }) ), }, { evidence: { ...red, rerun: Option.some("passed") }, name: "fails, then passes on a fresh run of the same tree", refusal: Option.some(new Flake({ lane: unit })), }, { evidence: { ...red, onMerged: "blocked" }, name: "the checker could not start, which earns one fresh run", refusal: Option.some(new Flake({ lane: unit })), }, { evidence: { ...red, onMerged: "blocked", rerun: Option.some("blocked") }, name: "the checker could not start twice on a tree whose main passes", refusal: Option.some( new ChecksFailed({ lane: unit, logRef: "logs/datekit/unit-2222222", next: "bun run test", }) ), }, { evidence: { ...red, onMain: "blocked", onMerged: "blocked" }, name: "the checker could not start on main either, so no fresh run is spent", refusal: Option.some(new VerifierBlocked({})), }, { evidence: { ...red, command: "bun run doctor", isDoctor: true, lane: LaneName.make("doctor"), onMain: "failed", }, name: "the doctor lane fails on main", refusal: Option.some(new VerifierBlocked({})), }, { evidence: { ...red, onMain: "failed" }, name: "the lane fails on main too", refusal: Option.some(new VerifierBlocked({})), }, { evidence: { ...red, failingPaths: [pad] }, name: "fails on merged outside the diff, on a lane that passes on main", refusal: Option.some(new StaleBase({ base, conflicts: [], main })), }, { evidence: { ...red, onMerged: "passed" }, name: "passes on merged", refusal: Option.none(), },];
describe(classifyFailure, () => { it.each(rows)("$name", ({ evidence, refusal }) => { const found = classifyFailure(evidence, changed, { base, main });
expect(Option.map(found, (one) => wire([one]))).toStrictEqual( Option.map(refusal, (one) => wire([one])) ); });});