Skip to content
Myr

Review fixes for 1205

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- The Finish decision's patch declared 9 old lines in its first hunk and held 8, so the diff view refused it (`parsePatchContent: hunk line count mismatch` on /vellum/decisions/dec-000004); the header now reads `-1,8 +1,14`. The Finish case now counts every hunk against its header (red on the old patch: 8/14 against 9/14). - vellum's `evidence` answered `UnknownProject` for a log ref nobody kept before it asked who was reading, which told a stranger which logs exist; it now refuses `NotDecider` first and only then looks for the log, as the service does. New case: the claimant reads the unit lane's log, and wren gets `NotDecider` for the kept ref and for a made-up one (red before: `UnknownProject` for the made-up one). - `told()` hands out copies of the story's arrays and maps, so a record already served cannot change under a read while the live landing or a decision writes the story. - The live landing takes its one shot with `Ref.getAndSet`, so two reads at once cannot both land the lint child. - `decodeRecord` also decodes the answers `status` serves. - vellum's decision budget and claim warn/lapse times are stated once and feed both its `policy.json` and the story, where the same numbers were written twice. - The Today case compares the decision kinds with `DecisionSubject.cases`, so a new kind with no fixture fails it. - Fixed the fillers' timing comment (three minutes apart, not two).

authored by oscabriel · committed by oscabriel · parent c77e426 · Browse files · 6 files+158 added−50 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+158 added−50 removed

  • tests:+94 added−11 removed
  • other:+64 added−39 removed

6 files+158 added−50 removed

modified:apps/web/src/dev/fixtures/fillers.ts+3 added-2 removed
190 unmodified lines
191 ],192 ]);193194/**195 * Every filler made and adopted, one every two minutes from `minute`, each196 * one's ask opened by its decider a minute after its first push.195 * Every filler made and adopted, one every three minutes from `minute`,196 * each one's ask (or, in mossgate, a visitor's proposal) a minute after its197 * first push.198 */199export const seedFillers = (minute: number) =>200 Effect.forEach(201 fillers,
48 unmodified lines
modified:apps/web/src/dev/fixtures/record.ts+6 added-2 removed
12 unmodified lines
13 */14import { creditsByArea } from "@repo/project/attention/credits";15import { today } from "@repo/project/attention/today";16import { listingOf } from "@repo/project/events";17import type { AnswerView, Verdict } from "@repo/protocol/domain/answer";18import { Verdict as VerdictSchema } from "@repo/protocol/domain/answer";17import type { Verdict } from "@repo/protocol/domain/answer";18import {19 AnswerView,20 Verdict as VerdictSchema,21} from "@repo/protocol/domain/answer";22import { Ask } from "@repo/protocol/domain/ask";23import type { AskListing } from "@repo/protocol/domain/ask";24import { ClaimView } from "@repo/protocol/domain/claim";25import { ForkRef } from "@repo/protocol/domain/code";
81 unmodified lines
107108 yield* many(Ask, [...record.asks.values()]);109 yield* many(ProjectEvent, record.events);110 yield* many(VerdictSchema, [...record.verdicts.values()].flat());111 yield* many(AnswerView, record.answers);112 yield* many(LandingView, record.landings);113 yield* many(Decision, record.decisions);114 yield* many(ClaimView, record.claims);115 yield* many(ForkRef, record.forks);
145 unmodified lines
modified:apps/web/src/dev/fixtures/story.ts+13 added-10 removed
147 unmodified lines
148 readonly files: Files;149 readonly lanes: Lanes;150 readonly project: ProjectName;151 readonly test: string;152 readonly warnAfter: { readonly hours: number };152 readonly lapseAfter: { readonly hours: number };153 readonly warnAfter: { readonly hours: number };154}) =>155 Effect.gen(function* () {156 const host = yield* RepoHost;157 const { project } = input;
664 unmodified lines
822 repo: RepoName.make(`${project}--me--${handle}`),823 })),824 ];825826 // A copy of each part: a later step writes the story's own arrays827 // and maps in place, and a record already served must not change828 // under a read while that step is under way.829 return {827 answers,828 asks,830 answers: [...answers],831 asks: new Map(asks),832 claims: claimViews,830 decisions,833 decisions: [...decisions],834 env: apart.env,832 events,835 events: [...events],836 firstClaims: [...firstClaims].map(([handle, at]) => ({ at, handle })),837 forks,838 head,836 landings,837 ledger: { ...apart.ledger, entries: ledger },838 logs,839 proposals,840 verdicts,839 landings: [...landings],840 ledger: { ...apart.ledger, entries: [...ledger] },841 logs: new Map(logs),842 proposals: new Map(proposals),843 verdicts: new Map(verdicts),844 };845 },846 };847 });
3 unmodified lines
modified:apps/web/src/dev/fixtures/vellum.ts+16 added-8 removed
221 unmodified lines
222 "LEGACY_PDF_ENGINE=",223 "",224].join("\n");225226/** How many decisions a vellum decider takes a day (its `policy.json`'s budget). */227export const decisionsPerDay = 5;228229/** How long a claim goes without a push before it is warned, then lapses. */230const CLAIMS = { lapseAfter: { hours: 96 }, warnAfter: { hours: 48 } } as const;231232const HOUR_MS = 3_600_000;233234const policy = policyJson({235 asks: [],228 budget: { decisionsPerDay: 5, expireDays: 3 },236 budget: { decisionsPerDay, expireDays: 3 },237 caps: { claimsPerPerson: 3, proposalsPerPerson: 2 },230 claims: { lapseAfterMs: 345_600_000, warnAfterMs: 172_800_000 },238 claims: {239 lapseAfterMs: CLAIMS.lapseAfter.hours * HOUR_MS,240 warnAfterMs: CLAIMS.warnAfter.hours * HOUR_MS,241 },242 deciders: [243 { handles: [people.ines], paths: "**" },244 { handles: [people.ines, people.lin], paths: `${dir}/**` },245 { handles: [people.okonkwo], paths: "packages/export/**" },
477 unmodified lines
723 "diff --git a/packages/render/src/table.ts b/packages/render/src/table.ts",724 "index 5d1c0e2..a8f4b71 100644",725 "--- a/packages/render/src/table.ts",726 "+++ b/packages/render/src/table.ts",716 "@@ -1,9 +1,14 @@",727 "@@ -1,8 +1,14 @@",728 ' import type { Token } from "@vellum/parser";',729 " ",730 "+const MAX_CELL = 40;",731 "+",
162 unmodified lines
894 const story = yield* storyOf({895 base,896 files: vellumFiles,897 lanes: LANES,887 lapseAfter: { hours: 96 },898 lapseAfter: CLAIMS.lapseAfter,899 project: vellum,900 test: TEST,890 warnAfter: { hours: 48 },901 warnAfter: CLAIMS.warnAfter,902 });903904 const answerAndLand = (input: {905 readonly stated: Stated;
1069 unmodified lines
1975 ["packages/lint/src/index.ts", entryOf("lint", "tokenize")],1976 ]),1977 });1978 });19681969/** How many decisions a vellum decider takes a day (its `policy.json`'s budget). */1970export const decisionsPerDay = 5;
modified:apps/web/src/dev/fixtures.ts+26 added-17 removed
256 unmodified lines
257 ? [was, was]258 : [Option.none(), Option.some(at)]259 );260261 if (Option.isNone(armed) || (yield* Ref.get(fixtures.landed))) {261 if (Option.isNone(armed)) {262 return;263 }264265 const waited = Duration.nanos(at - armed.value);266267 if (Duration.isLessThan(waited, after)) {267 // Taken in one step, so two reads at once land it only once.268 if (269 Duration.isLessThan(waited, after) ||270 (yield* Ref.getAndSet(fixtures.landed, true))271 ) {272 return;273 }274271 yield* Ref.set(fixtures.landed, true);275 yield* write((story) =>276 Effect.gen(function* () {277 const landedAt = DateTime.add(yield* now, { minutes: 1 });278
37 unmodified lines
316 .slice(0, limit)317 .map((event) => ({ event, seq: event.seq }))318 )319 ),320 // As the service answers: a decider here or the log's claimant may321 // read; anyone else hears `NotDecider` whether or not a log is kept,322 // so the reply tells no one which logs exist.323 evidence: (caller, ref) =>324 Effect.gen(function* () {325 const record = yield* current;320 const log = record.logs.get(ref);321 const who = callerOf(caller);326 const log = Option.fromUndefinedOr(record.logs.get(ref));327323 const allowed = Option.exists(who, ({ handle }) =>324 log === undefined325 ? false326 : sameHandle(log.claimant, handle) ||327 record.decisions.some(({ deciders }) =>328 deciders.some((each) => sameHandle(each, handle))329 )328 const allowed = Option.exists(329 callerOf(caller),330 ({ handle }) =>331 record.decisions.some(({ deciders }) =>332 deciders.some((each) => sameHandle(each, handle))333 ) ||334 Option.exists(log, ({ claimant }) => sameHandle(claimant, handle))335 );336332 if (log === undefined) {333 return yield* new UnknownProject({ project: vellum });334 }335337 if (!allowed) {338 return yield* new NotDecider({});339 }340340 return { lane: log.lane, text: log.text, truncated: false };341 if (Option.isNone(log)) {342 return yield* new UnknownProject({ project: vellum });343 }344345 return {346 lane: log.value.lane,347 text: log.value.text,348 truncated: false,349 };350 }),351 forks: () => Effect.map(current, ({ forks }) => forks),352 head: () => Effect.map(current, ({ head }) => ({ landed: head })),353 landing: (_caller, sha) =>
134 unmodified lines
modified:apps/web/test/dev-fixtures.test.ts+94 added-11 removed
145 unmodified lines
146 ? outcome.refusals147 : [];148149/**150 * Each hunk of a unified diff, as its header declares its old and new151 * lengths and as its lines count them, so a patch a diff view cannot parse152 * shows as a mismatch.153 */154const hunksOf = (patch: string) => {155 const hunks: { declared: string; counted: string }[] = [];156 let old = 0;157 let fresh = 0;158 let declared: string | undefined;159160 const close = () => {161 if (declared !== undefined) {162 hunks.push({ counted: `${old}/${fresh}`, declared });163 }164 };165166 for (const line of patch.split("\n")) {167 const header =168 /^@@ -\d+(?:,(?<old>\d+))? \+\d+(?:,(?<fresh>\d+))? @@/u.exec(line);169170 if (header !== null) {171 close();172 declared = `${header.groups?.old ?? "1"}/${header.groups?.fresh ?? "1"}`;173 old = 0;174 fresh = 0;175 } else if (line.startsWith("diff --git ")) {176 close();177 declared = undefined;178 } else if (declared !== undefined && line !== "") {179 old += line.startsWith("+") ? 0 : 1;180 fresh += line.startsWith("-") ? 0 : 1;181 }182 }183184 close();185186 return hunks;187};188189/**190 * Each test seeds a whole world with its fixtures while turbo runs every191 * package's tests at once, as `dev-backend.test.ts` does.192 */193const seededWorlds = { timeout: 30_000 };
84 unmodified lines
278 })279 );280281 it.live(282 "give a failed lane's log to its claimant, and the same NotDecider to anyone else whether or not a log is kept",283 () =>284 inWorld(withFixtures, (as) =>285 Effect.gen(function* () {286 const anyone = yield* as();287 const nested = ask("render-nested-lists");288289 const { verdict } = yield* anyone.verdict({290 ask: nested,291 project: vellum,292 });293294 const ref = verdict?.lanes.find(295 ({ logRef }) => logRef !== undefined296 )?.logRef;297298 const claimant = askStates(yield* eventsOf(anyone)).get(299 nested300 )?.claimant;301302 const read = (client: Reader, logRef: string) =>303 Effect.match(client.evidence({ project: vellum, ref: logRef }), {304 onFailure: ({ _tag }): string => _tag,305 onSuccess: ({ lane }): string => lane,306 });307308 const owner = yield* as(signedIn(claimant ?? "nobody"));309 const stranger = yield* as(signedIn("wren"));310311 expect(claimant).toBeDefined();312 expect([313 yield* read(owner, ref ?? ""),314 yield* read(stranger, ref ?? ""),315 yield* read(316 stranger,317 "push-0000000000000000000000000000000000000000-wren/unit"318 ),319 ]).toStrictEqual(["unit", "NotDecider", "NotDecider"]);320 })321 )322 );323324 it.live(325 "land one answer with a decision and the Held-back trailer, and one with neither",326 () =>327 Effect.gen(function* () {328 const { byAsk, decided, plain } = yield* answersRead;
153 unmodified lines
482 mine.newcomers.length > 0,483 mine.unattended.length > 0,484 merged.overflow >= 3,485 ]).toStrictEqual([true, true, true]);403 expect([...kinds].toSorted()).toStrictEqual([404 "Finish",405 "OpenProposal",406 "PostureChange",407 "ProxyWidened",408 "RaiseRatchet",409 "SecretInTree",410 "StrayPush",411 "Vouch",412 "Waiver",413 ]);486 expect([...kinds].toSorted()).toStrictEqual(487 Object.keys(DecisionSubject.cases).toSorted()488 );489 })490 )491 );492
23 unmodified lines
516517 expect(finish?.evidence.map(({ label }) => label)).toContain("fork");518 expect(placed).toHaveLength(1);519 expect(patch).toContain(`+++ b/${placed[0]?.path}`);520521 // Every hunk holds the lines its header declares, or the diff view refuses it.522 const hunks = hunksOf(patch ?? "");523524 expect(hunks.length).toBeGreaterThan(0);525 expect(hunks.map(({ counted }) => counted)).toStrictEqual(526 hunks.map(({ declared }) => declared)527 );528 })529 )530 );531
192 unmodified lines