Skip to content
Myr

Set a migrate ask's callers ratchet at its count when it opens, count callers only in the packages its territory spans, and call the family's asks children

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

Review of 506 against its issue (Spec) and AGENTS.md / spec §7 (Standards). - Fix: the opening recorded the callers ratchet through `afterLanding`, which only lowers. A baseline a closed migrate ask of the same name left lower (nothing counts callers once it closes, so callers can come back) stayed below the new count, and every answer that changed nothing was then refused `Weakened`. The opening now sets `callers-<from>` at its count (`opens.callers`, beside the lowering `counted`). While a migrate ask of that name is open no answer can raise the count, so the set never hides a raise. Test: "records the callers ratchet at the counted total, over a lower one a closed migrate ask left" (30 left by `move-p2-fetch`, then one caller added by an answer nothing counted, then the family opens at 31; red at 30 before the fix). - Fix: `callersIn` read the whole total for a territory that spans some packages but not all, so a migrate ask over p1 and p2 opened red first when only p3 had callers. It now sums the packages the territory spans. It still reads the total when the territory spans every package or none (a repo with no modules), and one package's count when the territory names it. Test: a `callersIn` table (one package, every package, two of six; red on the third before the fix). - Test gap: a family file that would replace an ask the project holds is refused `TouchedJudge{paths}`, and nothing lands. This path was untested. It is now covered by a case that is red with the guard removed. - Test gap: case 1 now asserts the family's opening commit carries `Asked-by: alice` (the issue's Want: "one platform landing (`Asked-by` the decider)"). - Vocabulary: the issue, CAA §2.F and the Interface (`children`, `deleteChild`, `childId`) say "child ask" and "delete child", but the prose, local names, test titles, the generated file header and the opening commit's body said "step". In project.ts "step" already names an answer's landing steps (`Settled.steps`, `runStep`). Renamed to child throughout the diff. The opening body now reads "Its child asks, the last waiting on the rest:". The generated `kind` variable is `own`. - Test cleanup: the inheritance case compares picked fields directly instead of deduped JSON strings, and drops a no-op `kind: parent.kind`. - Checked and kept: the stale-tree skip in `ratchetJudged` (red without it, as the builder said). It is safe: the landing lifecycle's `moved` sends a tree checked on an old main back through Merging and Checking before it can land. - verify green (project 379 tests, 5 new; debt at baseline; platform entry 1,604,270 of 1,665,000).

authored by oscabriel · committed by oscabriel · parent 15afcac · Browse files · 3 files+318 added−152 removed
This commit

State

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

Diff stats

3 files+318 added−152 removed

  • tests:+215 added−68 removed
  • other:+103 added−84 removed

3 files+318 added−152 removed

modified:packages/project/src/migrate.ts+59 added-52 removed
1/**2 * A migrate ask's family (CAA §2.F): one ask that moves every use of a name3 * to another opens, when its callers sit in two or more of the project's4 * modules, as one step per module with callers, each with that module as5 * its territory and "no callers in this module" as its check, and a delete6 * step that waits on every step and checks the name is gone. The steps'7 * territories are disjoint, so their claims never overlap and their answers8 * re-merge cleanly through the serial landing queue; the parent closes when9 * its last step lands.4 * modules, as one child ask per module with callers, each with that module5 * as its territory and "no callers in this module" as its check, and a6 * delete child that waits on every child and checks the name is gone. The7 * children's territories are disjoint, so their claims never overlap and8 * their answers re-merge cleanly through the serial landing queue; the9 * parent closes when its last child lands.10 *11 * Pure: the callers are counted by the project's own command (its stdout is12 * `CallerCount`), never by a scan here, and the service lands the family and13 * moves it after each landing.
45 unmodified lines
59}6061/** A migrate ask split into its family, and what its opening lands. */62export interface MigrateFamily {63 /** The migrate ask, blocked by every step and the delete step. */63 /** The migrate ask, blocked by every child and the delete child. */64 readonly parent: Ask;65 /** One step per module with callers, in the policy's module order. */65 /** One child per module with callers, in the policy's module order. */66 readonly children: Array.NonEmptyReadonlyArray<Ask>;67 /** The last step: the name is gone. Blocked by every step until they land. */67 /** The last child: the name is gone. Blocked by every child until they land. */68 readonly deleteChild: Ask;69 /** The steps' and the delete step's ask files, in that order. */69 /** The children's and the delete child's ask files, in that order. */70 readonly files: Array.NonEmptyReadonlyArray<FamilyFile>;71 /** The callers ratchet the opening records, at the counted total. */72 readonly ratchet: {73 readonly name: RatchetName;
8 unmodified lines
82 .replaceAll(/[^a-z0-9]+/gu, "-")83 .replaceAll(/^-+|-+$/gu, "");8485/**86 * The id of a family's step in `module`: `drop-legacy-fetch-p1`. It never86 * The id of a family's child in `module`: `drop-legacy-fetch-p1`. It never87 * holds `--`, which repo names keep as their separator (spec §4.5).88 */89export const childId = (parent: AskId, module: string): AskId =>90 AskId.make(`${parent}-${slug(module) || "root"}`);9192/** The id of a family's delete step: `drop-legacy-fetch-delete`. */92/** The id of a family's delete child: `drop-legacy-fetch-delete`. */93export const deleteChildId = (parent: AskId): AskId =>94 AskId.make(`${parent}-delete`);9596/** The ratchet on a name's callers: `legacyFetch` → `callers-legacyfetch`. */
6 unmodified lines
103 asks: ReadonlyMap<AskId, Ask>104): readonly AskId[] =>105 ask.blockedBy.filter((blocker) => asks.get(blocker)?.state !== "closed");106107/** Whether a family is done: it has steps, and every one has closed. */107/** Whether a family is done: it has children, and every one has closed. */108export const familyClosed = (109 parent: AskId,110 asks: ReadonlyMap<AskId, Ask>111): boolean => {
20 unmodified lines
132};133134/**135 * The callers an ask's own check counts: in its module, when its territory136 * names one; everywhere, when it spans the repo.136 * names one; in the modules it spans, when it spans some but not all;137 * everywhere, when it spans them all or none (a repo with no modules).138 */139export const callersIn = (140 territory: Territory,141 counts: CallerCount,142 modules: readonly Territory[]142): number =>143 modules.some(({ module }) => module === territory.module)144 ? (counts.byModule[territory.module] ?? 0)145 : counts.total;143): number => {144 const within = modulesWithin(territory, modules);145146 return within.length === 0 || within.length === modules.length147 ? counts.total148 : within.reduce(149 (sum, { module }) => sum + (counts.byModule[module] ?? 0),150 0151 );152};153154/**155 * The ratchet a migrate ask's callers are counted by on every answer while156 * it is open: its count command's `total`, over the whole project.157 */
18 unmodified lines
176177const quoted = (text: string) => JSON.stringify(text);178179const header = (parent: AskId) =>173 `// A step of the migrate ask ${parent}, written by ${Brand.name} when it opened.`;180 `// A child of the migrate ask ${parent}, written by ${Brand.name} when it opened.`;181182const sdk = quoted(`${Brand.cliPackage}/rules`);183184/** An object literal's lines, each `key: value,`, indented by two. */185const fields = (entries: readonly (readonly [string, string])[]) =>186 entries.map(([key, value]) => ` ${key}: ${value},`);187188/**182 * A step's file, through the sdk's `kinds.migrate` when the parent is of189 * A child's file, through the sdk's `kinds.migrate` when the parent is of190 * that kind, else through a kind of the parent's name made in the file.191 */185const stepFile = (step: Ask, check: MigrateCheck, parent: AskId) => {192const childFile = (child: Ask, check: MigrateCheck, parent: AskId) => {193 const stated: (readonly [string, string])[] = [194 ["parent", quoted(parent)],188 ["territory", `territory.package(${quoted(step.territory.module)})`],189 ["want", quoted(step.brief.want)],195 ["territory", `territory.package(${quoted(child.territory.module)})`],196 ["want", quoted(child.brief.want)],197 ];198199 const args: (readonly [string, string])[] = [200 ["count", quoted(check.count)],201 ["from", quoted(check.from)],202 ...(check.to === undefined ? [] : [["to", quoted(check.to)] as const]),203 ];204198 if (step.kind === "migrate") {205 if (child.kind === "migrate") {206 return [207 header(parent),208 `import { kinds, territory } from ${sdk};`,209 "",
9 unmodified lines
219 return [220 header(parent),221 `import { check, kind, territory } from ${sdk};`,222 "",216 "const step = kind({",223 "const own = kind({",224 " args: {},",225 ` check: () => check.migrate({ ${args.map(([key, value]) => `${key}: ${value}`).join(", ")} }),`,226 ` checkKind: "migrate",`,220 ` name: ${quoted(step.kind)},`,227 ` name: ${quoted(child.kind)},`,228 "});",229 "",223 "export default step.ask({",230 "export default own.ask({",231 ...fields(stated),232 "});",233 "",234 ].join("\n");235};236237/**231 * The delete step's file: the sdk has no `symbolAbsent` builder, so the238 * The delete child's file: the sdk has no `symbolAbsent` builder, so the239 * file makes a kind of the parent's name whose check is the name gone.240 */234const deleteFile = (step: Ask, check: MigrateCheck, parent: AskId) =>241const deleteFile = (child: Ask, check: MigrateCheck, parent: AskId) =>242 [243 header(parent),244 `import { kind } from ${sdk};`,245 "",239 "const step = kind({",246 "const own = kind({",247 " args: {},",248 ` check: () => ({ _tag: "SymbolAbsent", count: ${quoted(check.count)}, symbol: ${quoted(check.from)} }),`,249 ` checkKind: "symbolAbsent",`,243 ` name: ${quoted(step.kind)},`,250 ` name: ${quoted(child.kind)},`,251 "});",252 "",246 "export default step.ask({",253 "export default own.ask({",254 ...fields([248 ["blockedBy", JSON.stringify(step.blockedBy)],255 ["blockedBy", JSON.stringify(child.blockedBy)],256 ["parent", quoted(parent)],250 ["territory", JSON.stringify(step.territory)],251 ["want", quoted(step.brief.want)],257 ["territory", JSON.stringify(child.territory)],258 ["want", quoted(child.brief.want)],259 ]),260 "});",261 "",262 ].join("\n");263264const callersOf = (count: number) =>265 count === 1 ? "1 caller" : `${count} callers`;266260/** A step's want: `p1: 5 callers of legacyFetch → http.get`. */261const stepWant = (module: string, count: number, check: MigrateCheck) =>267/** A child's want: `p1: 5 callers of legacyFetch → http.get`. */268const childWant = (module: string, count: number, check: MigrateCheck) =>269 check.to === undefined270 ? `${module}: ${callersOf(count)} of ${check.from} to remove`271 : `${module}: ${callersOf(count)} of ${check.from} → ${check.to}`;272273/**267 * Splits a migrate ask into its family: a step for each module of its274 * Splits a migrate ask into its family: a child for each module of its275 * territory that has callers, in the policy's module order, and a delete269 * step blocked by all of them, each asked by the parent's asker and held276 * child blocked by all of them, each asked by the parent's asker and held277 * as the parent is held. `None` when the ask is no migrate ask, or fewer278 * than two of its modules have callers: a split of one is the ask itself.279 */280export const splitFamily = (input: {
11 unmodified lines
292293 const fileOf = (id: AskId) =>294 RepoPath.make(`${input.configDir}/asks/${id}.ask.ts`);295289 const step = (296 const member = (297 id: AskId,298 own: Pick<Ask, "blockedBy" | "brief" | "check" | "state" | "territory">299 ): Ask => ({300 ...parent,
2 unmodified lines
303 id,304 parent: parent.id,305 });306300 const children = modulesWithin(parent.territory, input.modules).flatMap(307 const called = modulesWithin(parent.territory, input.modules).flatMap(308 (module) => {309 const count = counts.byModule[module.module] ?? 0;310311 return count > 0312 ? [306 step(childId(parent.id, module.module), {313 member(childId(parent.id, module.module), {314 blockedBy: [],308 brief: { want: stepWant(module.module, count, check) },315 brief: { want: childWant(module.module, count, check) },316 check,317 state: "open",318 territory: module,319 }),
1 unmodified line
321 : [];322 }323 );324318 const [first, second, ...rest] = children;325 const [first, second, ...rest] = called;326327 if (first === undefined || second === undefined) {328 return Option.none();329 }330324 const steps = Array.make(first, second, ...rest);325 const stepIds = steps.map(({ id }) => id);331 const children = Array.make(first, second, ...rest);332 const childIds = children.map(({ id }) => id);333 const deleteId = deleteChildId(parent.id);334328 const deleteChild = step(deleteId, {329 blockedBy: stepIds,335 const deleteChild = member(deleteId, {336 blockedBy: childIds,337 brief: { want: `Delete ${check.from}: nothing calls it any more` },338 check: CheckSpec.cases.SymbolAbsent.make({339 count: check.count satisfies Command,340 symbol: check.from,
2 unmodified lines
343 territory: parent.territory,344 });345346 return Option.some({340 children: steps,347 children,348 deleteChild,349 files: Array.append(343 Array.map(steps, (each) => ({344 content: stepFile(each, check, parent.id),350 Array.map(children, (each) => ({351 content: childFile(each, check, parent.id),352 path: each.file,353 })),354 {355 content: deleteFile(deleteChild, check, parent.id),
1 unmodified line
357 }358 ),359 parent: {360 ...parent,354 blockedBy: Array.dedupe([...parent.blockedBy, ...stepIds, deleteId]),361 blockedBy: Array.dedupe([...parent.blockedBy, ...childIds, deleteId]),362 },363 ratchet: { baseline: counts.total, name: callersRatchet(check.from) },364 });365};
modified:packages/project/src/project.ts+44 added-32 removed
920 unmodified lines
921922/** A check judged by what its command prints: a lint's count, or a migrate's callers. */923const isCounted = CheckSpec.isAnyOf(["LintToZero", "Migrate", "SymbolAbsent"]);924925/** A check that counts a name's callers: a migrate, or its delete step. */925/** A check that counts a name's callers: a migrate, or its delete child. */926const countsCallers = CheckSpec.isAnyOf(["Migrate", "SymbolAbsent"]);927928/**929 * The lane an ask's check runs as: a `lintToZero`, `migrate` or
1280 unmodified lines
2210 const asksNow = (h: Hydrated, writes: Writes): ReadonlyMap<AskId, Ask> =>2211 new Map([...h.asks, ...writes.asks]);22122213 /**2214 * A migrate family once its step `landed` closed (CAA §2.F): each step2215 * waiting on its siblings opens when the last of them lands, and the2216 * parent closes on the landing that closes its last step.2214 * A migrate family once its child `landed` closed (CAA §2.F): each2215 * child waiting on its siblings opens when the last of them lands, and2216 * the parent closes on the landing that closes its last child.2217 */2218 const familyAfter = (2219 h: Hydrated,2220 writes: Writes,
9 unmodified lines
2230 }22312232 const before = asksNow(h, writes);22332234 for (const step of before.values()) {2234 for (const child of before.values()) {2235 if (2236 step.parent === parent.value &&2237 step.state === "waitingOnParent" &&2238 remainingBlockers(step, before).length === 02236 child.parent === parent.value &&2237 child.state === "waitingOnParent" &&2238 remainingBlockers(child, before).length === 02239 ) {2240 const opened: Ask = { ...step, state: "open" };2240 const opened: Ask = { ...child, state: "open" };22412242 writes.asks.set(step.id, opened);2242 writes.asks.set(child.id, opened);2243 writes.events.push(askOpened(opened, at.now));2244 }2245 }2246
324 unmodified lines
2571 const declared = input.report?.ratchets ?? [];25722573 // A tree merged onto a main that has moved on since is not judged:2574 // its counts still hold what later landings removed (a sibling2575 // step's callers), which against the baselines those landings2575 // child's callers), which against the baselines those landings2576 // lowered would read as a raise. It cannot land as it is: its land2577 // finds main moved, and it is merged and checked again first.2578 const current = Option.exists(2579 liveRow(h),
567 unmodified lines
3147 Effect.gen(function* () {3148 const { ask, composed, files, policy } = input;3149 const counts = yield* callersTwice(policy, ask, composed.commit);31503151 const counted: readonly RatchetCount[] = CheckSpec.guards.Migrate(3151 const callers: readonly RatchetCount[] = CheckSpec.guards.Migrate(3152 ask.check3153 )3154 ? [3155 {
13 unmodified lines
31693170 if (Option.isNone(family)) {3171 return {3172 asks: Array.make(ask),3173 counted,3173 callers,3174 children: [],3175 counted: [],3176 files,3175 steps: [],3177 tree: composed.tree,3178 };3179 }3180
14 unmodified lines
3195 });31963197 return {3198 asks: Array.make(parent, ...children, deleteChild),3198 counted,3199 callers,3200 children: [...children, deleteChild].map(({ id }) => id),3201 counted: [],3202 files: all,3200 steps: [...children, deleteChild].map(({ id }) => id),3203 tree,3204 };3205 });32063207 /**3208 * The landing that opens an ask: its files on main, authored by its3207 * asker. A migrate ask's landing names the steps it opened with it.3209 * asker. A migrate ask's landing names the children it opened with it.3210 */3211 const landAsk = (input: {3212 readonly ask: Ask;3213 readonly children: readonly AskId[];3214 readonly credits: readonly Credit[];3215 readonly files: Array.NonEmptyReadonlyArray<ComposedFile>;3216 readonly main: LandedSha;3214 readonly steps: readonly AskId[];3217 readonly tree: Checking["tree"];3218 }) => {3219 const requestId = RequestId.make(`open-${input.tree}`);3218 const { credits, steps } = input;3220 const { children, credits } = input;32213222 const landing = lander3223 .land({3224 author: input.ask.askedBy,
1 unmodified line
3226 message: formatLanding({3227 ask: { ask: input.ask.id, project: name },3228 assisted: [],3229 body:3228 steps.length === 03230 children.length === 03231 ? input.ask.brief.want3232 : [3233 input.ask.brief.want,3234 "",3233 "Its steps, the last waiting on the rest:",3234 ...steps.map((step) => `- ${step}`),3235 "Its child asks, the last waiting on the rest:",3236 ...children.map((child) => `- ${child}`),3237 ].join("\n"),3238 credits,3239 requestId,3240 subject: `Open ask ${input.ask.id}`,
115 unmodified lines
3356 writes,3357 })3358 : {3359 asks: Array.make(ask),3360 callers: [],3361 children: [],3362 counted: yield* redTwice(policy, ask, composed.commit),3363 files,3360 steps: [],3364 tree: composed.tree,3365 };33663367 const landed = yield* landAsk({3368 ask,3369 children: opens.children,3370 credits: opening.credits,3371 files: opens.files,3372 main,3369 steps: opens.steps,3373 tree: opens.tree,3374 });33753376 const opened = Array.map(opens.asks, (each): Ask => ({
3 unmodified lines
33803381 for (const each of opened) {3382 writes.asks.set(each.id, each);33833381 // A step that waits on others opens when they land.3384 // A child that waits on others opens when they land.3385 if (each.state === "open") {3386 writes.events.push(askOpened(each, now));3387 }3388 }
12 unmodified lines
3401 "row",3402 yield* withPolicyAt({ ...row, landed: landed.sha }, landed.sha, now)3403 );34043402 // The opening landing records the baselines its check's count read.3403 putRatchets(3404 h,3405 writes,3406 afterLanding(baselinesNow(h, writes), opens.counted, landed.sha)3407 .baselines3408 );3405 // The opening landing records the baselines its check's count read,3406 // and sets a migrate ask's callers ratchet at its count: a lower3407 // baseline a closed migrate ask of the same name left counted3408 // nothing since, and while one is open no answer can raise it.3409 putRatchets(h, writes, [3410 ...afterLanding(baselinesNow(h, writes), opens.counted, landed.sha)3411 .baselines,3412 ...opens.callers.map(3413 ({ count, ratchet, territory }): RatchetBaseline => ({3414 count,3415 ratchet,3416 setAt: landed.sha,3417 territory,3418 })3419 ),3420 ]);34213422 return { ask: Array.headNonEmpty(opened), landed: landed.sha };3423 });3424
850 unmodified lines
modified:packages/project/test/migrate.test.ts+215 added-68 removed
1/**2 * The migrate split family (CAA §2.F): one migrate ask over six packages3 * opens as six steps, one per package, and a delete step that waits on4 * them; six people claim the six at once, the steps land one by one through5 * the serial queue, and the delete step's landing closes the parent.3 * opens as six child asks, one per package, and a delete child that waits4 * on them; six people claim the six at once, the children land one by one5 * through the serial queue, and the delete child's landing closes the parent.6 *7 * The world is `world.ts`'s over memory adapters, with three stand-ins for8 * what the platform runs elsewhere:9 * - a Checker that runs the project's caller count on the tree it is given
19 unmodified lines
29import { CheckSpec } from "@repo/protocol/domain/check";30import { Command, Glob, SymbolName } from "@repo/protocol/domain/common";31import type { ProjectEvent } from "@repo/protocol/domain/event";32import { Outcome } from "@repo/protocol/domain/outcome";33import type { Territory } from "@repo/protocol/domain/territory";34import {35 AskId,36 Handle,37 KindName,
4 unmodified lines
42 RequestId,43} from "@repo/protocol/ids";44import type { CommitSha } from "@repo/protocol/ids";45import { Anonymous, Person } from "@repo/protocol/principal";45import { AskBlocked, NotRedFirst, Weakened } from "@repo/protocol/refusal";46import {47 AskBlocked,48 NotRedFirst,49 TouchedJudge,50 Weakened,51} from "@repo/protocol/refusal";52import {53 EvaluationFacts,54 RulesEvaluator,55 sdkVersion,56} from "@repo/rules/rules-evaluator";
20 unmodified lines
77import { Lander } from "../src/lander.ts";78import { LandingCommand } from "../src/landing.ts";79import type { Change } from "../src/landing.ts";80import {81 callersIn,82 childId,83 deleteChildId,84 familyClosed,85 remainingBlockers,
22 unmodified lines
108const total = 37;109110const answerers = ["bob", "carol", "dave", "eve", "frank", "grace"] as const;111105/** heidi answers the delete step; ivan the plain ask beside the family. */112/** heidi answers the delete child; ivan the plain ask beside the family. */113const others = ["heidi", "ivan"] as const;114115const family = sixChildren({ symbol, to: "http.get" });116
33 unmodified lines
150const mainRef = RefName.make("refs/heads/main");151152const parentId = AskId.make("drop-legacy-fetch");153147const stepIdOf = (name: Package) => AskId.make(`${parentId}-${name}`);154const childIdOf = (name: Package) => AskId.make(`${parentId}-${name}`);155149const childIds = Array.map(packages, stepIdOf);156const childIds = Array.map(packages, childIdOf);157158const deleteId = AskId.make(`${parentId}-delete`);159160const tidyId = AskId.make("tidy-p6");
479 unmodified lines
640// ------------------------------------------------------------- the story641642/**643 * The whole family: alice opens a plain ask and the migrate ask, six637 * people claim the six steps at once and land them one by one, a plain638 * answer that adds a caller is refused on the way, and the delete step644 * people claim the six children at once and land them one by one, a plain645 * answer that adds a caller is refused on the way, and the delete child646 * lands last.647 */648const story = Effect.gen(function* () {649 yield* advanceTo("2026-10-07T12:00:00Z");
14 unmodified lines
664 files: parentFiles,665 });666667 const atOpen = {668 children: yield* Effect.forEach(childIds, (id) => shown(api, id)),669 commit: yield* commitOf(opened.landed),670 deleteChild: yield* shown(api, deleteId),671 files: yield* Effect.forEach([parentId, ...childIds, deleteId], (id) =>672 holds(opened.landed, `${Brand.configDir}/asks/${id}.ask.ts`)673 ),674 listed: yield* listed(api),675 ratchets: yield* ratchetRows,668 steps: yield* Effect.forEach(childIds, (id) => shown(api, id)),676 };677678 const landingsBefore = yield* landingCount;679
13 unmodified lines
693 deleteChild: yield* api.claim(person("heidi"), deleteId).pipe(Effect.flip),694 parent: yield* api.claim(person("heidi"), parentId).pipe(Effect.flip),695 };696690 // Six people claim the six steps at once.697 // Six people claim the six children at once.698 const claims = yield* Effect.forEach(699 Array.zip(answerers, childIds),700 ([who, id]) => api.claim(person(who), id),701 { concurrency: "unbounded" }
4 unmodified lines
706 );707708 const tidyClaim = yield* api.claim(person("ivan"), tidyId);709703 /** Step `n`'s claimant answers it from where they claimed, and it lands. */704 const landStep = (n: number) =>710 /** Child `n`'s claimant answers it from where they claimed, and it lands. */711 const landChild = (n: number) =>712 Effect.gen(function* () {713 const name = packages[n] ?? "p1";714715 yield* answer(api, {709 ask: stepIdOf(name),716 ask: childIdOf(name),717 base: opened.landed,718 change: migrated(name),719 who: person(answerers[n] ?? "bob"),720 });721722 return yield* mainTip;723 });724718 const firstThree = yield* Effect.forEach([0, 1, 2], landStep);725 const firstThree = yield* Effect.forEach([0, 1, 2], landChild);726727 const midFamily = {728 deleteClaim: yield* api.claim(person("heidi"), deleteId).pipe(Effect.flip),729 main: yield* mainTip,
17 unmodified lines
747 main: yield* mainTip,748 outcomes: yield* outcomesOf(api, "ivan"),749 };750744 const lastThree = yield* Effect.forEach([3, 4, 5], landStep);751 const lastThree = yield* Effect.forEach([3, 4, 5], landChild);752753 const afterSix = {754 deleteChild: yield* shown(api, deleteId),755 parent: yield* shown(api, parentId),
8 unmodified lines
764 who: person("heidi"),765 });766767 const deleteLanded = yield* mainTip;761 const stepsLanded = [...firstThree, ...lastThree];768 const childrenLanded = [...firstThree, ...lastThree];769770 return {771 afterReplay,772 afterSix,773 atOpen,774 beforeFamily,775 childrenLanded,776 claims,777 deleteLanded,778 events: (yield* api.events(0, 1000)).map(({ event }) => event),779 forks,772 landings: yield* Effect.forEach([...stepsLanded, deleteLanded], commitOf),780 landings: yield* Effect.forEach(781 [...childrenLanded, deleteLanded],782 commitOf783 ),784 listedAtEnd: yield* listed(api),785 midFamily,786 opened,787 outcomes: yield* Effect.forEach([...answerers, "heidi"], (who) =>
2 unmodified lines
790 parentAtEnd: yield* shown(api, parentId),791 ratchetsAtEnd: yield* ratchetRows,792 refusedEarly,793 replay,783 stepsLanded,794 tidyAfter,795 };796});797
29 unmodified lines
827layer(Layer.effect(Seen, story).pipe(Layer.provide(worldWith())), wholeStory)(828 "a migrate ask over six packages",829 (cases) => {830 cases.effect(821 "1. opens as one platform commit adding the parent, the six steps and the delete step",831 "1. opens as one platform commit adding the parent, the six children and the delete child",832 () =>833 Effect.map(seen, ({ atOpen, beforeFamily, opened }) => {834 expect({835 asked: atOpen.commit.trailers.filter(836 ({ key }) => key === "Asked-by"837 ),838 author: atOpen.commit.author,839 files: atOpen.files,840 opened: opened.ask.id,841 parents: atOpen.commit.parents,842 }).toStrictEqual({843 asked: [askedByAlice],844 author: authorLine(alice.handle),845 files: Array.makeBy(8, () => true),846 opened: parentId,847 parents: [beforeFamily],
3 unmodified lines
851 );852 })853 );854841 cases.effect("1. gives each step its own package as its territory", () =>855 cases.effect("1. gives each child its own package as its territory", () =>856 Effect.map(seen, ({ atOpen }) => {857 expect(844 atOpen.steps.map(({ brief, check, parent, territory }) => ({858 atOpen.children.map(({ brief, check, parent, territory }) => ({859 check: check._tag,860 parent,861 territory: territory.paths,862 want: brief.want,
9 unmodified lines
872 })873 );874875 cases.effect(862 "1. blocks the delete step on the six, and the parent on all seven",876 "1. blocks the delete child on the six, and the parent on all seven",877 () =>878 Effect.map(seen, ({ atOpen, opened }) => {879 expect({880 blockedBy: atOpen.deleteChild.blockedBy,
33 unmodified lines
914 })915 );916917 cases.effect(904 "2. refuses a claim on the delete step, or on the parent, as blocked",918 "2. refuses a claim on the delete child, or on the parent, as blocked",919 () =>920 Effect.map(seen, ({ refusedEarly }) => {921 expect(refusedEarly).toStrictEqual({922 deleteChild: AskBlocked.of(deleteId, childIds),
2 unmodified lines
925 })926 );927928 cases.effect(915 "3. lets six people claim the six steps at once, each in a fork",929 "3. lets six people claim the six children at once, each in a fork",930 () =>931 Effect.map(seen, ({ claims, forks }) => {932 expect(933 claims.map(({ claim }) => [claim.ask, claim.claimant])
4 unmodified lines
938939 cases.effect(940 "4. lands the six answers in turn, none stale, each authored by its claimant and asked by alice",941 () =>928 Effect.map(seen, ({ landings, outcomes, stepsLanded }) => {942 Effect.map(seen, ({ landings, outcomes, childrenLanded }) => {943 expect(outcomes.slice(0, 6)).toStrictEqual(930 stepsLanded.map((sha) => [Outcome.cases.Landed.make({ sha })])944 childrenLanded.map((sha) => [Outcome.cases.Landed.make({ sha })])945 );946 expect(947 landings.slice(0, 6).map(({ author, trailers }) => ({948 asked: trailers.filter(({ key }) => key === "Asked-by"),
8 unmodified lines
957 })958 );959960 cases.effect(947 "5. still refuses the delete step after three land, naming the three still open",961 "5. still refuses the delete child after three land, naming the three still open",962 () =>963 Effect.map(seen, ({ midFamily }) => {964 expect(midFamily.deleteClaim).toStrictEqual(965 AskBlocked.of(966 deleteId,953 Array.map(["p4", "p5", "p6"] as const, stepIdOf)967 Array.map(["p4", "p5", "p6"] as const, childIdOf)968 )969 );970 })971 );972959 cases.effect("lowers the callers ratchet as each step lands", () =>973 cases.effect("lowers the callers ratchet as each child lands", () =>974 Effect.map(seen, ({ midFamily, ratchetsAtEnd }) => {975 expect([midFamily.ratchets, ratchetsAtEnd]).toStrictEqual([976 [977 {
33 unmodified lines
1011 })1012 );10131014 cases.effect(1001 "6. opens the delete step once the six land, while the parent waits on it",1015 "6. opens the delete child once the six land, while the parent waits on it",1016 () =>1017 Effect.map(seen, ({ afterSix, events }) => {1018 expect([1019 afterSix.deleteChild.state,
7 unmodified lines
1027 })1028 );10291030 cases.effect(1017 "6. lands the delete step by heidi, and closes the parent on that landing",1031 "6. lands the delete child by heidi, and closes the parent on that landing",1032 () =>1033 Effect.map(1034 seen,1035 ({
43 unmodified lines
1079 ask: parentId,1080 files: Array.make(askFile(parentId)),1081 });10821069 const steps = Array.zip(packages, answerers);1083 const children = Array.zip(packages, answerers);10841085 yield* Effect.forEach(1072 steps,1073 ([name, who]) => api.claim(person(who), stepIdOf(name)),1086 children,1087 ([name, who]) => api.claim(person(who), childIdOf(name)),1088 { concurrency: "unbounded" }1089 );10901091 yield* Effect.forEach(1078 steps,1092 children,1093 ([name, who]) =>1094 answer(api, {1081 ask: stepIdOf(name),1095 ask: childIdOf(name),1096 base: opened.landed,1097 change: migrated(name),1098 who: person(who),1099 }),
13 unmodified lines
1113 ratchets: yield* ratchetRows,1114 };1115}).pipe(Effect.provide(worldWith()));11161103describe("six answers to the six steps at once", () => {1117describe("six answers to the six children at once", () => {1118 it.effect(1119 "all land, none stale and none refused by the callers ratchet",1120 () =>1121 Effect.map(allAtOnce, (seenThen) => {
32 unmodified lines
1154 ratchets: yield* ratchetRows,1155 };1156 }).pipe(Effect.provide(worldWith(options)));11571158/**1159 * A migrate ask over p2 lands and closes, leaving its callers ratchet at1160 * 30; with no migrate ask open nothing counts callers, so ivan's answer1161 * adds one in p6 and lands; then alice opens the family over 31 callers.1162 */1163const reopening = Effect.gen(function* () {1164 yield* advanceTo("2026-10-07T12:00:00Z");11651166 const api = yield* projectService(project);1167 const onePackage = AskId.make("move-p2-fetch");11681169 yield* fromFirstPush(api);1170 yield* api.openAsk(alice, {1171 ask: onePackage,1172 files: Array.make(askFile(onePackage)),1173 });11741175 const moving = yield* api.claim(person("bob"), onePackage);11761177 yield* answer(api, {1178 ask: onePackage,1179 base: LandedSha.make(moving.claim.base),1180 change: migrated("p2"),1181 who: person("bob"),1182 });11831184 yield* api.openAsk(alice, { ask: tidyId, files: plainFiles(tidyId) });11851186 const tidying = yield* api.claim(person("ivan"), tidyId);11871188 yield* answer(api, {1189 ask: tidyId,1190 base: LandedSha.make(tidying.claim.base),1191 change: (files) =>1192 changed(1193 files,1194 extraOf("p6"),1195 `export const extra = () => {\n${calls(symbol, 1)}};\n`1196 ),1197 who: person("ivan"),1198 });11991200 const left = yield* ratchetRows;12011202 yield* api.openAsk(alice, {1203 ask: parentId,1204 files: Array.make(askFile(parentId)),1205 });12061207 return { left, opened: yield* ratchetRows };1208}).pipe(Effect.provide(worldWith()));12091210/** alice opens p1's child ask alone first, then the migrate ask whose family would write that file again. */1211const overwriting = Effect.gen(function* () {1212 yield* advanceTo("2026-10-07T12:00:00Z");12131214 const api = yield* projectService(project);1215 const p1 = childIdOf("p1");12161217 yield* fromFirstPush(api);1218 yield* api.openAsk(alice, { ask: p1, files: Array.make(askFile(p1)) });12191220 const main = yield* mainTip;12211222 const opened = yield* Effect.result(1223 api.openAsk(alice, {1224 ask: parentId,1225 files: Array.make(askFile(parentId)),1226 })1227 );12281229 return {1230 listed: yield* listed(api),1231 main,1232 mainAfter: yield* mainTip,1233 opened,1234 };1235}).pipe(Effect.provide(worldWith()));12361237describe("opening a migrate ask", () => {1238 it.effect(1239 "is refused TouchedJudge when a child's file would replace an ask the project holds",1240 () =>1241 Effect.map(overwriting, ({ listed: open, main, mainAfter, opened }) => {1242 expect({ listed: open, mainAfter, opened }).toStrictEqual({1243 listed: [childIdOf("p1")],1244 mainAfter: main,1245 opened: Result.fail(1246 new TouchedJudge({1247 paths: [1248 RepoPath.make(1249 `${Brand.configDir}/asks/${childIdOf("p1")}.ask.ts`1250 ),1251 ],1252 })1253 ),1254 });1255 }),1256 wholeStory1257 );12581259 it.effect(1260 "is refused NotRedFirst when the two counts on main differ",1261 () =>1262 Effect.map(openingOf(parentId, { drifting: true }), (seenThen) => {1263 expect(seenThen).toStrictEqual({
18 unmodified lines
1282 wholeStory1283 );12841285 it.effect(1286 "records the callers ratchet at the counted total, over a lower one a closed migrate ask left",1287 () =>1288 Effect.map(reopening, (seenThen) => {1289 expect(seenThen).toStrictEqual({1290 left: [1291 { count: total - callers.p2, ratchet: ratchetName, territory: "." },1292 ],1293 opened: [1294 {1295 count: total - callers.p2 + 1,1296 ratchet: ratchetName,1297 territory: ".",1298 },1299 ],1300 });1301 }),1302 wholeStory1303 );13041305 it.effect(1306 "opens as one plain ask, with no family, when its territory is one package",1307 () =>1308 Effect.map(1309 openingOf("move-p2-fetch"),
48 unmodified lines
1358 "territory",1359 ]);13601361describe(splitFamily, () => {1228 it("splits as testkit's sixChildren() is written by hand: six steps and a delete step", () => {1362 it("splits as testkit's sixChildren() is written by hand: six children and a delete child", () => {1363 const made = Option.getOrThrow(split(callers));1364 const byHand = new Map(family.policy.asks.map((ask) => [ask.id, ask]));13651366 const expected = (id: AskId, state: Ask["state"]) => {
25 unmodified lines
1392 ratchet: { baseline: total, name: ratchetName },1393 });1394 });13951262 it("gives no step to a module with no callers", () => {1396 it("gives no child to a module with no callers", () => {1397 expect(1398 Option.map(split({ ...callers, p3: 0 }), ({ children }) =>1399 children.map(({ id }) => id)1400 )1401 ).toStrictEqual(1268 Option.some(Array.map(["p1", "p2", "p4", "p5", "p6"] as const, stepIdOf))1402 Option.some(Array.map(["p1", "p2", "p4", "p5", "p6"] as const, childIdOf))1403 );1404 });14051272 it("gives no step to a module outside the parent's territory", () => {1406 it("gives no child to a module outside the parent's territory", () => {1407 const narrower: Ask = {1408 ...parent,1409 territory: {1410 module: ".",
4 unmodified lines
1415 expect(1416 Option.map(split(callers, narrower), ({ children }) =>1417 children.map(({ id }) => id)1418 )1285 ).toStrictEqual(Option.some(Array.map(["p1", "p2"] as const, stepIdOf)));1419 ).toStrictEqual(Option.some(Array.map(["p1", "p2"] as const, childIdOf)));1420 });14211422 it.each([1423 ["only one module has callers", { p2: 7 }, parent],
16 unmodified lines
1440 ] as const)("does not split when %s", (_, byModule, of) => {1441 expect(split(byModule, of)).toStrictEqual(Option.none());1442 });14431310 it("holds every step to the parent's asker, kind and reserve", () => {1444 it("holds every child to the parent's asker, kind and reserve", () => {1445 const reserved: Ask = {1446 ...parent,1313 kind: parent.kind,1447 mentor: Handle.make("alice"),1448 reserve: "newcomers",1449 };14501451 const made = Option.getOrThrow(split(callers, reserved));14521453 expect(1321 Array.dedupe(1322 [...made.children, made.deleteChild].map(1323 ({ askedBy, kind, mentor, reserve }) =>1324 JSON.stringify({ askedBy, kind, mentor, reserve })1325 )1454 [...made.children, made.deleteChild].map((ask) =>1455 Struct.pick(ask, ["askedBy", "kind", "mentor", "reserve"])1456 )1327 ).toStrictEqual([1328 JSON.stringify({1457 ).toStrictEqual(1458 Array.makeBy(7, () => ({1459 askedBy: parent.askedBy,1330 kind: parent.kind,1331 mentor: "alice",1460 kind: KindName.make("migrate"),1461 mentor: Handle.make("alice"),1462 reserve: "newcomers",1333 }),1334 ]);1463 }))1464 );1465 });1466});14671468describe(callersIn, () => {1469 const twoPackages: Territory = {1470 module: ".",1471 paths: [Glob.make("packages/p1/**"), Glob.make("packages/p2/**")],1472 };14731474 it.each([1475 ["the one package it names", modules[1] ?? parent.territory, 7],1476 ["every package", parent.territory, total],1477 ["two of the six packages", twoPackages, callers.p1 + callers.p2],1478 ] as const)("counts the callers in %s", (_, territory, count) => {1479 expect(callersIn(territory, counted(callers), modules)).toStrictEqual(1480 count1481 );1482 });1483});14841485describe(childId, () => {1486 it.each([1487 ["p1", "drop-legacy-fetch-p1"],1488 ["@burrow/http-kit", "drop-legacy-fetch-burrow-http-kit"],1489 ["--Odd__Name--", "drop-legacy-fetch-odd-name"],1343 ])("names %s's step %s, an ask id with no --", (module, id) => {1490 ])("names %s's child %s, an ask id with no --", (module, id) => {1491 const named = childId(parentId, module);14921493 expect([1494 named,
1 unmodified line
1496 Schema.is(AskId)(named),1497 ]).toStrictEqual([id, false, true]);1498 });14991353 it("names the delete step apart from every step", () => {1500 it("names the delete child apart from every child", () => {1501 expect(deleteChildId(parentId)).toStrictEqual(deleteId);1502 });1503});15041358/** The family as it stands once the steps in `closed` have landed. */1505/** The family as it stands once the children in `closed` have landed. */1506const standing = (closed: readonly Package[]) => {1507 const made = Option.getOrThrow(split(callers));15081509 return new Map(1510 [made.parent, ...made.children, made.deleteChild].map((ask) => [1511 ask.id,1512 packages.some(1366 (name) => closed.includes(name) && stepIdOf(name) === ask.id1513 (name) => closed.includes(name) && childIdOf(name) === ask.id1514 )1515 ? { ...ask, state: "closed" as const }1516 : ask,1517 ])1518 );1519};15201521describe(remainingBlockers, () => {1375 it("names the steps still open, in order", () => {1522 it("names the children still open, in order", () => {1523 const asks = standing(["p1", "p3", "p5"]);15241525 expect(1526 remainingBlockers(1527 Option.getOrThrow(Option.fromUndefinedOr(asks.get(deleteId))),1528 asks1529 )1383 ).toStrictEqual(Array.map(["p2", "p4", "p6"] as const, stepIdOf));1530 ).toStrictEqual(Array.map(["p2", "p4", "p6"] as const, childIdOf));1531 });15321386 it("names none once every step has closed", () => {1533 it("names none once every child has closed", () => {1534 const asks = standing(packages);15351536 expect(1537 remainingBlockers(
12 unmodified lines
1550 });1551});15521553describe(familyClosed, () => {1407 it("is false while the delete step is open, and true once it closes", () => {1554 it("is false while the delete child is open, and true once it closes", () => {1555 const asks = standing(packages);15561410 const deleteStep = Option.getOrThrow(1557 const deleteChild = Option.getOrThrow(1558 Option.fromUndefinedOr(asks.get(deleteId))1559 );15601561 expect([1562 familyClosed(parentId, asks),1563 familyClosed(1564 parentId,1418 new Map(asks).set(deleteId, { ...deleteStep, state: "closed" })1565 new Map(asks).set(deleteId, { ...deleteChild, state: "closed" })1566 ),1567 ]).toStrictEqual([false, true]);1568 });15691423 it("is false for an ask with no steps", () => {1570 it("is false for an ask with no children", () => {1571 expect([familyClosed(tidyId, standing([]))]).toStrictEqual([false]);1572 });1573});1574
74 unmodified lines
1649 );16501651describe("the family's ask files", () => {1652 it.live(1506 "evaluate, through the sdk, to the family's steps and its delete step",1653 "evaluate, through the sdk, to the family's children and its delete child",1654 () =>1655 Effect.map(evaluatedFamily(parent), ({ evaluated, family: written }) => {1656 expect(evaluated).toStrictEqual(written);1657 }),
18 unmodified lines