escapes.test.ts
This file
Path
packages/gate/test/escapes.test.ts
195 lines · 5.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–47why, one step back1import { describe, expect, it } from "@effect/vitest";2import { RatchetMeasure, RatchetSpec } from "@repo/protocol/domain/check";3import { Command } from "@repo/protocol/domain/common";4import { DecisionSubject } from "@repo/protocol/domain/decision";5import { RatchetName, RepoPath } from "@repo/protocol/ids";6import { Option } from "effect";78import {9 escapeDecisions,10 escapeRatchet,11 explainedRaises,12} from "../src/escapes.ts";13import { addedLines, ask, policy, testFacts } from "./facts.ts";1415const week = "packages/parse/src/week.ts";1617const lex = "packages/parse/src/lex.ts";1819const pad = "packages/format/src/pad.ts";2021const cast =22 "// oxlint-disable-next-line no-explicit-any -- the parser's one cast";2324const generated = "/* eslint-disable no-console -- generated tables */";2526const parseEscapes = RatchetName.make("escapes-datekit-parse");2728const waiver = (path: string, line: number, marker: string, reason: string) =>29 DecisionSubject.cases.Waiver.make({30 ask: ask.id,31 at: { line, path: RepoPath.make(path) },32 marker,33 reason,34 });3536describe(escapeRatchet, () => {37 it.each([38 ["@datekit/parse", "escapes-datekit-parse"],39 ["packages/parser", "escapes-packages-parser"],40 ["Parse_Kit", "escapes-parse-kit"],41 [".", "escapes-root"],42 ])("names %s's escape ratchet %s", (territory, name) => {43 expect(escapeRatchet(territory)).toBe(name);44 });45});4647describe(escapeDecisions, () => {Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 48why, one step back48 it("asks a maintainer about a reasoned escape in a territory with none yet", () => {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 49–70why, one step back49 expect(50 escapeDecisions(testFacts({ addedLines: addedLines([week, 4, cast]) }))51 ).toStrictEqual([52 waiver(week, 4, "oxlint-disable", "the parser's one cast"),53 ]);54 });5556 it("asks about every reasoned escape in a territory the push raises", () => {57 expect(58 escapeDecisions(59 testFacts({60 addedLines: addedLines([week, 9, generated], [week, 4, cast]),61 ratchetBaselines: new Map([[parseEscapes, 1]]),62 })63 )64 ).toStrictEqual([65 waiver(week, 4, "oxlint-disable", "the parser's one cast"),66 waiver(week, 9, "eslint-disable", "generated tables"),67 ]);68 });6970 it("asks nothing when the baseline already covers the territory's escapes after the push", () => {Merge build/maintainer-wording into mainoscabrielbefore adoption4c1a571
line 71why, one step back71 // A maintainer accepted a waiver for this answer: the baseline rose to 3Merge 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 72–195why, one step back72 // while main still holds 2, so the answer, checked again, is within it.73 expect(74 escapeDecisions(75 testFacts({76 addedLines: addedLines([week, 4, cast]),77 escapeCounts: new Map([[parseEscapes, 2]]),78 ratchetBaselines: new Map([[parseEscapes, 3]]),79 })80 )81 ).toStrictEqual([]);82 });8384 it("asks nothing when the push removes as many escapes from the territory as it adds", () => {85 expect(86 escapeDecisions(87 testFacts({88 addedLines: addedLines([week, 4, cast]),89 ratchetBaselines: new Map([[parseEscapes, 1]]),90 removedLines: addedLines([lex, 12, generated]),91 })92 )93 ).toStrictEqual([]);94 });9596 it("counts a removed escape only against its own territory", () => {97 expect(98 escapeDecisions(99 testFacts({100 addedLines: addedLines([week, 4, cast]),101 ratchetBaselines: new Map([102 [escapeRatchet("@datekit/format"), 1],103 [parseEscapes, 1],104 ]),105 removedLines: addedLines([pad, 3, generated], [lex, 7, "// x"]),106 })107 )108 ).toStrictEqual([109 waiver(week, 4, "oxlint-disable", "the parser's one cast"),110 ]);111 });112113 it("asks nothing about a marker with no reason, which shape refuses", () => {114 expect(115 escapeDecisions(116 testFacts({ addedLines: addedLines([week, 4, "// @ts-ignore"]) })117 )118 ).toStrictEqual([]);119 });120121 it("asks nothing for a push that answers no ask", () => {122 expect(123 escapeDecisions(124 testFacts({125 addedLines: addedLines([week, 4, cast]),126 ask: Option.none(),127 })128 )129 ).toStrictEqual([]);130 });131});132133describe(explainedRaises, () => {134 const anyCount = RatchetName.make("no-explicit-any");135136 const bundleKb = RatchetName.make("bundle-kb");137138 const declaring = {139 ...policy,140 ratchets: [141 RatchetSpec.make({142 measure: RatchetMeasure.cases.Count.make({143 command: Command.make("oxlint --format json"),144 rule: "typescript/no-explicit-any",145 }),146 name: anyCount,147 }),148 RatchetSpec.make({149 measure: RatchetMeasure.cases.Count.make({150 command: Command.make("oxlint --format json"),151 rule: "import/max-dependencies",152 }),153 name: bundleKb,154 }),155 ],156 };157158 it("asks to raise every declared ratchet in each reasoned escape's territory, for its reason", () => {159 expect(160 explainedRaises(declaring, ask, [161 waiver(week, 4, "oxlint-disable", "the parser's one cast"),162 waiver(pad, 2, "eslint-disable", "generated tables"),163 ])164 ).toStrictEqual([165 {166 ratchet: anyCount,167 reason: "the parser's one cast",168 territory: "@datekit/parse",169 },170 {171 ratchet: bundleKb,172 reason: "the parser's one cast",173 territory: "@datekit/parse",174 },175 {176 ratchet: anyCount,177 reason: "generated tables",178 territory: "@datekit/format",179 },180 {181 ratchet: bundleKb,182 reason: "generated tables",183 territory: "@datekit/format",184 },185 ]);186 });187188 it("asks nothing of a project that declares no ratchets", () => {189 expect(190 explainedRaises(policy, ask, [191 waiver(week, 4, "oxlint-disable", "the parser's one cast"),192 ])193 ).toStrictEqual([]);194 });195});