parse.test.ts
This file
Path
packages/gate/test/parse.test.ts
261 lines · 7.6 KiB · TypeScript
Last changed by
Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
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
lines 1–55why, one step back1import { describe, expect, it } from "@effect/vitest";2import { RefNameText } from "@repo/protocol/domain/common";3import { LayerName, ProjectName } from "@repo/protocol/ids";4import { Anonymous, Person } from "@repo/protocol/principal";5import {6 CapReached,7 ClaimLapsed,8 Denounced,9 DirectPush,10 NoAsk,11 NotClaimed,12 NotVouched,13} from "@repo/protocol/refusal";14import type { Refusal } from "@repo/protocol/refusal";15import { Effect, Option } from "effect";1617import { PushTarget } from "../src/facts.ts";18import type { PushFacts } from "../src/facts.ts";19import { parse } from "../src/stages/parse.ts";20import {21 alice,22 ask,23 bob,24 carol,25 claim,26 dana,27 mallory,28 policy,29 testFacts,30 wire,31} from "./facts.ts";3233const danasPush = (mode: PushFacts["policy"]["vouch"]["mode"]) =>34 testFacts({35 claim: Option.some({ ...claim, claimant: dana }),36 policy: { ...policy, vouch: { ...policy.vouch, mode } },37 pusher: Person.make({ handle: dana }),38 target: PushTarget.ClaimFork({39 ask: ask.id,40 claimant: dana,41 project: ask.project,42 }),43 });4445const danasWorkingForkPush = (mode: PushFacts["policy"]["vouch"]["mode"]) =>46 testFacts({47 ask: Option.none(),48 claim: Option.none(),49 policy: { ...policy, vouch: { ...policy.vouch, mode } },50 pusher: Person.make({ handle: dana }),51 target: PushTarget.WorkingFork({ owner: dana, project: ask.project }),52 });5354const main = RefNameText.make("refs/heads/main");55Merge build/1103 into mainoscabrielbefore adoption9c64f9b
lines 56–57why, one step back56const tag = RefNameText.make("refs/tags/v1");57Merge 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 58–157why, one step back58const rows: readonly {59 readonly name: string;60 readonly facts: PushFacts;61 readonly refusals: readonly Refusal[];62}[] = [63 {64 facts: testFacts(),65 name: "the claimant's push to their fork",66 refusals: [],67 },68 {69 facts: testFacts({ claim: Option.none() }),70 name: "a push to an ask no one has claimed",71 refusals: [NotClaimed.of(ask.id)],72 },73 {74 facts: testFacts({ claim: Option.some({ ...claim, state: "lapsed" }) }),75 name: "a push on a lapsed claim",76 refusals: [ClaimLapsed.of(ask.id)],77 },78 {79 facts: testFacts({ pusher: Person.make({ handle: carol }) }),80 name: "a push to someone else's claim fork",81 refusals: [NotClaimed.of(ask.id)],82 },83 {84 facts: testFacts({85 pusher: Person.make({ handle: carol }),86 target: PushTarget.ClaimFork({87 ask: ask.id,88 claimant: carol,89 project: ask.project,90 }),91 }),92 name: "a push to a fork in the pusher's name while another holds the claim",93 refusals: [NotClaimed.of(ask.id)],94 },95 {96 facts: testFacts({ claim: Option.some({ ...claim, state: "released" }) }),97 name: "a push on a released claim",98 refusals: [NotClaimed.of(ask.id)],99 },100 {101 facts: testFacts({ pusher: Anonymous.make({}) }),102 name: "a push with no person behind it",103 refusals: [NotClaimed.of(ask.id)],104 },105 {106 facts: testFacts({ pusher: Person.make({ handle: mallory }) }),107 name: "a push by a denounced person",108 refusals: [new Denounced({})],109 },110 // The claim already passed the kind's `claimers` rule (`mayClaim`), which111 // may admit an unvouched person (an `anyone` kind, a record, a mentor), so112 // a push to the claim's own fork does not judge the vouch again.113 {114 facts: danasPush("forCode"),115 name: "an unvouched claimant's push to their claim's fork when code needs a vouch",116 refusals: [],117 },118 {119 facts: danasPush("all"),120 name: "an unvouched claimant's push to their claim's fork when everything needs a vouch",121 refusals: [],122 },123 {124 facts: danasWorkingForkPush("forCode"),125 name: "an unvouched person's push to their working fork when code needs a vouch",126 refusals: [new NotVouched({})],127 },128 {129 facts: danasWorkingForkPush("bansOnly"),130 name: "an unvouched person's push to their working fork when only denouncements count",131 refusals: [],132 },133 {134 facts: testFacts({135 policy: {136 ...policy,137 vouches: [{ denounced: false, handle: mallory }, ...policy.vouches],138 },139 pusher: Person.make({ handle: mallory }),140 }),141 name: "a push by a person the vouch file both vouches for and denounces",142 refusals: [new Denounced({})],143 },144 {145 facts: testFacts({146 pusher: Person.make({ handle: mallory }),147 target: PushTarget.Canonical({ project: ask.project }),148 }),149 name: "a push to canonical main, even by a denounced person",150 refusals: [new DirectPush({ ref: main })],151 },152 {153 facts: testFacts({154 pusher: Person.make({ handle: alice }),155 ref: RefNameText.make("refs/heads/release"),156 target: PushTarget.Canonical({ project: ask.project }),157 }),Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 158why, one step back158 name: "a maintainer's push to another canonical branch",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 159–175why, one step back159 refusals: [new DirectPush({ ref: "refs/heads/release" })],160 },161 {162 facts: testFacts({ ask: Option.none() }),163 name: "a push to a claim fork whose ask is not open",164 refusals: [new NoAsk({})],165 },166 {167 facts: testFacts({ ask: Option.some({ ...ask, state: "closed" }) }),168 name: "a push to a claim fork whose ask has closed",169 refusals: [new NoAsk({})],170 },171 {172 facts: testFacts({173 target: PushTarget.ClaimFork({174 ask: ask.id,175 claimant: bob,Merge build/1400-w14-foundation into mainoscabrielbefore adoption47dd2f8
line 176why, one step back176 project: ProjectName.make("oscabriel/timekit"),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 177–198why, one step back177 }),178 }),179 name: "a push to another project's fork of an ask with the same name",180 refusals: [new NoAsk({})],181 },182 {183 facts: testFacts({ claimsHeld: 4 }),184 name: "a push by a claimant above the cap a landing lowered",185 refusals: [new CapReached({ cap: 3 })],186 },187 {188 facts: testFacts({ claimsHeld: 3 }),189 name: "a push by a claimant at the cap",190 refusals: [],191 },192 {193 facts: testFacts({194 ask: Option.none(),195 claim: Option.none(),196 pusher: Person.make({ handle: alice }),197 target: PushTarget.WorkingFork({ owner: alice, project: ask.project }),198 }),Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 199why, one step back199 name: "a maintainer's push to their own working fork (maintainers vouch, so need none)",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 200–222why, one step back200 refusals: [],201 },202 {203 facts: testFacts({204 ask: Option.none(),205 claim: Option.none(),206 target: PushTarget.WorkingFork({ owner: alice, project: ask.project }),207 }),208 name: "a push to another person's working fork",209 refusals: [new DirectPush({ ref: main })],210 },211 {212 facts: testFacts({213 ask: Option.none(),214 claim: Option.none(),215 pusher: Person.make({ handle: alice }),216 target: PushTarget.Layer({217 layer: LayerName.make("maintainers"),218 project: ask.project,219 }),220 }),221 name: "a push to a layer's repo, which W6 opens to its writers",222 refusals: [new DirectPush({ ref: main })],Merge build/1103 into mainoscabrielbefore adoption9c64f9b
lines 223–249why, one step back223 },224 {225 facts: testFacts({ ref: tag }),226 name: "the claimant's push of a tag to their claim's fork",227 refusals: [new DirectPush({ ref: tag })],228 },229 {230 facts: testFacts({231 ask: Option.none(),232 claim: Option.none(),233 pusher: Person.make({ handle: alice }),234 ref: tag,235 target: PushTarget.WorkingFork({ owner: alice, project: ask.project }),236 }),237 name: "an owner's push of a tag to their own working fork",238 refusals: [new DirectPush({ ref: tag })],239 },240 {241 facts: testFacts({242 ask: Option.none(),243 claim: Option.none(),244 pusher: Person.make({ handle: alice }),245 ref: RefNameText.make("refs/heads/wip"),246 target: PushTarget.WorkingFork({ owner: alice, project: ask.project }),247 }),248 name: "an owner's push of another branch to their own working fork",249 refusals: [],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 250–261why, one step back250 },251];252253describe("parse: who may push what", () => {254 it.effect.each(rows)("$name", ({ facts, refusals }) =>255 Effect.gen(function* () {256 const found = yield* parse.run(facts);257258 expect(wire(found)).toStrictEqual(wire(refusals));259 })260 );261});