Judge check's ratchets with the platform's own judge, and print finish with the ask first on the web
Before adoption: this commit came in with the history the project adopted, so no landing records it.
- Review of 516. The Check said to reuse the platform's code, not copy it, but `check` carried three copies: `judgeMoves` copied `judgeRatchets`, `countLanes` copied the platform's count-lane building, and `askedRaises` copied the Project DO's escape-to-raise mapping. Each now has one home that both sides import, so `check`'s `Weakened` and waits cannot drift from the gateway's. - `@repo/checks/kinds/ratchet` now holds `countLanes`, `judgeRatchets` (moved from `@repo/project/ratchets`, unchanged), `RaiseRatchet`, `RatchetJudgement`, `RatchetKey` and `sameRatchet`. That module stays pure: it imports `CheckLane` from the port as a type only. The platform's cheap stage (`lanes.ts`), the Project DO and `check` call them all. `@repo/project/ratchets` keeps only the baselines (`afterLanding`, `decideRaise`). - `@repo/gate/escapes` gains `explainedRaises(policy, ask, waivers)` and `RaiseRequest` (moved from project): a reasoned escape in a territory explains a raise of every declared ratchet there. `project.ts` and `check` both use it. - `check`'s `RatchetMove.ratchet` is now a `RatchetName`, not a bare string (principle 2). `check` notes each `RaiseRatchet` the judge would open. - `apps/web` finish view prints `finish <ask> --project …`. Before, it taught `--ask`, the hidden alias that ends after a release. - `PROVENANCE.md`'s `cli.ts` row now records `formerFlags`. - Tests: `packages/checks/test/kinds/ratchet.test.ts` gains `countLanes` (one lane per command, named for its first ratchet; none for no ratchets) and the `judgeRatchets` cases, moved from project with the function. `packages/gate/test/escapes.test.ts` gains `explainedRaises` (every declared ratchet in each escape's territory, with its reason; none without ratchets). `apps/web/test/finish.test.tsx` expects `finish parse-iso --project datekit`; it was red first by assertion. The project's model test still drives the moved judge. A planted bug that dropped one explained raise turned `check`'s escape case red.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+433 added−345 removed
- tests:+220 added−112 removed
- other:+213 added−233 removed
Provenance
- Commit
ec99d7e- Tree
fd4c99e- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
7f1a273
13 files changed+433 added−345 removed
modified:apps/cli/src/local/check.ts+6 added-12 removed
73 unmodified lines74 ConfigBundler,75 ConfigBundlerBun,76 localPolicy,77 } from "./local-policy.ts";78-import {79- askedRaises,80- countRatchets,81- judgeMoves,82- RatchetMove,83-} from "./ratchets.ts";78+import { countRatchets, judgeMoves, RatchetMove } from "./ratchets.ts";79 import { staleGenerated } from "./stale.ts";80 import type { StaleCopy } from "./stale.ts";81 82 const COMMAND = "check";718 unmodified lines801 }802 803 // The ratchets, counted on the base and on HEAD as the platform's804 // cheap stage counts them, unless `--lane` asked for lanes alone.810- const counting =811- Array.isReadonlyArrayNonEmpty(policy.ratchets) &&812- flags.lane.length === 0;805+ const declared = Array.isReadonlyArrayNonEmpty(policy.ratchets);806+ const counting = declared && flags.lane.length === 0;807 814- if (Array.isReadonlyArrayNonEmpty(policy.ratchets) && !counting) {808+ if (declared && !counting) {809 yield* output.note(810 "The ratchets were not counted: --lane runs only the lanes it names."811 );812 }13 unmodified lines826 `Could not count the ratchet ${ratchet} here: ${why}. The platform counts it after the push.`827 );828 }829 836- const ratcheted = judgeMoves(counts.moves, askedRaises(facts));830+ const ratcheted = judgeMoves(facts, ask.value, counts.moves);831 838- for (const move of ratcheted.waiting) {832+ for (const move of ratcheted.decisions) {833 yield* output.note(834 `The ratchet ${moveText(move)}: a reasoned escape you add there asks a decider to raise it, so the answer will wait on that decision.`835 );836 }27 unmodified linesmodified:apps/cli/src/local/ratchets.ts+46 added-100 removed
1 /**2 * `check`'s ratchets: the project's ratchets counted on this machine, on the3 * tree an answer started from and on the answer's own, by the count lanes4- * the platform's cheap stage runs (one per command, from the run block, each4+ * the platform's cheap stage runs (`countLanes`, from the run block, each5 * handing back its stdout) and read by the platform's own counting code6- * (`measure` in `@repo/checks/kinds/ratchet`); then judged as the Project DO7- * judges an answer's counts, with the base's counts standing in for the8- * baselines, which no contract serves (a landing leaves each baseline at6+ * (`measure`); then judged by the Project DO's own `judgeRatchets` (all three7+ * in `@repo/checks/kinds/ratchet`), with the base's counts standing in for8+ * the baselines, which no contract serves (a landing leaves each baseline at9 * what main then counts). A count over its base's is `Weakened{ratchet}`,10 * unless a reasoned escape the answer adds in that territory asks a decider11- * to raise it: then the answer will wait on that decision instead.11+ * to raise it (`explainedRaises` in `@repo/gate/escapes`): then the answer12+ * will wait on that decision instead.13 *14 * A ratchet this machine cannot count (its command prints nothing the15 * counter reads, or the tree could not be checked out and set up) is named16 * with why, and left to the platform: it never fails `check`.17 */18+import { CheckAt, CheckRunner, outputOf } from "@repo/checks/check-runner";19+import type { CheckLane, CheckRun } from "@repo/checks/check-runner";20 import {18- CheckAt,19- CheckLane,20- CheckRunner,21- outputOf,22-} from "@repo/checks/check-runner";23-import type { CheckRun } from "@repo/checks/check-runner";24-import { measure } from "@repo/checks/kinds/ratchet";25-import type { RatchetCount } from "@repo/checks/kinds/ratchet";26-import { escapeDecisions, territoryOf } from "@repo/gate/escapes";21+ countLanes,22+ judgeRatchets,23+ measure,24+ sameRatchet,25+} from "@repo/checks/kinds/ratchet";26+import type {27+ RatchetCount,28+ RatchetJudgement,29+} from "@repo/checks/kinds/ratchet";30+import { escapeDecisions, explainedRaises } from "@repo/gate/escapes";31 import type { PushFacts } from "@repo/gate/facts";32 import type { LaneOutcome } from "@repo/protocol/domain/answer";29-import type { RatchetSpec } from "@repo/protocol/domain/check";33+import type { Ask } from "@repo/protocol/domain/ask";34 import type { Policy } from "@repo/protocol/domain/policy";31-import { LaneName } from "@repo/protocol/ids";32-import type {33- CommitSha,34- ProjectName,35- RatchetName,36- RepoName,37-} from "@repo/protocol/ids";38-import { Weakened } from "@repo/protocol/refusal";35+import { RatchetName } from "@repo/protocol/ids";36+import type { CommitSha, ProjectName, RepoName } from "@repo/protocol/ids";37 import { Array, Effect, Option, Result, Schema } from "effect";38 39 /** One ratchet's count in one territory, on the answer's base and on its head. */40 export const RatchetMove = Schema.Struct({41 after: Schema.Int,42 before: Schema.Int,45- ratchet: Schema.String,43+ ratchet: RatchetName,44 territory: Schema.String,45 });46 47 export type RatchetMove = typeof RatchetMove.Type;9 unmodified lines57 readonly moves: readonly RatchetMove[];58 readonly uncounted: readonly Uncounted[];59 }60 63-/** The answer's counts judged: what refuses it, and the raises it will wait on. */64-export interface LocalJudgement {65- readonly refusals: readonly Weakened[];66- readonly waiting: readonly RatchetMove[];67-}68-69-/** A ratchet in a territory: the key a baseline and a raise are kept by. */70-interface Keyed {71- readonly ratchet: string;72- readonly territory: string;73-}74-75-const sameRatchet =76- (one: Keyed) =>77- (other: Keyed): boolean =>78- one.ratchet === other.ratchet && one.territory === other.territory;79-80-/**81- * The lanes that count `ratchets`, as the platform's cheap stage makes82- * them: one per command, named for the first ratchet that runs it, each83- * handing back what it printed.84- */85-const countLanes = (ratchets: readonly RatchetSpec[]): readonly CheckLane[] =>86- Array.dedupeWith(87- ratchets,88- (one, other) => one.measure.command === other.measure.command89- ).map(({ measure: { command }, name }) =>90- CheckLane.make({ command, lane: LaneName.make(name), output: "stdout" })91- );92-61 /** How a count lane that printed no count ended, in words. */62 const endings = {63 blocked: "it never ran here, or ran out of time",64 failed: "it failed",142 unmodified lines207 return { moves, uncounted };208 });209 210 /**243- * The raises a push asks a decider for, as the Project DO reads them: each244- * reasoned escape it adds over its territory's escape count (a `Waiver`)245- * asks to raise every declared ratchet in that territory.211+ * The answer's counts judged by the Project DO's own `judgeRatchets`, with212+ * each count on the base as the baseline and the raises the push's reasoned213+ * escapes explain, as the Project DO reads them from the same facts: a count214+ * over its base's is refused `Weakened{ratchet}`, unless the answer asks to215+ * raise that ratchet in that territory, when it waits on a decider instead216+ * (`decisions`).217 */247-export const askedRaises = (facts: PushFacts): readonly Keyed[] =>248- Option.match(facts.ask, {249- onNone: () => [],250- onSome: (ask) =>251- escapeDecisions(facts).flatMap((waiver) =>252- facts.policy.ratchets.map(({ name }) => ({253- ratchet: name,254- territory: territoryOf(facts.policy, ask, waiver.at.path),255- }))256- ),257- });258-259-/**260- * The answer's counts judged as the platform's `judgeRatchets` judges them,261- * with each count on the base as the baseline: one over it is refused262- * `Weakened{ratchet}`, unless the answer asks to raise that ratchet in that263- * territory, when it waits on a decider instead.264- */218 export const judgeMoves = (266- moves: readonly RatchetMove[],267- raises: readonly Keyed[]268-): LocalJudgement => {269- const raised = moves.filter(({ after, before }) => after > before);270-271- const asked = (move: RatchetMove) => raises.some(sameRatchet(move));272-273- return {274- refusals: raised.flatMap((move) =>275- asked(move)276- ? []277- : [278- new Weakened({279- weakening: {280- after: move.after,281- before: move.before,282- ratchet: move.ratchet,283- territory: move.territory,284- },285- }),286- ]287- ),288- waiting: raised.filter(asked),289- };290-};219+ facts: PushFacts,220+ ask: Ask,221+ moves: readonly RatchetMove[]222+): RatchetJudgement =>223+ judgeRatchets({224+ ask: ask.id,225+ baselines: moves.map(({ before, ratchet, territory }) => ({226+ count: before,227+ ratchet,228+ territory,229+ })),230+ measured: moves.map(({ after, ratchet, territory }) => ({231+ count: after,232+ ratchet,233+ territory,234+ })),235+ raises: explainedRaises(facts.policy, ask, escapeDecisions(facts)),236+ });modified:apps/platform/src/workflows/answer/lanes.ts+2 added-7 removed
23 unmodified lines24 } from "@repo/checks/check-runner";25 import type { CheckRun, LaneEvidence } from "@repo/checks/check-runner";26 import { EvidenceStore } from "@repo/checks/evidence-store";27 import { lintToZeroCount } from "@repo/checks/kinds/lint-to-zero";28-import { measure } from "@repo/checks/kinds/ratchet";28+import { countLanes, measure } from "@repo/checks/kinds/ratchet";29 import { classifyFailure } from "@repo/gate/classify";30 import { MeasuredCount, runBlockOf } from "@repo/project/answer-runs";31 import type { AnswerRun } from "@repo/project/answer-runs";32 import { LandingState } from "@repo/project/landing";361 unmodified lines394 if (!Array.isReadonlyArrayNonEmpty(specs)) {395 return { counts: [], uncounted: Option.none() };396 }397 398- const lanes = Array.dedupeWith(399- specs,400- (one, other) => one.measure.command === other.measure.command401- ).map(({ measure: { command }, name }) =>402- CheckLane.make({ command, lane: LaneName.make(name), output: "stdout" })403- );398+ const lanes = countLanes(specs);399 400 const ran = yield* job(lanes);401 402 const printed = (command: string) =>207 unmodified linesmodified:apps/web/src/features/finish/finish-view.tsx+1 added-1 removed
51 unmodified lines52 const base = verdict?.base ?? "<base>";53 54 return {55 fetch: [`git fetch ${remote} ${head}`, "git switch --detach FETCH_HEAD"],56- finish: `${Brand.cli} finish --project ${decision.project} --ask ${ask} --base ${base} --head $(git rev-parse HEAD) --requestId finish-$(git rev-parse HEAD) --yes`,56+ finish: `${Brand.cli} finish ${ask} --project ${decision.project} --base ${base} --head $(git rev-parse HEAD) --requestId finish-$(git rev-parse HEAD) --yes`,57 push: `git push ${remote} HEAD:main`,58 };59 };60 158 unmodified linesmodified:apps/web/test/finish.test.tsx+1 added-3 removed
219 unmodified lines220 const text = textOf(element);221 222 expect(text).toContain(`git fetch ${PLATFORM_URL}/`);223 expect(text).toContain(` ${head}`);224- expect(text).toContain(225- `${Brand.cli} finish --project datekit --ask parse-iso`226- );224+ expect(text).toContain(`${Brand.cli} finish parse-iso --project datekit`);225 expect(markupOf(element)).not.toContain("<diffs-container");226 expect(markupOf(element)).not.toContain('data-diff="');227 });228 86 unmodified linesmodified:packages/checks/src/kinds/ratchet.ts+107 added-8 removed
1234567234567891011121314151613141718192021222324252694 unmodified lines121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216/** * The `ratchet` check kind's measure: run a ratchet's declared command once * and read its number per territory, exactly as the project's own tool * reports it. A lint count splits by path, so it yields one count per * territory (per-territory baselines, so the children of a split land on * their own; FE §8.4 B3); a metric is one number, so it yields one. The * command runs through the runner it is given, never here. * The `ratchet` check kind: the lanes that count a project's ratchets, the * measure that reads a ratchet's declared command's output as its number * per territory, exactly as the project's own tool reports it, and the * judgement of an answer's counts against the counts it is held to. A lint * count splits by path, so it yields one count per territory (per-territory * baselines, so the children of a split land on their own; FE §8.4 B3); a * metric is one number, so it yields one. The command runs through the * runner it is given, never here. The platform's cheap stage and the Project * DO, and `<cli> check` before a push, all count and judge through here. */import { RatchetMeasure } from "@repo/protocol/domain/check";import type { RatchetSpec } from "@repo/protocol/domain/check";import { Glob } from "@repo/protocol/domain/common";import { DecisionSubject } from "@repo/protocol/domain/decision";import type { Territory } from "@repo/protocol/domain/territory";import type { RatchetName } from "@repo/protocol/ids";import { Effect } from "effect";import { LaneName } from "@repo/protocol/ids";import type { AskId, RatchetName } from "@repo/protocol/ids";import { Weakened } from "@repo/protocol/refusal";import { Array, Effect, Option } from "effect";
import type { CheckLane } from "../check-runner.ts";import { countLint, countWithin } from "./lint-count.ts";import type { CountUnreadable } from "./lint-count.ts";import { readMetric } from "./metric.ts";
94 unmodified lines }, ]) ), });
/** * The lanes that count `ratchets`: one per command, named for the first * ratchet that runs it, each handing back what it printed for `measure` to * read (a lint's exit code says nothing of its count). */export const countLanes = ( ratchets: readonly RatchetSpec[]): readonly CheckLane[] => Array.dedupeWith( ratchets, (one, other) => one.measure.command === other.measure.command ).map(({ measure: { command }, name }) => ({ command, lane: LaneName.make(name), output: "stdout", }));
/** A ratchet in a territory: the key a baseline, a count and a raise are kept by. */export interface RatchetKey { readonly ratchet: RatchetName; readonly territory: string;}
/** Whether two rows name one ratchet in one territory. */export const sameRatchet = (one: RatchetKey) => (other: RatchetKey): boolean => one.ratchet === other.ratchet && one.territory === other.territory;
/** The decision a raise waits on. */export type RaiseRatchet = Extract<DecisionSubject, { _tag: "RaiseRatchet" }>;
/** What judging an answer's counts gives: its refusals, and the raises it waits on. */export interface RatchetJudgement { readonly refusals: readonly Weakened[]; readonly decisions: readonly RaiseRatchet[];}
/** * Judges an answer's counts against the counts it is held to (the Project * DO's baselines; on a person's machine, the counts on the answer's base). A * count at or under its baseline passes; one over it is refused with * `Weakened{ratchet}`, unless the answer asks to raise that ratchet in that * territory: then it is not refused, and waits on a `RaiseRatchet` decision * instead. A ratchet with no baseline yet is not judged (its first landing * sets it). */export const judgeRatchets = (input: { readonly baselines: readonly RatchetCount[]; readonly measured: readonly RatchetCount[]; readonly ask: AskId; readonly raises: readonly RatchetKey[];}): RatchetJudgement => { const raised = input.measured.flatMap((measured) => Option.match(Array.findFirst(input.baselines, sameRatchet(measured)), { onNone: () => [], onSome: (held) => measured.count > held.count ? [ { after: measured.count, asked: input.raises.some(sameRatchet(measured)), before: held.count, ratchet: measured.ratchet, territory: measured.territory, }, ] : [], }) );
return { decisions: raised .filter(({ asked }) => asked) .map(({ after, before, ratchet, territory }) => DecisionSubject.cases.RaiseRatchet.make({ after, ask: input.ask, before, ratchet, territory, }) ), refusals: raised .filter(({ asked }) => !asked) .map( ({ after, before, ratchet, territory }) => new Weakened({ weakening: { after, before, ratchet, territory } }) ), };};modified:packages/checks/test/kinds/ratchet.test.ts+142 added-3 removed
1 import { describe, expect, it } from "@effect/vitest";2 import { RatchetMeasure, RatchetSpec } from "@repo/protocol/domain/check";3 import { Command, Glob, JsonPath } from "@repo/protocol/domain/common";4+import { DecisionSubject } from "@repo/protocol/domain/decision";5 import type { Territory } from "@repo/protocol/domain/territory";5-import { RatchetName } from "@repo/protocol/ids";6-import { Effect, Exit, Ref } from "effect";6+import { AskId, RatchetName } from "@repo/protocol/ids";7+import { Weakened } from "@repo/protocol/refusal";8+import { Effect, Exit, Ref, Schema } from "effect";9 10 import { CountUnreadable } from "../../src/kinds/lint-count.ts";9-import { measure } from "../../src/kinds/ratchet.ts";11+import { countLanes, judgeRatchets, measure } from "../../src/kinds/ratchet.ts";12+import type { RatchetCount } from "../../src/kinds/ratchet.ts";13 import { recorded } from "./recorded.ts";14 15 // The recordings `lint-count.test.ts` describes: `any` three times in16 // parse.ts and once in date.ts (packages/parser), once in lex.ts161 unmodified lines178 expect(exit).toStrictEqual(Exit.fail("no checker"));179 })180 );181 });182+183+describe(countLanes, () => {184+ it("runs each command once, in a lane named for the first ratchet that runs it, handing back what it printed", () => {185+ const anyInLexer = RatchetSpec.make({186+ ...counting,187+ name: RatchetName.make("anyInLexer"),188+ territory: "@fixture/lexer",189+ });190+191+ expect(countLanes([counting, bundle, anyInLexer])).toStrictEqual([192+ { command: lintCommand, lane: "anyCount", output: "stdout" },193+ { command: bundleCommand, lane: "bundleKb", output: "stdout" },194+ ]);195+ });196+197+ it("runs nothing for a project with no ratchets", () => {198+ expect(countLanes([])).toStrictEqual([]);199+ });200+});201+202+const ask = AskId.make("parse-dates");203+204+const parser = "@fixture/parser";205+206+const counted = (count: number, territory = parser): RatchetCount => ({207+ count,208+ ratchet: anyCount,209+ territory,210+});211+212+const raising = {213+ ratchet: anyCount,214+ reason: "the parser's one cast, until the date types land",215+ territory: parser,216+};217+218+const wire = (refusals: readonly Weakened[]) =>219+ refusals.map((refusal) => Schema.encodeSync(Weakened)(refusal));220+221+describe(judgeRatchets, () => {222+ it("refuses an answer that raises a ratchet with Weakened", () => {223+ const { decisions, refusals } = judgeRatchets({224+ ask,225+ baselines: [counted(14)],226+ measured: [counted(15)],227+ raises: [],228+ });229+230+ expect(decisions).toStrictEqual([]);231+ expect(wire(refusals)).toStrictEqual(232+ wire([233+ new Weakened({234+ weakening: {235+ after: 15,236+ before: 14,237+ ratchet: anyCount,238+ territory: parser,239+ },240+ }),241+ ])242+ );243+ });244+245+ it.each([14, 12, 0])("lets an answer through at %i", (count) => {246+ expect(247+ judgeRatchets({248+ ask,249+ baselines: [counted(14)],250+ measured: [counted(count)],251+ raises: [],252+ })253+ ).toStrictEqual({ decisions: [], refusals: [] });254+ });255+256+ it("turns an asked-for raise into one RaiseRatchet decision, not a refusal", () => {257+ expect(258+ judgeRatchets({259+ ask,260+ baselines: [counted(14)],261+ measured: [counted(15)],262+ raises: [raising],263+ })264+ ).toStrictEqual({265+ decisions: [266+ DecisionSubject.cases.RaiseRatchet.make({267+ after: 15,268+ ask,269+ before: 14,270+ ratchet: anyCount,271+ territory: parser,272+ }),273+ ],274+ refusals: [],275+ });276+ });277+278+ it("refuses a raise asked for in another territory", () => {279+ const { decisions, refusals } = judgeRatchets({280+ ask,281+ baselines: [counted(14)],282+ measured: [counted(15)],283+ raises: [{ ...raising, territory: "@fixture/lexer" }],284+ });285+286+ expect(decisions).toStrictEqual([]);287+ expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([288+ { after: 15, before: 14, ratchet: anyCount, territory: parser },289+ ]);290+ });291+292+ it("judges nothing a ratchet has no baseline for yet", () => {293+ expect(294+ judgeRatchets({295+ ask,296+ baselines: [],297+ measured: [counted(15)],298+ raises: [],299+ })300+ ).toStrictEqual({ decisions: [], refusals: [] });301+ });302+303+ it("judges each territory against its own baseline", () => {304+ const lexer = "@fixture/lexer";305+306+ const { refusals } = judgeRatchets({307+ ask,308+ baselines: [counted(14), counted(2, lexer)],309+ measured: [counted(14), counted(3, lexer)],310+ raises: [],311+ });312+313+ expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([314+ { after: 3, before: 2, ratchet: anyCount, territory: lexer },315+ ]);316+ });317+});modified:packages/gate/src/escapes.ts+26 added
23 unmodified lines24 25 /** A `Waiver` decision's subject. */26 export type Waiver = Extract<DecisionSubject, { readonly _tag: "Waiver" }>;27 28+/** An answer asking a decider to raise one ratchet in one territory, and why. */29+export interface RaiseRequest {30+ readonly ratchet: RatchetName;31+ readonly territory: string;32+ readonly reason: string;33+}34+35 /**36 * The escape ratchet of `territory`: `escapes-` and the territory's name in37 * lowercase words joined by `-` (`@datekit/parse` is `escapes-datekit-parse`);38 * a territory with no such words, the root's `.`, is `escapes-root`.73 unmodified lines112 })113 );114 },115 });116+117+/**118+ * The raises a push's `waivers` ask a decider for: a reasoned escape in a119+ * territory explains a raise of every declared ratchet there, for its120+ * reason. The Project DO judges an answer's counts with them, and121+ * `<cli> check` does the same before the push.122+ */123+export const explainedRaises = (124+ policy: Policy,125+ ask: Ask,126+ waivers: readonly Waiver[]127+): readonly RaiseRequest[] =>128+ waivers.flatMap((waiver) =>129+ policy.ratchets.map(({ name: ratchet }) => ({130+ ratchet,131+ reason: waiver.reason,132+ territory: territoryOf(policy, ask, waiver.at.path),133+ }))134+ );modified:packages/gate/test/escapes.test.ts+72 added-2 removed
1 import { describe, expect, it } from "@effect/vitest";2+import { RatchetMeasure, RatchetSpec } from "@repo/protocol/domain/check";3+import { Command } from "@repo/protocol/domain/common";4 import { DecisionSubject } from "@repo/protocol/domain/decision";5 import { RatchetName, RepoPath } from "@repo/protocol/ids";6 import { Option } from "effect";7 8+import {9+ escapeDecisions,10+ escapeRatchet,11+ explainedRaises,6-import { escapeDecisions, escapeRatchet } from "../src/escapes.ts";7-import { addedLines, ask, testFacts } from "./facts.ts";12+} from "../src/escapes.ts";13+import { addedLines, ask, policy, testFacts } from "./facts.ts";14 15 const week = "packages/parse/src/week.ts";16 17 const lex = "packages/parse/src/lex.ts";111 unmodified lines129 )130 ).toStrictEqual([]);131 });132 });133+134+describe(explainedRaises, () => {135+ const anyCount = RatchetName.make("no-explicit-any");136+137+ const bundleKb = RatchetName.make("bundle-kb");138+139+ const declaring = {140+ ...policy,141+ ratchets: [142+ RatchetSpec.make({143+ measure: RatchetMeasure.cases.Count.make({144+ command: Command.make("oxlint --format json"),145+ rule: "typescript/no-explicit-any",146+ }),147+ name: anyCount,148+ }),149+ RatchetSpec.make({150+ measure: RatchetMeasure.cases.Count.make({151+ command: Command.make("oxlint --format json"),152+ rule: "import/max-dependencies",153+ }),154+ name: bundleKb,155+ }),156+ ],157+ };158+159+ it("asks to raise every declared ratchet in each reasoned escape's territory, for its reason", () => {160+ expect(161+ explainedRaises(declaring, ask, [162+ waiver(week, 4, "oxlint-disable", "the parser's one cast"),163+ waiver(pad, 2, "eslint-disable", "generated tables"),164+ ])165+ ).toStrictEqual([166+ {167+ ratchet: anyCount,168+ reason: "the parser's one cast",169+ territory: "@datekit/parse",170+ },171+ {172+ ratchet: bundleKb,173+ reason: "the parser's one cast",174+ territory: "@datekit/parse",175+ },176+ {177+ ratchet: anyCount,178+ reason: "generated tables",179+ territory: "@datekit/format",180+ },181+ {182+ ratchet: bundleKb,183+ reason: "generated tables",184+ territory: "@datekit/format",185+ },186+ ]);187+ });188+189+ it("asks nothing of a project that declares no ratchets", () => {190+ expect(191+ explainedRaises(policy, ask, [192+ waiver(week, 4, "oxlint-disable", "the parser's one cast"),193+ ])194+ ).toStrictEqual([]);195+ });196+});modified:packages/project/src/project.ts+10 added-15 removed
34 unmodified lines35 import { judgeClosure } from "@repo/checks/judge";36 import { checkVersion, commandFor } from "@repo/checks/kinds";37 import { lintToZeroCount } from "@repo/checks/kinds/lint-to-zero";38 import type { LintToZeroCheck } from "@repo/checks/kinds/lint-to-zero";39+import {40+ judgeRatchets,41+ measure,42+ WHOLE_PROJECT,39-import { measure, WHOLE_PROJECT } from "@repo/checks/kinds/ratchet";40-import type { RatchetCount } from "@repo/checks/kinds/ratchet";43+} from "@repo/checks/kinds/ratchet";44+import type { RaiseRatchet, RatchetCount } from "@repo/checks/kinds/ratchet";45 import { redFirstOfRuns } from "@repo/checks/red-first";46 import { weaknessesOf } from "@repo/checks/weak-shapes";47 import {48 escapeDecisions,49 escapeRatchet,50+ explainedRaises,51 territoryOf,52 } from "@repo/gate/escapes";53 import type { Waiver } from "@repo/gate/escapes";54 import { PushTarget } from "@repo/gate/facts";207 unmodified lines262 RatchetRow,263 } from "./project-store/rows.ts";264 import type { Projection } from "./projection.ts";265 import { askToLand, holdsSlot, leave, queueOf, storedQueue } from "./queue.ts";261-import { afterLanding, decideRaise, judgeRatchets } from "./ratchets.ts";262-import type {263- RaiseRatchet,264- RaiseRequest,265- RatchetBaseline,266-} from "./ratchets.ts";266+import { afterLanding, decideRaise } from "./ratchets.ts";267+import type { RatchetBaseline } from "./ratchets.ts";268 269 /** Every port one project's service runs on. */270 export type ProjectPorts =271 | Alarms2358 unmodified lines2630 const territoryIn = (waiver: Waiver) =>2631 territoryOf(policy, asked, waiver.at.path);2632 2633 // A reasoned escape in a territory explains a raise there.2633- const raises = waivers.flatMap((waiver): readonly RaiseRequest[] =>2634- policy.ratchets.map(({ name: ratchet }) => ({2635- ratchet,2636- reason: waiver.reason,2637- territory: territoryIn(waiver),2638- }))2639- );2634+ const raises = explainedRaises(policy, asked, waivers);2635 2636 const declared = input.report?.ratchets ?? [];2637 2638 // A tree merged onto a main that has moved on since is not judged:1717 unmodified linesmodified:packages/project/src/ratchets.ts+14 added-89 removed
1 /**2 * Ratchets' baselines, and the rules that move them (GLOSSARY "Ratchet"):3 * a baseline per (ratchet, territory), recorded at landing and lowered by a4- * landing with no one asking; an answer that raises one is refused, unless5- * it asks a decider to raise it; the only way up is a `RaiseRatchet`6- * decision a decider accepts. Pure: the counts come from7- * `@repo/checks/kinds/ratchet`'s `measure`, and the baselines live in the8- * Project DO's `ratchets` rows (no suppressions file in the tree; FE §8.4 B3).4+ * landing with no one asking; the only way up is a `RaiseRatchet` decision a5+ * decider accepts. Pure: the counts come from `@repo/checks/kinds/ratchet`'s6+ * `measure`, an answer's counts are judged against these baselines there7+ * (`judgeRatchets`, which `<cli> check` judges with too), and the baselines8+ * live in the Project DO's `ratchets` rows (no suppressions file in the9+ * tree; FE §8.4 B3).10 */10-import type { RatchetCount } from "@repo/checks/kinds/ratchet";11-import { DecisionSubject } from "@repo/protocol/domain/decision";11+import { sameRatchet } from "@repo/checks/kinds/ratchet";12+import type {13+ RaiseRatchet,14+ RatchetCount,15+ RatchetKey,16+} from "@repo/checks/kinds/ratchet";17 import type { Choice } from "@repo/protocol/domain/decision";13-import type { AskId, LandedSha, RatchetName } from "@repo/protocol/ids";14-import { Weakened } from "@repo/protocol/refusal";18+import type { LandedSha, RatchetName } from "@repo/protocol/ids";19 import { Array, Option } from "effect";20 21 /** A ratchet's baseline in one territory, and the landed SHA that set it. */22 export interface RatchetBaseline {2 unmodified lines25 readonly count: number;26 readonly setAt: LandedSha;27 }28 25-/** An answer asking a decider to raise one ratchet in one territory, and why. */26-export interface RaiseRequest {27- readonly ratchet: RatchetName;28- readonly territory: string;29- readonly reason: string;30-}31-32-/** The decision a raise waits on. */33-export type RaiseRatchet = Extract<DecisionSubject, { _tag: "RaiseRatchet" }>;34-29 /** A baseline a landing lowered, from what to what. */30 export interface Lowered {31 readonly ratchet: RatchetName;32 readonly territory: string;33 readonly before: number;34 readonly after: number;35 }36 43-/** What judging an answer's counts gives: its refusals, and the raises it waits on. */44-export interface RatchetJudgement {45- readonly refusals: readonly Weakened[];46- readonly decisions: readonly RaiseRatchet[];47-}48-37 /** The baselines after a landing, and the ones it lowered. */38 export interface BaselinesAfterLanding {39 readonly baselines: readonly RatchetBaseline[];40 readonly lowered: readonly Lowered[];41 }42 55-interface Keyed {56- readonly ratchet: RatchetName;57- readonly territory: string;58-}59-60-/** Whether two rows name one ratchet in one territory. */61-const sameRatchet =62- (one: Keyed) =>63- (other: Keyed): boolean =>64- one.ratchet === other.ratchet && one.territory === other.territory;65-66-const baselineOf = (baselines: readonly RatchetBaseline[], key: Keyed) =>43+const baselineOf = (baselines: readonly RatchetBaseline[], key: RatchetKey) =>44 Array.findFirst(baselines, sameRatchet(key));45 46 /**70- * Judges an answer's counts against the baselines. A count at or under its71- * baseline passes; one over it is refused with `Weakened{ratchet}`, unless72- * the answer asks to raise that ratchet in that territory: then it is not73- * refused, and waits on a `RaiseRatchet` decision instead. A ratchet with no74- * baseline yet is not judged (its first landing sets it).75- */76-export const judgeRatchets = (input: {77- readonly baselines: readonly RatchetBaseline[];78- readonly measured: readonly RatchetCount[];79- readonly ask: AskId;80- readonly raises: readonly RaiseRequest[];81-}): RatchetJudgement => {82- const raised = input.measured.flatMap((measured) =>83- Option.match(baselineOf(input.baselines, measured), {84- onNone: () => [],85- onSome: (held) =>86- measured.count > held.count87- ? [88- {89- after: measured.count,90- asked: input.raises.some(sameRatchet(measured)),91- before: held.count,92- ratchet: measured.ratchet,93- territory: measured.territory,94- },95- ]96- : [],97- })98- );99-100- return {101- decisions: raised102- .filter(({ asked }) => asked)103- .map(({ after, before, ratchet, territory }) =>104- DecisionSubject.cases.RaiseRatchet.make({105- after,106- ask: input.ask,107- before,108- ratchet,109- territory,110- })111- ),112- refusals: raised113- .filter(({ asked }) => !asked)114- .map(115- ({ after, before, ratchet, territory }) =>116- new Weakened({ weakening: { after, before, ratchet, territory } })117- ),118- };119-};120-121-/**47 * The baselines after a landing measured `measured` at `landed`: each count48 * under its baseline lowers it (and is named in `lowered`), a ratchet with no49 * baseline yet takes its count, and nothing else moves. A landing never50 * raises a baseline: an accepted `RaiseRatchet` already set it.82 unmodified linesmodified:packages/project/test/ratchets.test.ts+5 added-104 removed
1 import { describe, expect, it } from "@effect/vitest";2-import type { RatchetCount } from "@repo/checks/kinds/ratchet";2+import { judgeRatchets } from "@repo/checks/kinds/ratchet";3+import type { RaiseRatchet, RatchetCount } from "@repo/checks/kinds/ratchet";4+import type { RaiseRequest } from "@repo/gate/escapes";5 import { Choice, DecisionSubject } from "@repo/protocol/domain/decision";6 import { AskId, LandedSha, RatchetName } from "@repo/protocol/ids";5-import { Weakened } from "@repo/protocol/refusal";7 import { Arbitrary, Array, Effect, Option, Result, Schema } from "effect";8 8-import { afterLanding, decideRaise, judgeRatchets } from "../src/ratchets.ts";9-import type {10- RaiseRatchet,11- RaiseRequest,12- RatchetBaseline,13-} from "../src/ratchets.ts";9+import { afterLanding, decideRaise } from "../src/ratchets.ts";10+import type { RatchetBaseline } from "../src/ratchets.ts";11 12 const hex = (n: number) => n.toString(16).padStart(40, "0");13 14 const shaAt = (step: number) => LandedSha.make(hex(0x1_00_00 + step));16 unmodified lines31 ratchet: noExplicitAny,32 territory: parser,33 });34 38-const raising: RaiseRequest = {39- ratchet: noExplicitAny,40- reason: "the parser's one cast, until the date types land",41- territory: parser,42-};43-44-const wire = (refusals: readonly Weakened[]) =>45- refusals.map((refusal) => Schema.encodeSync(Weakened)(refusal));46-35 const raiseTo = (after: number): RaiseRatchet =>36 DecisionSubject.cases.RaiseRatchet.make({37 after,38 ask,1 unmodified line40 ratchet: noExplicitAny,41 territory: parser,42 });43 56-describe(judgeRatchets, () => {57- it("refuses an answer that raises a ratchet with Weakened", () => {58- const { decisions, refusals } = judgeRatchets({59- ask,60- baselines: [baseline(14)],61- measured: [measuring(15)],62- raises: [],63- });64-65- expect(decisions).toStrictEqual([]);66- expect(wire(refusals)).toStrictEqual(67- wire([68- new Weakened({69- weakening: {70- after: 15,71- before: 14,72- ratchet: noExplicitAny,73- territory: parser,74- },75- }),76- ])77- );78- });79-80- it.each([14, 12, 0])("lets an answer through at %i", (count) => {81- expect(82- judgeRatchets({83- ask,84- baselines: [baseline(14)],85- measured: [measuring(count)],86- raises: [],87- })88- ).toStrictEqual({ decisions: [], refusals: [] });89- });90-91- it("turns an asked-for raise into one RaiseRatchet decision, not a refusal", () => {92- expect(93- judgeRatchets({94- ask,95- baselines: [baseline(14)],96- measured: [measuring(15)],97- raises: [raising],98- })99- ).toStrictEqual({ decisions: [raiseTo(15)], refusals: [] });100- });101-102- it("refuses a raise asked for in another territory", () => {103- const { decisions, refusals } = judgeRatchets({104- ask,105- baselines: [baseline(14)],106- measured: [measuring(15)],107- raises: [{ ...raising, territory: "packages/lexer" }],108- });109-110- expect(decisions).toStrictEqual([]);111- expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([112- { after: 15, before: 14, ratchet: noExplicitAny, territory: parser },113- ]);114- });115-116- it("judges nothing a ratchet has no baseline for yet", () => {117- expect(118- judgeRatchets({119- ask,120- baselines: [],121- measured: [measuring(15)],122- raises: [],123- })124- ).toStrictEqual({ decisions: [], refusals: [] });125- });126-127- it("judges each territory against its own baseline", () => {128- const lexer = "packages/lexer";129-130- const { refusals } = judgeRatchets({131- ask,132- baselines: [baseline(14), { ...baseline(2), territory: lexer }],133- measured: [measuring(14), { ...measuring(3), territory: lexer }],134- raises: [],135- });136-137- expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([138- { after: 3, before: 2, ratchet: noExplicitAny, territory: lexer },139- ]);140- });141-});142-44 describe(afterLanding, () => {45 it("lowers a baseline to a landing's lower count, by itself", () => {46 expect(47 afterLanding([baseline(14)], [measuring(12)], shaAt(1))398 unmodified linesmodified:PROVENANCE.md+1 added-1 removed
5 unmodified lines6 7 | Our file | Origin | Licence | Our changes |8 | --- | --- | --- | --- |9 | `tools/oxlint/anti-slop/` | [dmmulroy/anti-slop](https://github.com/dmmulroy/anti-slop) at `c44ef22` | MIT, `LICENSES/anti-slop.MIT.txt` | None; vendored by its own install script. See `UPSTREAM.md` there. |10-| `packages/protocol/src/cli.ts` | [joelhooks/rat-stack](https://github.com/joelhooks/rat-stack) `packages/capability/src/to-command.ts` l.14–247 at `fba26d8` | MIT, `LICENSES/rat-stack.MIT.txt` | Projects an `Rpc` whose payload is a struct (or an empty record), not a capability, and calls it through an `RpcClient`, named and given positionals by the `Cli` annotation; `toCommands` projects a whole group by its `Surfaces` annotation. `--json` is always offered; `--yes` is restored from our own `NeedsApproval` (without it the command fails with `ApprovalNeeded` before any call); `--dry-run` is offered unless `ReadOnly` (it prints the encoded payload and calls nothing). The command prints through a `CommandOutput` port, never the console: a refusal (or the refusals a success carries, such as a refused receipt) goes to it once and the command fails with `Reported`. Defaults may fill required fields left out (the repo's project). String flags check their value with the field's schema, so the parser refuses a malformed value by its flag. The description comes from the `Description` annotation. Dropped: the reserved-field guards and the `as never` casts. |10+| `packages/protocol/src/cli.ts` | [joelhooks/rat-stack](https://github.com/joelhooks/rat-stack) `packages/capability/src/to-command.ts` l.14–247 at `fba26d8` | MIT, `LICENSES/rat-stack.MIT.txt` | Projects an `Rpc` whose payload is a struct (or an empty record), not a capability, and calls it through an `RpcClient`, named and given positionals by the `Cli` annotation (a positional it lists in `formerFlags` still parses as its former flag, hidden from help, while help shows the argument as required); `toCommands` projects a whole group by its `Surfaces` annotation. `--json` is always offered; `--yes` is restored from our own `NeedsApproval` (without it the command fails with `ApprovalNeeded` before any call); `--dry-run` is offered unless `ReadOnly` (it prints the encoded payload and calls nothing). The command prints through a `CommandOutput` port, never the console: a refusal (or the refusals a success carries, such as a refused receipt) goes to it once and the command fails with `Reported`. Defaults may fill required fields left out (the repo's project). String flags check their value with the field's schema, so the parser refuses a malformed value by its flag. The description comes from the `Description` annotation. Dropped: the reserved-field guards and the `as never` casts. |11 | `packages/protocol/src/mcp.ts` | [joelhooks/rat-stack](https://github.com/joelhooks/rat-stack) `packages/capability/src/to-toolkit.ts` l.18–146 at `fba26d8` | MIT, `LICENSES/rat-stack.MIT.txt` | Projects an `RpcGroup`'s Rpcs, not capabilities: the payload, success and error schemas become the tool's. Handlers call each Rpc through an `RpcClient`, passing the payload alone. The description comes from the `Description` annotation. Hint annotations restored from our own `ReadOnly`, `Idempotent` and `Destructive` annotations, with `OpenWorld` false; a `NeedsApproval` contract's description gains "Asks a person first." Added `listTools`, the tools as `tools/list` shows them, and `toJsonSchema`, which derives a schema the way `McpServer` does (top-level `$ref` inlined, definitions under `$defs`). Dropped: the empty-input dynamic tool, upstream's approval flow and the file-wide diagnostics escape. |12 | `tools/oxlint/fence/rules/debt-ledger.ts` | [joelhooks/rat-stack](https://github.com/joelhooks/rat-stack) `scripts/oxlint-plugin-debt-ledger.ts` at `fba26d8` | MIT, `LICENSES/rat-stack.MIT.txt` | Five kinds, one per `debt.baseline.json` key: the TypeScript kind is split by directive into `@ts-expect-error`, `@ts-ignore` and `@ts-nocheck`. A named export, registered in the `fence` plugin rather than its own, and run only through `oxlint.debt.config.ts`. `eslint-disable` directives count as `oxlint-disable`, since oxlint honours them. A directive counts only where a comment's line starts, as oxlint, eslint and tsc read it, except `@effect-diagnostics`, which the Effect language service reads anywhere. Every report sits at the file's first offset, where no disable comment can hide it, and carries its line (and column) in the message. An empty reason (`-- ` with nothing after) leaves the directive text without the ` --`. The JSON message `{directive, kind, reason?}` and the reason after ` -- ` are upstream's. |13 | `tools/oxlint/fence/rules/no-module-level-mutable-state.ts` | [joelhooks/rat-stack](https://github.com/joelhooks/rat-stack) `scripts/oxlint-plugin-patterns.ts` l.28–43 and l.621–677 at `fba26d8` | MIT, `LICENSES/rat-stack.MIT.txt` | Only this rule is ported from that file. A named export in the `fence` plugin. `workspacePath` reads the path string alone: it strips oxlint's `cwd`, then finds the whole `(apps\|packages)/<name>/src/` shape anywhere, so a fixture tree counts and folders above the checkout don't; no `node:path` import and no `nodeBuiltinImport` escape. `workspacePath` is exported, for `no-effect-sleep-in-project`. The `.svelte` exclusion is dropped, and `declare let`/`declare var` is skipped. The scope check, `isModuleScopedVar`, the `moduleState` message and the description are upstream's. See `tools/oxlint/fence/UPSTREAM.md`. |14 | `examples/burrow/tools/oxlint/burrow/rules/no-module-level-mutable-state.ts` | [joelhooks/rat-stack](https://github.com/joelhooks/rat-stack) `scripts/oxlint-plugin-patterns.ts` l.28–43 and l.621–677 at `fba26d8`, copied from `tools/oxlint/fence/rules/no-module-level-mutable-state.ts` | MIT, `examples/burrow/tools/oxlint/burrow/LICENSE-rat-stack.txt` (a copy of `LICENSES/rat-stack.MIT.txt`, so the example carries its own notice) | A copy of the fence's port, for the fictional example `burrow`. Its header points at burrow's own licence copy and `UPSTREAM.md`. It is registered in burrow's `burrow` plugin and set to `warn` by burrow's config. Everything else is as in the fence's row. See `examples/burrow/tools/oxlint/burrow/UPSTREAM.md`. |33 unmodified lines