Skip to content
Myr

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.

authored by oscabriel · committed by oscabriel · parent 204f254 · Browse files · 2 files+244 added−24 removed
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

2 files+244 added−24 removed

modified:packages/project/src/lander/isogit.ts+5 added-1 removed
543 unmodified lines
544 theirs: Option.some(theirs.tree),545 }546 );547548 // 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 lines
modified:packages/project/test/lander-isogit.test.ts+239 added-23 removed
18 unmodified lines
19 parseTrailers,20} from "@repo/git/trailers";21import { Verdict } from "@repo/protocol/domain/answer";22import { Outcome } from "@repo/protocol/domain/outcome";23import type { CommitSha } from "@repo/protocol/ids";23import {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";36import { StaleBase, VerifierBlocked } from "@repo/protocol/refusal";37import { advanceTo } from "@repo/testkit/clock";36import { RepoBusy, StaleBase, VerifierBlocked } from "@repo/protocol/refusal";37import { advanceTo, at } from "@repo/testkit/clock";38import { gitClient } from "@repo/testkit/git-client";39import type { Files } from "@repo/testkit/git-client";40import { DateTime, Effect, Layer, Option, Schema } from "effect";41import { hashBlob, readCommit } from "isomorphic-git";40import { Context, DateTime, Effect, Layer, Option, Ref, Schema } from "effect";41import { hashBlob, readCommit, writeCommit } from "isomorphic-git";4243import { composeRef, Lander, landedRef, Rebuild } from "../src/lander.ts";44import type { LandJob } from "../src/lander.ts";45import { LanderIsogit } from "../src/lander/isogit.ts";
9 unmodified lines
55const bob = Handle.make("bob");5657const requestId = RequestId.make("request-fix-parser-1");5859// When the landing in the first land test is made, by the TestClock.60const landingTime = "2026-10-07T12:30:00Z";6162/** The Lander over a fresh memory store, with the store itself for the test to read. */63const world = Layer.provideMerge(LanderIsogit, RepoHostMemory);6465/** The refs whose pushes the store refuses as busy; the test sets them as it goes. */66class BusyRefs extends Context.Service<67 BusyRefs,68 Ref.Ref<ReadonlySet<RefName>>69>()("test/BusyRefs") {}7071/** From now on, the store refuses every push of one of `refs` as busy. */72const busy = (...refs: readonly RefName[]) =>73 BusyRefs.use((busyRefs) => Ref.set(busyRefs, new Set(refs)));7475/**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 */66const busyBookkeeping = Layer.provideMerge(79const busyWorld = Layer.provideMerge(80 LanderIsogit,81 Layer.effect(82 RepoHost,83 Effect.gen(function* () {84 const host = yield* RepoHost;85 const busyRefs = yield* BusyRefs;8687 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);9293 if (updates.some(({ ref }) => refused.has(ref))) {94 return yield* new HostBusy({ name });95 }9697 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);108109/** git's id for a blob holding `text`. */110const blobOf = (text: string) =>
46 unmodified lines
157158 return TreeSha.make(commit.tree);159 });160161 /**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 );176177 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 );193194 return CommitSha.make(oid);195 });196136 return { advance, base, treeOf };197 return { advance, base, platformCommitOf, treeOf };198 });199200/** The tip of `main`, as the platform last landed it. */201const landed = (sha: CommitSha) => LandedSha.make(sha);
61 unmodified lines
263 * main changed `src/b.ts` since the fork; alice's head changed `src/a.ts`264 * and added `docs/guide.md`.265 */266const diverged = Effect.gen(function* () {206 const { advance, base, treeOf } = yield* project(start);267 const { advance, base, platformCommitOf, treeOf } = yield* project(start);268269 const main = yield* advance(demo, base, "Touch b", [270 ["src/a.ts", "a1\n"],271 ["src/b.ts", "b2\n"],
4 unmodified lines
276 ["src/a.ts", "a2\n"],277 ["src/b.ts", "b1\n"],278 ]);279219 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});289290/** A land of alice's merged answer onto `main`. */291const landOf = (input: {
82 unmodified lines
374 }).pipe(Effect.provide(world))375 );376377 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);382383 const { advance, base } = yield* project([384 ...start,385 ["src-x.ts", "x1\n"],386 ]);387316 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 ]);393321 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 lines
403404 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 lines
418 () =>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;423424 const merged = yield* lander.merge({425 base,426 fork,
1 unmodified line
428 main,429 repo: demo,430 });431358 yield* advanceTo("2026-10-07T12:30:00Z");432 yield* advanceTo(landingTime);433434 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 lines
467 { 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`);482483 const note = Option.getOrThrow(yield* noteOn(demo, result.sha));484
85 unmodified lines
570 main,571 repo: demo,572 });573574 yield* busy(landedRef, notesRef);575576 const result = yield* lander.land(577 landOf({ base, head, main, tree: merged.tree })578 );579
4 unmodified lines
584 expect([refs.has(landedRef), refs.has(notesRef)]).toStrictEqual([585 false,586 false,587 ]);502 }).pipe(Effect.provide(busyBookkeeping))588 }).pipe(Effect.provide(busyWorld))589 );590591 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;598599 const merged = yield* lander.merge({600 base,601 fork,602 head,603 main,604 repo: demo,605 });606607 const job = landOf({ base, head, main, tree: merged.tree });608609 yield* busy(landedRef, notesRef);610611 const first = yield* lander.land(job);612613 yield* busy();614615 const again = yield* lander.land(job);616 const refs = yield* repos.refs(demo);617618 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 });629630 const note = Option.getOrThrow(yield* noteOn(demo, first.sha));631632 expect(yield* decodeNote(note)).toStrictEqual(633 Option.getOrThrow(job.verdict)634 );635 }).pipe(Effect.provide(busyWorld))636 );637638 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");647648 const merged = yield* lander.merge({649 base,650 fork,651 head,652 main,653 repo: demo,654 });655656 const job = landOf({ base, head, main, tree: merged.tree });657658 yield* busy(landedRef);659660 const first = yield* lander.land(job);661662 yield* busy();663664 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 });679680 const again = yield* lander.land(job);681682 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 );693694 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;701702 const merged = yield* lander.merge({703 base,704 fork,705 head,706 main,707 repo: demo,708 });709710 yield* busy(mainRef);711712 const refused = yield* lander713 .land(landOf({ base, head, main, tree: merged.tree }))714 .pipe(Effect.flip);715716 expect(refused).toStrictEqual(new RepoBusy({}));717 expect((yield* repos.refs(demo)).get(mainRef)).toBe(main);718 }).pipe(Effect.provide(busyWorld))719 );720721 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