gate.test.ts
This file
Path
packages/gate/test/gate.test.ts
140 lines · 3.8 KiB · TypeScript
Last changed by
Merge observability into mainoscabrielbefore adoption1985111
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141import { describe, expect, it } from "@effect/vitest";import { RepoPath } from "@repo/protocol/ids";import { NotClaimed, OutOfScope, TouchedJudge } from "@repo/protocol/refusal";import type { Refusal } from "@repo/protocol/refusal";import { Effect, Option } from "effect";
import { pushStages, refusingStage, runGate } from "../src/gate.ts";import type { Stage } from "../src/stage.ts";import { ask, modified, testFacts, wire } from "./facts.ts";
const wired = (answer: Option.Option<readonly Refusal[]>) => Option.map(answer, wire);
const always = ( accumulate: boolean, refusals: readonly Refusal[]): Stage<never> => ({ accumulate, name: "cheap", run: () => Effect.succeed(refusals),});
const outside = new OutOfScope({ paths: [RepoPath.make("docs/guide.md")] });
const judged = new TouchedJudge({ paths: [RepoPath.make(".github/workflows/ci.yml")],});
describe(runGate, () => { it.effect("stops after parse when parse refuses, so shape is not heard", () => Effect.gen(function* () { const answer = yield* runGate( pushStages, testFacts({ changes: modified("docs/guide.md"), claim: Option.none(), }) );
expect(wired(answer)).toStrictEqual( Option.some(wire([NotClaimed.of(ask.id)])) ); }) );
it.effect( "returns every shape refusal when parse lets the push through", () => Effect.gen(function* () { const answer = yield* runGate( pushStages, testFacts({ changes: modified("docs/guide.md", ".github/workflows/ci.yml"), }) );
expect(wired(answer)).toStrictEqual( Option.some(wire([outside, judged])) ); }) );
it.effect("returns None when every stage lets the push through", () => Effect.gen(function* () { const answer = yield* runGate(pushStages, testFacts());
expect(answer).toStrictEqual(Option.none()); }) );
it.effect("stops a stage that does not accumulate at its first refusal", () => Effect.gen(function* () { const answer = yield* runGate( [always(false, [outside, judged]), always(true, [judged])], testFacts() );
expect(wired(answer)).toStrictEqual(Option.some(wire([outside]))); }) );
it.effect("keeps every refusal of a stage that accumulates", () => Effect.gen(function* () { const answer = yield* runGate( [always(true, []), always(true, [outside, judged])], testFacts() );
expect(wired(answer)).toStrictEqual(Option.some(wire([outside, judged]))); }) );});
describe(refusingStage, () => { it.effect("names parse when parse refuses the push", () => Effect.gen(function* () { const refused = yield* refusingStage( pushStages, testFacts({ changes: modified("docs/guide.md"), claim: Option.none(), }) );
expect(Option.map(refused, ({ stage }) => stage)).toStrictEqual( Option.some("parse") ); }) );
it.effect( "names shape, with every refusal it gave, when parse lets the push through", () => Effect.gen(function* () { const refused = yield* refusingStage( pushStages, testFacts({ changes: modified("docs/guide.md", ".github/workflows/ci.yml"), }) );
expect( Option.map(refused, ({ refusals, stage }) => ({ refusals: wire(refusals), stage, })) ).toStrictEqual( Option.some({ refusals: wire([outside, judged]), stage: "shape" }) ); }) );
it.effect("names no stage when every stage lets the push through", () => Effect.gen(function* () { expect(yield* refusingStage(pushStages, testFacts())).toStrictEqual( Option.none() ); }) );});