Test the Lander's busy main, its bookkeeping retry and its clock, and sort a merge's conflicts by path
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixes from the review of 212 (Spec and Standards) against its issue file. - merge's StaleBase.conflicts are now sorted by whole path. The tree walk emitted them folder by folder, so src/a.ts came before src-x.ts, while the issue's Comments promise them sorted; the conflict test now plants both and asserts the order. - A land whose push of main finds the store busy is RepoBusy and leaves main alone (the Interface's HostBusy mapping had no test). - Landing the same job again writes the mirror ref and the note that came back pending, with no new commit: the retry protocol the outbox (214, 221) relies on. - A retry of an earlier landing never moves the mirror back off a later landing's commit. - The first land test now asserts the landing's commit id, built at the TestClock's time, so a commit stamped by anything but Clock fails it (it advanced the clock but asserted nothing about the time). - The busy-store test layer is now one switchable store (a BusyRefs Ref the test sets), replacing the store that refused every non-main push. - Each new test was checked against a broken adapter line (unsorted conflicts, a fixed time, no tip guard on the mirror, HostBusy mapped to VerifierBlocked) and fails by assertion. lander-isogit has 17 tests.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+244 added−24 removed
- tests:+239 added−23 removed
- other:+5 added−1 removed
Provenance
- Commit
a3a3d24- Tree
cdaba85- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
204f254
2 files changed+244 added−24 removed
modified:packages/project/src/lander/isogit.ts+5 added-1 removed
543 unmodified lines544 theirs: Option.some(theirs.tree),545 }546 );547 548+ // Sorted as whole paths: the walk's folder-by-folder order puts549+ // `src/a.ts` before `src-x.ts`, which a sort by path does not.550 if (merged.conflicts.length > 0) {551 return yield* new StaleBase({552 base: job.base,551- conflicts: merged.conflicts.map((path) => RepoPath.make(path)),553+ conflicts: Array.sort(merged.conflicts, Order.String).map((path) =>554+ RepoPath.make(path)555+ ),556 main: job.main,557 });558 }559 436 unmodified linesmodified:packages/project/test/lander-isogit.test.ts+239 added-23 removed
18 unmodified lines19 parseTrailers,20 } from "@repo/git/trailers";21 import { Verdict } from "@repo/protocol/domain/answer";22 import { Outcome } from "@repo/protocol/domain/outcome";23-import type { CommitSha } from "@repo/protocol/ids";23 import {24 AskId,25 BlobSha,26 CheckVersion,27+ CommitSha,28 Handle,29 LandedSha,30 PatchId,31 ProjectName,32 RepoPath,33 RequestId,34 TreeSha,35 } from "@repo/protocol/ids";36-import { StaleBase, VerifierBlocked } from "@repo/protocol/refusal";37-import { advanceTo } from "@repo/testkit/clock";36+import { RepoBusy, StaleBase, VerifierBlocked } from "@repo/protocol/refusal";37+import { advanceTo, at } from "@repo/testkit/clock";38 import { gitClient } from "@repo/testkit/git-client";39 import type { Files } from "@repo/testkit/git-client";40-import { DateTime, Effect, Layer, Option, Schema } from "effect";41-import { hashBlob, readCommit } from "isomorphic-git";40+import { Context, DateTime, Effect, Layer, Option, Ref, Schema } from "effect";41+import { hashBlob, readCommit, writeCommit } from "isomorphic-git";42 43 import { composeRef, Lander, landedRef, Rebuild } from "../src/lander.ts";44 import type { LandJob } from "../src/lander.ts";45 import { LanderIsogit } from "../src/lander/isogit.ts";9 unmodified lines55 const bob = Handle.make("bob");56 57 const requestId = RequestId.make("request-fix-parser-1");58 59+// When the landing in the first land test is made, by the TestClock.60+const landingTime = "2026-10-07T12:30:00Z";61+62 /** The Lander over a fresh memory store, with the store itself for the test to read. */63 const world = Layer.provideMerge(LanderIsogit, RepoHostMemory);64 65+/** The refs whose pushes the store refuses as busy; the test sets them as it goes. */66+class BusyRefs extends Context.Service<67+ BusyRefs,68+ Ref.Ref<ReadonlySet<RefName>>69+>()("test/BusyRefs") {}70+71+/** From now on, the store refuses every push of one of `refs` as busy. */72+const busy = (...refs: readonly RefName[]) =>73+ BusyRefs.use((busyRefs) => Ref.set(busyRefs, new Set(refs)));74+75 /**63- * A memory store whose pushes of any ref but `main` are refused as busy: the64- * bookkeeping after a landing cannot be written.76+ * The Lander over a fresh memory store that refuses as busy any push of a77+ * ref in `BusyRefs` (none at first), with the store for the test to read.78 */66-const busyBookkeeping = Layer.provideMerge(79+const busyWorld = Layer.provideMerge(80 LanderIsogit,81 Layer.effect(82 RepoHost,83 Effect.gen(function* () {84 const host = yield* RepoHost;85+ const busyRefs = yield* BusyRefs;86 87 return RepoHost.of({88 ...host,89 push: (name, source, updates) =>76- updates.some(({ ref }) => ref !== mainRef)77- ? Effect.fail(new HostBusy({ name }))78- : host.push(name, source, updates),90+ Effect.gen(function* () {91+ const refused = yield* Ref.get(busyRefs);92+93+ if (updates.some(({ ref }) => refused.has(ref))) {94+ return yield* new HostBusy({ name });95+ }96+97+ return yield* host.push(name, source, updates);98+ }),99 });100 })81- ).pipe(Layer.provide(RepoHostMemory))101+ ).pipe(102+ Layer.provide(RepoHostMemory),103+ Layer.provideMerge(104+ Layer.effect(BusyRefs, Ref.make<ReadonlySet<RefName>>(new Set()))105+ )106+ )107 );108 109 /** git's id for a blob holding `text`. */110 const blobOf = (text: string) =>46 unmodified lines157 158 return TreeSha.make(commit.tree);159 });160 161+ /**162+ * The id git gives a platform commit of `tree` on `parent` by `author`,163+ * made at `iso`: written in the client and never pushed.164+ */165+ const platformCommitOf = (input: {166+ readonly tree: TreeSha;167+ readonly parent: CommitSha;168+ readonly author: Handle;169+ readonly message: string;170+ readonly iso: string;171+ }) =>172+ Effect.gen(function* () {173+ const timestamp = Math.floor(174+ DateTime.toEpochMillis(at(input.iso)) / 1000175+ );176+177+ const oid = yield* Effect.promise(() =>178+ writeCommit({179+ ...client.source,180+ commit: {181+ author: {182+ ...authorLine(input.author),183+ timestamp,184+ timezoneOffset: 0,185+ },186+ committer: { ...committerLine, timestamp, timezoneOffset: 0 },187+ message: input.message,188+ parent: [input.parent],189+ tree: input.tree,190+ },191+ })192+ );193+194+ return CommitSha.make(oid);195+ });196+136- return { advance, base, treeOf };197+ return { advance, base, platformCommitOf, treeOf };198 });199 200 /** The tip of `main`, as the platform last landed it. */201 const landed = (sha: CommitSha) => LandedSha.make(sha);61 unmodified lines263 * main changed `src/b.ts` since the fork; alice's head changed `src/a.ts`264 * and added `docs/guide.md`.265 */266 const diverged = Effect.gen(function* () {206- const { advance, base, treeOf } = yield* project(start);267+ const { advance, base, platformCommitOf, treeOf } = yield* project(start);268 269 const main = yield* advance(demo, base, "Touch b", [270 ["src/a.ts", "a1\n"],271 ["src/b.ts", "b2\n"],4 unmodified lines276 ["src/a.ts", "a2\n"],277 ["src/b.ts", "b1\n"],278 ]);279 219- return { advance, base, head, main: landed(main), treeOf };280+ return {281+ advance,282+ base,283+ head,284+ main: landed(main),285+ platformCommitOf,286+ treeOf,287+ };288 });289 290 /** A land of alice's merged answer onto `main`. */291 const landOf = (input: {82 unmodified lines374 }).pipe(Effect.provide(world))375 );376 377 it.effect(310- "refuses a head that conflicts with main as StaleBase, naming the path",378+ "refuses a head that conflicts with main as StaleBase, naming every conflicting path in order",379 () =>380 Effect.gen(function* () {381 const lander = yield* Lander;314- const { advance, base } = yield* project(start);382 383+ const { advance, base } = yield* project([384+ ...start,385+ ["src-x.ts", "x1\n"],386+ ]);387+316- const main = yield* advance(demo, base, "Main's a", [388+ const main = yield* advance(demo, base, "Main's a and x", [389+ ["src-x.ts", "x-main\n"],390 ["src/a.ts", "a-main\n"],391 ["src/b.ts", "b1\n"],392 ]);393 321- const head = yield* advance(fork, base, "Alice's a", [394+ const head = yield* advance(fork, base, "Alice's a and x", [395+ ["src-x.ts", "x-alice\n"],396 ["src/a.ts", "a-alice\n"],397 ["src/b.ts", "b1\n"],398 ]);399 3 unmodified lines403 404 expect(refused).toStrictEqual(405 new StaleBase({406 base,333- conflicts: [RepoPath.make("src/a.ts")],407+ conflicts: [RepoPath.make("src-x.ts"), RepoPath.make("src/a.ts")],408 main,409 })410 );411 }).pipe(Effect.provide(world))6 unmodified lines418 () =>419 Effect.gen(function* () {420 const lander = yield* Lander;421 const repos = yield* RepoHost;348- const { base, head, main } = yield* diverged;422+ const { base, head, main, platformCommitOf } = yield* diverged;423 424 const merged = yield* lander.merge({425 base,426 fork,1 unmodified line428 main,429 repo: demo,430 });431 358- yield* advanceTo("2026-10-07T12:30:00Z");432+ yield* advanceTo(landingTime);433 434 const job = landOf({ base, head, main, tree: merged.tree });435 const result = yield* lander.land(job);436 const refs = yield* repos.refs(demo);30 unmodified lines467 { key: "Request-Id", value: requestId },468 ],469 tree: merged.tree,470 });471+ // The whole commit, its time from the Clock included.472+ expect(result.sha).toBe(473+ yield* platformCommitOf({474+ author: alice,475+ iso: landingTime,476+ message,477+ parent: main,478+ tree: merged.tree,479+ })480+ );481 expect(landedRef).toBe(`${Brand.refsPrefix}landed`);482 483 const note = Option.getOrThrow(yield* noteOn(demo, result.sha));484 85 unmodified lines570 main,571 repo: demo,572 });573 574+ yield* busy(landedRef, notesRef);575+576 const result = yield* lander.land(577 landOf({ base, head, main, tree: merged.tree })578 );579 4 unmodified lines584 expect([refs.has(landedRef), refs.has(notesRef)]).toStrictEqual([585 false,586 false,587 ]);502- }).pipe(Effect.provide(busyBookkeeping))588+ }).pipe(Effect.provide(busyWorld))589 );590 591 it.effect(592+ "writes the pending mirror ref and note when the same job lands again, with no new commit",593+ () =>594+ Effect.gen(function* () {595+ const lander = yield* Lander;596+ const repos = yield* RepoHost;597+ const { base, head, main } = yield* diverged;598+599+ const merged = yield* lander.merge({600+ base,601+ fork,602+ head,603+ main,604+ repo: demo,605+ });606+607+ const job = landOf({ base, head, main, tree: merged.tree });608+609+ yield* busy(landedRef, notesRef);610+611+ const first = yield* lander.land(job);612+613+ yield* busy();614+615+ const again = yield* lander.land(job);616+ const refs = yield* repos.refs(demo);617+618+ expect({619+ again,620+ first: first.pending,621+ mirror: refs.get(landedRef),622+ onMain: refs.get(mainRef),623+ }).toStrictEqual({624+ again: { pending: [], sha: first.sha },625+ first: ["mirror", "notes"],626+ mirror: first.sha,627+ onMain: first.sha,628+ });629+630+ const note = Option.getOrThrow(yield* noteOn(demo, first.sha));631+632+ expect(yield* decodeNote(note)).toStrictEqual(633+ Option.getOrThrow(job.verdict)634+ );635+ }).pipe(Effect.provide(busyWorld))636+ );637+638+ it.effect(639+ "never moves the mirror back to an earlier landing that lands again after a later one",640+ () =>641+ Effect.gen(function* () {642+ const lander = yield* Lander;643+ const repos = yield* RepoHost;644+ const { base, head, main } = yield* diverged;645+ const forked = Option.getOrThrow(yield* repos.readCommit(demo, base));646+ const revertId = RequestId.make("request-revert-1");647+648+ const merged = yield* lander.merge({649+ base,650+ fork,651+ head,652+ main,653+ repo: demo,654+ });655+656+ const job = landOf({ base, head, main, tree: merged.tree });657+658+ yield* busy(landedRef);659+660+ const first = yield* lander.land(job);661+662+ yield* busy();663+664+ const later = yield* lander.land({665+ author: bob,666+ main: first.sha,667+ message: formatLanding({668+ assisted: [],669+ credits: [{ handle: bob, role: "Signed-off-by" }],670+ requestId: revertId,671+ subject: "Revert the parser fix",672+ }),673+ rebuild: Rebuild.Existing({ commit: base }),674+ repo: demo,675+ requestId: revertId,676+ tree: TreeSha.make(forked.tree),677+ verdict: Option.none(),678+ });679+680+ const again = yield* lander.land(job);681+682+ expect({683+ again,684+ first: first.pending,685+ mirror: (yield* repos.refs(demo)).get(landedRef),686+ }).toStrictEqual({687+ again: { pending: [], sha: first.sha },688+ first: ["mirror"],689+ mirror: later.sha,690+ });691+ }).pipe(Effect.provide(busyWorld))692+ );693+694+ it.effect(695+ "refuses as RepoBusy when the store is busy with main, and leaves main where it was",696+ () =>697+ Effect.gen(function* () {698+ const lander = yield* Lander;699+ const repos = yield* RepoHost;700+ const { base, head, main } = yield* diverged;701+702+ const merged = yield* lander.merge({703+ base,704+ fork,705+ head,706+ main,707+ repo: demo,708+ });709+710+ yield* busy(mainRef);711+712+ const refused = yield* lander713+ .land(landOf({ base, head, main, tree: merged.tree }))714+ .pipe(Effect.flip);715+716+ expect(refused).toStrictEqual(new RepoBusy({}));717+ expect((yield* repos.refs(demo)).get(mainRef)).toBe(main);718+ }).pipe(Effect.provide(busyWorld))719+ );720+721+ it.effect(722 "refuses a rebuild that does not give the checked tree, leaving main where it was",723 () =>724 Effect.gen(function* () {725 const lander = yield* Lander;218 unmodified lines