Skip to content
Myr

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.

authored by oscabriel · committed by oscabriel · parent 7f1a273 · Browse files · 13 files+433 added−345 removed
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

13 files+433 added−345 removed

modified:apps/cli/src/local/check.ts+6 added-12 removed
73 unmodified lines
74 ConfigBundler,75 ConfigBundlerBun,76 localPolicy,77} from "./local-policy.ts";78import {79 askedRaises,80 countRatchets,81 judgeMoves,82 RatchetMove,83} from "./ratchets.ts";78import { countRatchets, judgeMoves, RatchetMove } from "./ratchets.ts";79import { staleGenerated } from "./stale.ts";80import type { StaleCopy } from "./stale.ts";8182const COMMAND = "check";
718 unmodified lines
801 }802803 // 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;807814 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 lines
826 `Could not count the ratchet ${ratchet} here: ${why}. The platform counts it after the push.`827 );828 }829836 const ratcheted = judgeMoves(counts.moves, askedRaises(facts));830 const ratcheted = judgeMoves(facts, ask.value, counts.moves);831838 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 lines
modified: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 */18import { CheckAt, CheckRunner, outputOf } from "@repo/checks/check-runner";19import type { CheckLane, CheckRun } from "@repo/checks/check-runner";20import {18 CheckAt,19 CheckLane,20 CheckRunner,21 outputOf,22} from "@repo/checks/check-runner";23import type { CheckRun } from "@repo/checks/check-runner";24import { measure } from "@repo/checks/kinds/ratchet";25import type { RatchetCount } from "@repo/checks/kinds/ratchet";26import { escapeDecisions, territoryOf } from "@repo/gate/escapes";21 countLanes,22 judgeRatchets,23 measure,24 sameRatchet,25} from "@repo/checks/kinds/ratchet";26import type {27 RatchetCount,28 RatchetJudgement,29} from "@repo/checks/kinds/ratchet";30import { escapeDecisions, explainedRaises } from "@repo/gate/escapes";31import type { PushFacts } from "@repo/gate/facts";32import type { LaneOutcome } from "@repo/protocol/domain/answer";29import type { RatchetSpec } from "@repo/protocol/domain/check";33import type { Ask } from "@repo/protocol/domain/ask";34import type { Policy } from "@repo/protocol/domain/policy";31import { LaneName } from "@repo/protocol/ids";32import type {33 CommitSha,34 ProjectName,35 RatchetName,36 RepoName,37} from "@repo/protocol/ids";38import { Weakened } from "@repo/protocol/refusal";35import { RatchetName } from "@repo/protocol/ids";36import type { CommitSha, ProjectName, RepoName } from "@repo/protocol/ids";37import { Array, Effect, Option, Result, Schema } from "effect";3839/** One ratchet's count in one territory, on the answer's base and on its head. */40export const RatchetMove = Schema.Struct({41 after: Schema.Int,42 before: Schema.Int,45 ratchet: Schema.String,43 ratchet: RatchetName,44 territory: Schema.String,45});4647export type RatchetMove = typeof RatchetMove.Type;
9 unmodified lines
57 readonly moves: readonly RatchetMove[];58 readonly uncounted: readonly Uncounted[];59}6063/** The answer's counts judged: what refuses it, and the raises it will wait on. */64export interface LocalJudgement {65 readonly refusals: readonly Weakened[];66 readonly waiting: readonly RatchetMove[];67}6869/** A ratchet in a territory: the key a baseline and a raise are kept by. */70interface Keyed {71 readonly ratchet: string;72 readonly territory: string;73}7475const sameRatchet =76 (one: Keyed) =>77 (other: Keyed): boolean =>78 one.ratchet === other.ratchet && one.territory === other.territory;7980/**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 */85const 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 );9261/** How a count lane that printed no count ended, in words. */62const endings = {63 blocked: "it never ran here, or ran out of time",64 failed: "it failed",
142 unmodified lines
207 return { moves, uncounted };208 });209210/**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 */247export 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 });258259/**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 */218export const judgeMoves = (266 moves: readonly RatchetMove[],267 raises: readonly Keyed[]268): LocalJudgement => {269 const raised = moves.filter(({ after, before }) => after > before);270271 const asked = (move: RatchetMove) => raises.some(sameRatchet(move));272273 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 lines
24} from "@repo/checks/check-runner";25import type { CheckRun, LaneEvidence } from "@repo/checks/check-runner";26import { EvidenceStore } from "@repo/checks/evidence-store";27import { lintToZeroCount } from "@repo/checks/kinds/lint-to-zero";28import { measure } from "@repo/checks/kinds/ratchet";28import { countLanes, measure } from "@repo/checks/kinds/ratchet";29import { classifyFailure } from "@repo/gate/classify";30import { MeasuredCount, runBlockOf } from "@repo/project/answer-runs";31import type { AnswerRun } from "@repo/project/answer-runs";32import { LandingState } from "@repo/project/landing";
361 unmodified lines
394 if (!Array.isReadonlyArrayNonEmpty(specs)) {395 return { counts: [], uncounted: Option.none() };396 }397398 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);399400 const ran = yield* job(lanes);401402 const printed = (command: string) =>
207 unmodified lines
modified:apps/web/src/features/finish/finish-view.tsx+1 added-1 removed
51 unmodified lines
52 const base = verdict?.base ?? "<base>";5354 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 lines
modified:apps/web/test/finish.test.tsx+1 added-3 removed
219 unmodified lines
220 const text = textOf(element);221222 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 lines
modified:packages/checks/src/kinds/ratchet.ts+107 added-8 removed
modified:packages/checks/test/kinds/ratchet.test.ts+142 added-3 removed
1import { describe, expect, it } from "@effect/vitest";2import { RatchetMeasure, RatchetSpec } from "@repo/protocol/domain/check";3import { Command, Glob, JsonPath } from "@repo/protocol/domain/common";4import { DecisionSubject } from "@repo/protocol/domain/decision";5import type { Territory } from "@repo/protocol/domain/territory";5import { RatchetName } from "@repo/protocol/ids";6import { Effect, Exit, Ref } from "effect";6import { AskId, RatchetName } from "@repo/protocol/ids";7import { Weakened } from "@repo/protocol/refusal";8import { Effect, Exit, Ref, Schema } from "effect";910import { CountUnreadable } from "../../src/kinds/lint-count.ts";9import { measure } from "../../src/kinds/ratchet.ts";11import { countLanes, judgeRatchets, measure } from "../../src/kinds/ratchet.ts";12import type { RatchetCount } from "../../src/kinds/ratchet.ts";13import { recorded } from "./recorded.ts";1415// The recordings `lint-count.test.ts` describes: `any` three times in16// parse.ts and once in date.ts (packages/parser), once in lex.ts
161 unmodified lines
178 expect(exit).toStrictEqual(Exit.fail("no checker"));179 })180 );181});182183describe(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 });190191 expect(countLanes([counting, bundle, anyInLexer])).toStrictEqual([192 { command: lintCommand, lane: "anyCount", output: "stdout" },193 { command: bundleCommand, lane: "bundleKb", output: "stdout" },194 ]);195 });196197 it("runs nothing for a project with no ratchets", () => {198 expect(countLanes([])).toStrictEqual([]);199 });200});201202const ask = AskId.make("parse-dates");203204const parser = "@fixture/parser";205206const counted = (count: number, territory = parser): RatchetCount => ({207 count,208 ratchet: anyCount,209 territory,210});211212const raising = {213 ratchet: anyCount,214 reason: "the parser's one cast, until the date types land",215 territory: parser,216};217218const wire = (refusals: readonly Weakened[]) =>219 refusals.map((refusal) => Schema.encodeSync(Weakened)(refusal));220221describe(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 });229230 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 });244245 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 });255256 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 });277278 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 });285286 expect(decisions).toStrictEqual([]);287 expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([288 { after: 15, before: 14, ratchet: anyCount, territory: parser },289 ]);290 });291292 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 });302303 it("judges each territory against its own baseline", () => {304 const lexer = "@fixture/lexer";305306 const { refusals } = judgeRatchets({307 ask,308 baselines: [counted(14), counted(2, lexer)],309 measured: [counted(14), counted(3, lexer)],310 raises: [],311 });312313 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 lines
2425/** A `Waiver` decision's subject. */26export type Waiver = Extract<DecisionSubject, { readonly _tag: "Waiver" }>;2728/** An answer asking a decider to raise one ratchet in one territory, and why. */29export interface RaiseRequest {30 readonly ratchet: RatchetName;31 readonly territory: string;32 readonly reason: string;33}3435/**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 lines
112 })113 );114 },115 });116117/**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 */123export 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
1import { 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,6import { escapeDecisions, escapeRatchet } from "../src/escapes.ts";7import { addedLines, ask, testFacts } from "./facts.ts";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";
111 unmodified lines
129 )130 ).toStrictEqual([]);131 });132});133134describe(explainedRaises, () => {135 const anyCount = RatchetName.make("no-explicit-any");136137 const bundleKb = RatchetName.make("bundle-kb");138139 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 };158159 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 });188189 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 lines
35import { judgeClosure } from "@repo/checks/judge";36import { checkVersion, commandFor } from "@repo/checks/kinds";37import { lintToZeroCount } from "@repo/checks/kinds/lint-to-zero";38import type { LintToZeroCheck } from "@repo/checks/kinds/lint-to-zero";39import {40 judgeRatchets,41 measure,42 WHOLE_PROJECT,39import { measure, WHOLE_PROJECT } from "@repo/checks/kinds/ratchet";40import type { RatchetCount } from "@repo/checks/kinds/ratchet";43} from "@repo/checks/kinds/ratchet";44import type { RaiseRatchet, RatchetCount } from "@repo/checks/kinds/ratchet";45import { redFirstOfRuns } from "@repo/checks/red-first";46import { weaknessesOf } from "@repo/checks/weak-shapes";47import {48 escapeDecisions,49 escapeRatchet,50 explainedRaises,51 territoryOf,52} from "@repo/gate/escapes";53import type { Waiver } from "@repo/gate/escapes";54import { PushTarget } from "@repo/gate/facts";
207 unmodified lines
262 RatchetRow,263} from "./project-store/rows.ts";264import type { Projection } from "./projection.ts";265import { askToLand, holdsSlot, leave, queueOf, storedQueue } from "./queue.ts";261import { afterLanding, decideRaise, judgeRatchets } from "./ratchets.ts";262import type {263 RaiseRatchet,264 RaiseRequest,265 RatchetBaseline,266} from "./ratchets.ts";266import { afterLanding, decideRaise } from "./ratchets.ts";267import type { RatchetBaseline } from "./ratchets.ts";268269/** Every port one project's service runs on. */270export type ProjectPorts =271 | Alarms
2358 unmodified lines
2630 const territoryIn = (waiver: Waiver) =>2631 territoryOf(policy, asked, waiver.at.path);26322633 // 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);26352636 const declared = input.report?.ratchets ?? [];26372638 // A tree merged onto a main that has moved on since is not judged:
1717 unmodified lines
modified: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 */10import type { RatchetCount } from "@repo/checks/kinds/ratchet";11import { DecisionSubject } from "@repo/protocol/domain/decision";11import { sameRatchet } from "@repo/checks/kinds/ratchet";12import type {13 RaiseRatchet,14 RatchetCount,15 RatchetKey,16} from "@repo/checks/kinds/ratchet";17import type { Choice } from "@repo/protocol/domain/decision";13import type { AskId, LandedSha, RatchetName } from "@repo/protocol/ids";14import { Weakened } from "@repo/protocol/refusal";18import type { LandedSha, RatchetName } from "@repo/protocol/ids";19import { Array, Option } from "effect";2021/** A ratchet's baseline in one territory, and the landed SHA that set it. */22export interface RatchetBaseline {
2 unmodified lines
25 readonly count: number;26 readonly setAt: LandedSha;27}2825/** An answer asking a decider to raise one ratchet in one territory, and why. */26export interface RaiseRequest {27 readonly ratchet: RatchetName;28 readonly territory: string;29 readonly reason: string;30}3132/** The decision a raise waits on. */33export type RaiseRatchet = Extract<DecisionSubject, { _tag: "RaiseRatchet" }>;3429/** A baseline a landing lowered, from what to what. */30export interface Lowered {31 readonly ratchet: RatchetName;32 readonly territory: string;33 readonly before: number;34 readonly after: number;35}3643/** What judging an answer's counts gives: its refusals, and the raises it waits on. */44export interface RatchetJudgement {45 readonly refusals: readonly Weakened[];46 readonly decisions: readonly RaiseRatchet[];47}4837/** The baselines after a landing, and the ones it lowered. */38export interface BaselinesAfterLanding {39 readonly baselines: readonly RatchetBaseline[];40 readonly lowered: readonly Lowered[];41}4255interface Keyed {56 readonly ratchet: RatchetName;57 readonly territory: string;58}5960/** Whether two rows name one ratchet in one territory. */61const sameRatchet =62 (one: Keyed) =>63 (other: Keyed): boolean =>64 one.ratchet === other.ratchet && one.territory === other.territory;6566const baselineOf = (baselines: readonly RatchetBaseline[], key: Keyed) =>43const baselineOf = (baselines: readonly RatchetBaseline[], key: RatchetKey) =>44 Array.findFirst(baselines, sameRatchet(key));4546/**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 */76export 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 );99100 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};120121/**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 lines
modified:packages/project/test/ratchets.test.ts+5 added-104 removed
1import { describe, expect, it } from "@effect/vitest";2import type { RatchetCount } from "@repo/checks/kinds/ratchet";2import { judgeRatchets } from "@repo/checks/kinds/ratchet";3import type { RaiseRatchet, RatchetCount } from "@repo/checks/kinds/ratchet";4import type { RaiseRequest } from "@repo/gate/escapes";5import { Choice, DecisionSubject } from "@repo/protocol/domain/decision";6import { AskId, LandedSha, RatchetName } from "@repo/protocol/ids";5import { Weakened } from "@repo/protocol/refusal";7import { Arbitrary, Array, Effect, Option, Result, Schema } from "effect";88import { afterLanding, decideRaise, judgeRatchets } from "../src/ratchets.ts";9import type {10 RaiseRatchet,11 RaiseRequest,12 RatchetBaseline,13} from "../src/ratchets.ts";9import { afterLanding, decideRaise } from "../src/ratchets.ts";10import type { RatchetBaseline } from "../src/ratchets.ts";1112const hex = (n: number) => n.toString(16).padStart(40, "0");1314const shaAt = (step: number) => LandedSha.make(hex(0x1_00_00 + step));
16 unmodified lines
31 ratchet: noExplicitAny,32 territory: parser,33});3438const raising: RaiseRequest = {39 ratchet: noExplicitAny,40 reason: "the parser's one cast, until the date types land",41 territory: parser,42};4344const wire = (refusals: readonly Weakened[]) =>45 refusals.map((refusal) => Schema.encodeSync(Weakened)(refusal));4635const raiseTo = (after: number): RaiseRatchet =>36 DecisionSubject.cases.RaiseRatchet.make({37 after,38 ask,
1 unmodified line
40 ratchet: noExplicitAny,41 territory: parser,42 });4356describe(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 });6465 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 });7980 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 });9091 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 });101102 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 });109110 expect(decisions).toStrictEqual([]);111 expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([112 { after: 15, before: 14, ratchet: noExplicitAny, territory: parser },113 ]);114 });115116 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 });126127 it("judges each territory against its own baseline", () => {128 const lexer = "packages/lexer";129130 const { refusals } = judgeRatchets({131 ask,132 baselines: [baseline(14), { ...baseline(2), territory: lexer }],133 measured: [measuring(14), { ...measuring(3), territory: lexer }],134 raises: [],135 });136137 expect(refusals.map(({ weakening }) => weakening)).toStrictEqual([138 { after: 3, before: 2, ratchet: noExplicitAny, territory: lexer },139 ]);140 });141});14244describe(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 lines
modified:PROVENANCE.md+1 added-1 removed
5 unmodified lines
67| 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