Keep a landing's trailers readable whatever its body holds, parse trailers as git does, and hold tree reads to eight at once
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Review fixes for 207, before 299 merges it. - formatLanding: a body line `---` (a Markdown rule) or git's scissors line ended the message for git and for parseTrailers, so the landing's trailers vanished and a trailer-shaped paragraph above the line passed for them (creditsOf credited a `Decided-by` written in the body). Such subject and body lines are now written indented by one space. - parseTrailers follows git's find_end_of_log_message: it also stops at the scissors line, drops a closing `Conflicts:` block, and reads an unterminated last line as terminated, as interpret-trailers does. The old parser differed from git on 181 of 3,000 random messages; this one on none. - The request trailer is `Request-Id`, the spelling 212 (idempotency by that trailer) and 214 use, not `Request-id`. - addedLines reports no lines for a submodule pointer: its id names a commit the repo does not hold, and the read used to die. - treeDiff reads at most eight trees at once through one semaphore per walk; nested `concurrency: 8` let 128 run at once on a two-level change. addedLines diffs four changes at a time, two blob reads each, so a large change set holds four files' text, not all of them. - The exported git identity type is `GitIdentity`, not `Person`, which protocol uses for a signed-in principal. - Tests: a 200-message seeded property test against real `git interpret-trailers --parse` (red on the old parser), scissors and Conflicts edge messages, a landing whose body forges credit above a divider (red before), reads in flight counted through a wrapping layer (red at 128), a submodule pointer through a wrapping layer (died before), and FetchFailed becoming UpstreamFailure.
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+405 added−65 removed
- tests:+307 added−6 removed
- other:+98 added−59 removed
Provenance
- Commit
3d547d8- Tree
b4ab301- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent
992c278
5 files changed+405 added−65 removed
modified:packages/git/src/trailers.ts+52 added-26 removed
16 unmodified lines17 readonly value: string;18 }19 20 /** A git identity: the name and email of an author or committer line. */21-export interface Person {21+export interface GitIdentity {22 readonly name: string;23 readonly email: string;24 }25 26 /** The accountable person, as a landing's author: their handle at the platform's users domain. */27-export const authorLine = (handle: Handle): Person => ({27+export const authorLine = (handle: Handle): GitIdentity => ({28 email: `${handle}@users.${Brand.domain}`,29 name: handle,30 });31 32 /** The platform, which commits every landing. */33-export const committerLine: Person = {33+export const committerLine: GitIdentity = {34 email: `platform@${Brand.domain}`,35 name: Brand.name,36 };37 15 unmodified lines53 }54 55 const ASSISTED = "Assisted-by";56 57+// C's `isspace`, which git's trailer code tests with.58+const SPACE = /^[ \t\n\v\f\r]/u;59+60+const isSpace = (text: string) => SPACE.test(text);61+62+// git's scissors line: it and everything below it are not the message.63+const SCISSORS = "# ------------------------ >8 ------------------------";64+65+/**66+ * Whether git reads `line` as the end of a commit message: a `---` divider67+ * (then a blank or the line's end) or the scissors line.68+ */69+const endsMessage = (line: string) =>70+ line.startsWith(SCISSORS) ||71+ (line.startsWith("---") && (line.length === 3 || isSpace(line.slice(3))));72+73 /** One line, so no value or subject can open a paragraph or a trailer of its own. */74 const oneLine = (text: string) => text.replaceAll(/\s+/gu, " ").trim();75 76+/**77+ * A subject or body line as written, indented by a space if git would read78+ * it as the end of the message, which would hide the trailers below it and79+ * let a paragraph above it pass for them.80+ */81+const inMessage = (line: string) => (endsMessage(line) ? ` ${line}` : line);82+83 const personOf = (handle: Handle) => {84 const { email, name } = authorLine(handle);85 86 return `${name} <${email}>`;47 unmodified lines134 ? []135 : [{ key: "Held-back", value: oneLine(input.heldBack) }]),136 ...(input.requestId === undefined137 ? []115- : [{ key: "Request-id", value: input.requestId }]),138+ : [{ key: "Request-Id", value: input.requestId }]),139 ];140 141 const body = input.body?.trim() ?? "";142 143 const paragraphs = [121- oneLine(input.subject),122- ...(body === "" ? [] : [body]),144+ inMessage(oneLine(input.subject)),145+ ...(body === "" ? [] : [body.split("\n").map(inMessage).join("\n")]),146 ...(trailers.length === 0147 ? []148 : [trailers.map(({ key, value }) => `${key}: ${value}`).join("\n")]),149 ];150 151 return `${paragraphs.join("\n\n")}\n`;152 };153 131-// C's `isspace`, which git's trailer code tests with.132-const SPACE = /^[ \t\n\v\f\r]/u;133-134-const isSpace = (text: string) => SPACE.test(text);135-154 const isBlank = (line: string) => /^[ \t\n\v\f\r]*$/u.test(line);155 156 const isComment = (line: string) => line.startsWith("#");157 28 unmodified lines186 187 return -1;188 };189 172-/** The message's lines up to a `---` divider, less trailing comments and empty lines. */190+/**191+ * The lines git reads as the log message: up to a `---` divider or the192+ * scissors line, less a closing run of comments, empty lines and an old193+ * `Conflicts:` block (git's `find_end_of_log_message`). Like git, it reads194+ * a last line with no newline as if it had one.195+ */196 const logLines = (message: string) => {197 const lines = message.split("\n");175- const ended = message.endsWith("\n");198 177- if (ended) {199+ if (message.endsWith("\n")) {200 lines.pop();201 }202 181- const divider = lines.findIndex(182- (line, at) =>183- line.startsWith("---") &&184- (line.length > 3185- ? isSpace(line.slice(3))186- : at < lines.length - 1 || ended)187- );203+ const cut = lines.findIndex(endsMessage);204+ const kept = cut === -1 ? lines : lines.slice(0, cut);205 189- const kept = divider === -1 ? lines : lines.slice(0, divider);190- let end = kept.length;206+ // Where the closing run starts; git keeps a run that starts at the top.207+ let run = 0;208+ let conflicts = false;209 192- while (end > 0 && (kept[end - 1] === "" || isComment(kept[end - 1] ?? ""))) {193- end -= 1;210+ for (const [at, line] of kept.entries()) {211+ const header = line === "Conflicts:";212+213+ if (line === "" || isComment(line) || header) {214+ conflicts ||= header;215+ run = run === 0 ? at : run;216+ } else if (!(conflicts && line.startsWith("\t")) && run !== 0) {217+ run = 0;218+ conflicts = false;219+ }220 }221 196- return kept.slice(0, end);222+ return kept.slice(0, run === 0 ? kept.length : run);223 };224 225 /**226 * Where the trailer block starts, by git's rule: the last paragraph after164 unmodified linesmodified:packages/git/src/tree-diff.ts+46 added-33 removed
1 import { ObjectId, RepoHost } from "@repo/artifacts/repo-host";2 import type { RepoNotFound, TreeEntry } from "@repo/artifacts/repo-host";3 import { BlobSha, RepoPath } from "@repo/protocol/ids";4 import type { RepoName, TreeSha } from "@repo/protocol/ids";5-import { Array, Effect, Option, Order } from "effect";5+import { Array, Effect, Option, Order, Semaphore } from "effect";6 7 /**8 * One file an answer changed, with its blob ids before and after. The same9 * shape as the gate's `Change` (`@repo/gate/facts`), which git cannot import.10 unmodified lines20 readonly line: number;21 readonly text: string;22 }23 24-// Subtrees read at once: each read is a call to the store.25-const READS = { concurrency: 8 } as const;24+// Store calls under way at once, however deep the walk or long the change set.25+const STORE_CALLS = 8;26 27-const entriesOf = (repo: RepoName, tree: Option.Option<string>) =>27+// The walk forks freely; the semaphore alone holds the store to its calls.28+const ALL = { concurrency: "unbounded" } as const;29+30+const entriesOf = (31+ calls: Semaphore.Semaphore,32+ repo: RepoName,33+ tree: Option.Option<string>34+) =>35 Option.match(tree, {36 onNone: () => Effect.succeed<readonly TreeEntry[]>([]),37 onSome: (id) =>38 RepoHost.use((host) => host.readTree(repo, ObjectId.make(id))).pipe(39+ Semaphore.withPermit(calls),40 Effect.flatMap(41 Option.match({42 onNone: () => Effect.die(`${repo} has no tree ${id}`),43 onSome: Effect.succeed,29 unmodified lines73 return after === undefined ? [] : [{ after, path: at, status: "added" }];74 };75 76 const walk = (77+ calls: Semaphore.Semaphore,78 repo: RepoName,79 prefix: string,80 base: Option.Option<string>,81 head: Option.Option<string>82 ): Effect.Effect<readonly Change[], RepoNotFound, RepoHost> =>83 Effect.gen(function* () {84 const [before, after] = yield* Effect.all(76- [entriesOf(repo, base), entriesOf(repo, head)],77- READS85+ [entriesOf(calls, repo, base), entriesOf(calls, repo, head)],86+ ALL87 );88 89 const beforeByName = new Map(before.map((entry) => [entry.name, entry]));90 const afterByName = new Map(after.map((entry) => [entry.name, entry]));91 92+ // The same id and mode: nothing under it changed, so it is never read.93 const names = Array.sort(94 new Set([...beforeByName.keys(), ...afterByName.keys()]),95 Order.String86- );96+ ).filter((name) => {97+ const old = beforeByName.get(name);98+ const next = afterByName.get(name);99 100+ return old?.sha !== next?.sha || old?.mode !== next?.mode;101+ });102+103 const changed = yield* Effect.forEach(104 names,105 (name) => {106 const old = beforeByName.get(name);107 const next = afterByName.get(name);93-94- // The same id and mode: nothing under it changed, so it is never read.95- if (old?.sha === next?.sha && old?.mode === next?.mode) {96- return Effect.succeed<readonly Change[]>([]);97- }98-108 const path = `${prefix}${name}`;109 const files = fileChange(path, fileIdOf(old), fileIdOf(next));110 const inside = [treeIdOf(old), treeIdOf(next)] as const;111 112 return Option.isNone(inside[0]) && Option.isNone(inside[1])113 ? Effect.succeed(files)105- : walk(repo, `${path}/`, inside[0], inside[1]).pipe(114+ : walk(calls, repo, `${path}/`, inside[0], inside[1]).pipe(115 Effect.map((nested) => [...files, ...nested])116 );117 },109- READS118+ ALL119 );120 121 return changed.flat();122 });123 124 /**125 * The files that differ between two trees of `repo`, read through the126 * `RepoHost` port alone: it walks both roots and descends only into subtrees118- * whose ids differ, since the store has no diff of its own.127+ * whose ids differ, since the store has no diff of its own. At most eight128+ * trees are read at once.129 */130 export const treeDiff = (131 repo: RepoName,132 base: TreeSha,133 head: TreeSha134 ): Effect.Effect<readonly Change[], RepoNotFound, RepoHost> =>125- walk(repo, "", Option.some(base), Option.some(head));135+ Effect.flatMap(Semaphore.make(STORE_CALLS), (calls) =>136+ walk(calls, repo, "", Option.some(base), Option.some(head))137+ );138 139 // git's own test: a NUL among the first bytes means the blob is not text.140 const SNIFF = 8192;141 148 unmodified lines290 text: next[start + index] ?? "",291 }));292 };293 282-const blobOf = (repo: RepoName, blob: BlobSha) =>283- RepoHost.use((host) => host.readBlob(repo, ObjectId.make(blob))).pipe(284- Effect.flatMap(285- Option.match({286- onNone: () => Effect.die(`${repo} has no blob ${blob}`),287- onSome: Effect.succeed,288- })289- )290- );291-294+/**295+ * A file's lines; none for a binary blob, or for a submodule's pointer, whose296+ * id names a commit in another repo, so the store has no blob by it.297+ */298 const textOf = (repo: RepoName, blob: BlobSha | undefined) =>299 blob === undefined300 ? Effect.succeedSome<readonly string[]>([])295- : blobOf(repo, blob).pipe(296- Effect.map((bytes) =>297- isBinary(bytes) ? Option.none() : Option.some(linesOf(bytes))301+ : RepoHost.use((host) => host.readBlob(repo, ObjectId.make(blob))).pipe(302+ Effect.map(303+ Option.flatMap((bytes) =>304+ isBinary(bytes) ? Option.none() : Option.some(linesOf(bytes))305+ )306 )307 );308 309+// Changes diffed at once, each reading its two blobs together: eight store310+// calls, and no more than four files' text held at a time.311+const CHANGES = { concurrency: STORE_CALLS / 2 } as const;312+313 /**314 * The lines each added or modified file gained, by a line diff of its blobs.303- * A binary blob (a NUL in its first 8 KiB) reports no lines.315+ * A binary blob (a NUL in its first 8 KiB) and a submodule's pointer report316+ * no lines. At most eight blobs are read at once.317 */318 export const addedLines = (319 repo: RepoName,320 changes: readonly Change[]7 unmodified lines328 (change) =>329 Effect.gen(function* () {330 const [previous, next] = yield* Effect.all(331 [textOf(repo, change.before), textOf(repo, change.after)],319- READS332+ ALL333 );334 335 const lines = Option.match(next, {336 onNone: () => [],5 unmodified lines342 });343 344 return [change.path, lines] as const;345 }),333- READS346+ CHANGES347 ).pipe(Effect.map((entries) => new Map(entries)));modified:packages/git/test/trailers.test.ts+121 added-4 removed
54 unmodified lines55 "--parse",56 "message"57 );58 59+ // git prints `key: value`; a key holds no colon, and an empty value60+ // leaves `key:` once the output is trimmed.61 return parsed === ""62 ? []63 : parsed.split("\n").map((line) => {62- const cut = line.indexOf(": ");64+ const cut = line.indexOf(":");65 64- return { key: line.slice(0, cut), value: line.slice(cut + 2) };66+ return {67+ key: line.slice(0, cut),68+ value: line.slice(cut + 1).replace(/^ /u, ""),69+ };70 });71 }).pipe(Effect.scoped);72 73+// git's scissors line: it and everything below it are not the message.74+const scissors = "# ------------------------ >8 ------------------------";75+76 // Messages whose last paragraph tests git's rules: a title is never trailers,77 // a mixed paragraph counts only with a sign-off and 25% trailers, an indented70-// line continues the trailer above it, and `---` ends the message.78+// line continues the trailer above it, `---` and the scissors line end the79+// message, and an old `Conflicts:` block at the end is not part of it.80 const edges = [81 "Only a title: Not-a-trailer\n",82 "Title\n\nProse that ends.\nAcked-by: someone\n",83 "Title\n\nProse that ends.\nSigned-off-by: bob\nAcked-by: someone\n",84 "Title\n\nFixes: the parser\n and the printer\nReviewed-by : carol\n",85 "Title\n\nBody\n\nReported-by: dee\n---\nNot-read: after the divider\n",86 "Title\n\nBody\n\nSee-also: one\n\n \n",87+ `Title\n\nBody\n\nReported-by: dee\n${scissors}\n\nNot-read: below the scissors\n`,88+ "Title\n\nBody\n\nAcked-by: someone\n\nConflicts:\n\tsrc/a.ts\n# a comment\n",89 ];90 91+// Lines git's trailer rules turn on, for messages drawn at random.92+const pieces = [93+ "Title",94+ "",95+ "",96+ "Prose here.",97+ "Acked-by: a",98+ "Signed-off-by: b",99+ "Key : v",100+ " continued",101+ "\tsrc/a.ts",102+ "# a comment",103+ "---",104+ "--- x",105+ "----",106+ "Conflicts:",107+ scissors,108+ "(cherry picked from commit 0123abc)",109+ "x:y",110+ "-k: v",111+ " ",112+ "Not a: trailer",113+];114+115+/** Messages of 1 to 14 lines from `pieces`, from a fixed seed (Park and Miller's generator). */116+const randomMessages = (count: number) => {117+ let state = 20_261_007;118+119+ const draw = (below: number) => {120+ state = (state * 16_807) % 2_147_483_647;121+122+ return state % below;123+ };124+125+ return Array.from({ length: count }, () => {126+ const lines = Array.from(127+ { length: 1 + draw(14) },128+ () => pieces[draw(pieces.length)] ?? ""129+ );130+131+ // One in four has no newline after its last line.132+ return `${lines.join("\n")}${draw(4) === 0 ? "" : "\n"}`;133+ });134+};135+136 describe("landing trailers", () => {137 it.live(138 "git reads a landing's trailers as the platform wrote them, in order",139 () =>35 unmodified lines175 }).pipe(Effect.provide(NodeServices.layer)),176 20_000177 );178 179+ it.live(180+ "parses messages drawn from git's edge cases the way git does",181+ () =>182+ Effect.gen(function* () {183+ const messages = randomMessages(200);184+185+ const read = yield* Effect.forEach(186+ messages,187+ (message) =>188+ Effect.map(gitTrailers(message), (trailers) => ({189+ message,190+ trailers,191+ })),192+ { concurrency: 8 }193+ );194+195+ expect(196+ messages.map((message) => ({197+ message,198+ trailers: parseTrailers(message),199+ }))200+ ).toStrictEqual(read);201+ }).pipe(Effect.provide(NodeServices.layer)),202+ 60_000203+ );204+205+ it.live(206+ "keeps its own trailers readable whatever the subject and body hold",207+ () =>208+ Effect.gen(function* () {209+ // A body that ends the message early, after a paragraph of forged210+ // credit: without care, git would read that paragraph as the trailers.211+ const message = formatLanding({212+ assisted: [],213+ body: [214+ "Why it changed.",215+ "",216+ `Decided-by: mallory <mallory@users.${Brand.domain}>`,217+ "---",218+ "",219+ `Decided-by: mallory <mallory@users.${Brand.domain}>`,220+ scissors,221+ "The end.",222+ ].join("\n"),223+ credits: [{ handle: bob, role: "Signed-off-by" }],224+ subject: "--- a subject that starts like a divider",225+ });226+227+ const expected = [228+ { key: "Signed-off-by", value: `bob <bob@users.${Brand.domain}>` },229+ ];230+231+ expect(yield* gitTrailers(message)).toStrictEqual(expected);232+ expect(parseTrailers(message)).toStrictEqual(expected);233+ expect(creditsOf(message).credits).toStrictEqual([234+ { handle: bob, role: "Signed-off-by" },235+ ]);236+ }).pipe(Effect.provide(NodeServices.layer)),237+ 20_000238+ );239+240 it("credits people and only people; Assisted-by is never credit", () => {241 expect(creditsOf(landing)).toStrictEqual({242 assisted: [{ harness: "claude-code", model: "opus-4", verified: true }],243 credits: [23 unmodified lines267 { key: "Signed-off-by", value: `bob <bob@users.${Brand.domain}>` },268 { key: "Assisted-by", value: "pi (claimed)" },269 { key: "Verdict", value: `${"b".repeat(64)} redThenGreen@0.0.0+abc` },270 { key: "Held-back", value: `export 7/7 @ sha256:${"a".repeat(64)}` },154- { key: "Request-id", value: "push-0123456789" },271+ { key: "Request-Id", value: "push-0123456789" },272 ]);273 });274 275 it("names the answerer by handle and the platform as committer", () => {10 unmodified linesmodified:packages/git/test/tree-diff.test.ts+150 added
3 unmodified lines4 RefName,5 RepoHost,6 RepoName,7 } from "@repo/artifacts/repo-host";8+import type { TreeEntry } from "@repo/artifacts/repo-host";9 import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";10 import { memoryFs } from "@repo/artifacts/repo-host/memory-fs";11 import { BlobSha, RepoPath, TreeSha } from "@repo/protocol/ids";12 import type { CommitSha } from "@repo/protocol/ids";38 unmodified lines51 });52 })53 ).pipe(Layer.provide(RepoHostMemory));54 55+/**56+ * The memory store, with a submodule's pointer added to the trees `links`57+ * names: git writes one as a `160000` entry naming a commit in another repo.58+ */59+const withSubmodules = (links: Ref.Ref<ReadonlyMap<string, TreeEntry>>) =>60+ Layer.effect(61+ RepoHost,62+ Effect.gen(function* () {63+ const host = yield* RepoHost;64+65+ return RepoHost.of({66+ ...host,67+ readTree: (name, tree) =>68+ Effect.gen(function* () {69+ const entries = yield* host.readTree(name, tree);70+ const link = (yield* Ref.get(links)).get(tree);71+72+ return link === undefined73+ ? entries74+ : Option.map(entries, (all) => [...all, link]);75+ }),76+ });77+ })78+ ).pipe(Layer.provide(RepoHostMemory));79+80+/** Store reads under way at once: now, and the most at any moment. */81+interface InFlight {82+ readonly now: number;83+ readonly most: number;84+}85+86+/** The memory store, with the `readTree` calls under way at once counted in `reads`. */87+const inFlightBy = (reads: Ref.Ref<InFlight>) =>88+ Layer.effect(89+ RepoHost,90+ Effect.gen(function* () {91+ const host = yield* RepoHost;92+93+ return RepoHost.of({94+ ...host,95+ readTree: (name, tree) =>96+ Ref.update(reads, ({ most, now }) => ({97+ most: Math.max(most, now + 1),98+ now: now + 1,99+ })).pipe(100+ Effect.andThen(Effect.yieldNow),101+ Effect.andThen(host.readTree(name, tree)),102+ Effect.ensuring(103+ Ref.update(reads, ({ most, now }) => ({ most, now: now - 1 }))104+ )105+ ),106+ });107+ })108+ ).pipe(Layer.provide(RepoHostMemory));109+110+/**111+ * Nine folders of nine folders, each file holding `content`: when every file112+ * changes, a walk that reads eight at a time at each depth has far more than113+ * eight reads under way.114+ */115+const grid = (content: string): Files =>116+ Array.from({ length: 81 }, (_, at) => [117+ `p${Math.floor(at / 9)}/q${at % 9}/f.txt`,118+ content,119+ ]);120+121+/** A submodule's pointer at `vendor`, naming commit `digit` × 40 in another repo. */122+const pointer = (digit: string): TreeEntry => ({123+ mode: "160000",124+ name: "vendor",125+ sha: ObjectId.make(digit.repeat(40)),126+ type: "commit",127+});128+129 /** Two commits in `demo`, and the ids of their trees and blobs as git wrote them. */130 const twoCommits = Effect.gen(function* () {131 const repos = yield* RepoHost;132 const client = yield* gitClient(memoryFs());149 unmodified lines282 }).pipe(Effect.provide(countedBy(reads)));283 })284 );285 286+ it.effect("reads at most eight trees from the store at once", () =>287+ Effect.gen(function* () {288+ const reads = yield* Ref.make<InFlight>({ most: 0, now: 0 });289+290+ yield* Effect.gen(function* () {291+ const repos = yield* RepoHost;292+ const client = yield* gitClient(memoryFs());293+ const first = yield* client.commit("before", grid("1\n"));294+ const second = yield* client.commit("after", grid("2\n"), [first]);295+296+ yield* repos.create(repo);297+ yield* repos.push(repo, client.source, [298+ { from: Option.none(), ref: main, to: second },299+ ]);300+301+ const treeOf = (sha: CommitSha) =>302+ repos303+ .readCommit(repo, sha)304+ .pipe(305+ Effect.map((commit) =>306+ TreeSha.make(Option.getOrThrow(commit).tree)307+ )308+ );309+310+ const changes = yield* treeDiff(311+ repo,312+ yield* treeOf(first),313+ yield* treeOf(second)314+ );315+316+ expect(changes).toHaveLength(81);317+ }).pipe(Effect.provide(inFlightBy(reads)));318+319+ expect(yield* Ref.get(reads)).toStrictEqual({ most: 8, now: 0 });320+ })321+ );322+323+ it.effect(324+ "counts a submodule's moved pointer as a change with no lines",325+ () =>326+ Effect.gen(function* () {327+ const links = yield* Ref.make<ReadonlyMap<string, TreeEntry>>(328+ new Map()329+ );330+331+ yield* Effect.gen(function* () {332+ const { base, head } = yield* twoCommits;333+334+ yield* Ref.set(335+ links,336+ new Map([337+ [base, pointer("a")],338+ [head, pointer("b")],339+ ])340+ );341+342+ const changes = yield* treeDiff(repo, base, head);343+ const lines = yield* addedLines(repo, changes);344+345+ expect(346+ changes.filter(({ path }) => path === RepoPath.make("vendor"))347+ ).toStrictEqual([348+ {349+ after: BlobSha.make("b".repeat(40)),350+ before: BlobSha.make("a".repeat(40)),351+ path: RepoPath.make("vendor"),352+ status: "modified",353+ },354+ ]);355+ expect(lines.get(RepoPath.make("vendor"))).toStrictEqual([]);356+ expect(lines.get(RepoPath.make("src/a.ts"))).toHaveLength(3);357+ }).pipe(Effect.provide(withSubmodules(links)));358+ })359+ );360+361 it.effect("gives a modified file's new lines, numbered in the new file", () =>362 Effect.gen(function* () {363 const { base, head } = yield* twoCommits;364 const lines = yield* addedLines(repo, yield* treeDiff(repo, base, head));85 unmodified linesmodified:packages/git/test/upstream.test.ts+36 added-2 removed
1 import { describe, expect, it } from "@effect/vitest";2-import { Fetch } from "@repo/artifacts/fetch";2+import { Fetch, FetchFailed } from "@repo/artifacts/fetch";3 import { RepoHost, RepoName, RepoNotFound } from "@repo/artifacts/repo-host";4 import type { TokenScope } from "@repo/artifacts/repo-host";5 import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";6 import {6 unmodified lines13 Stream,14 } from "effect";15 import { TestClock } from "effect/testing";16 17-import { Exchange, Upstream } from "../src/upstream.ts";17+import { Exchange, Upstream, UpstreamFailure } from "../src/upstream.ts";18 import { UpstreamRepoHost } from "../src/upstream/repo-host.ts";19 20 const repo = RepoName.make("demo");21 208 unmodified lines230 })231 )232 );233 234+ it.effect("calls a request that got no response an UpstreamFailure", () =>235+ Effect.gen(function* () {236+ const unreachable = Layer.succeed(237+ Fetch,238+ Fetch.of({239+ fetch: (request) =>240+ Effect.fail(241+ new FetchFailed({ reason: "connection reset", url: request.url })242+ ),243+ })244+ );245+246+ const minted = yield* Ref.make<readonly Minted[]>([]);247+248+ const failure = yield* Effect.gen(function* () {249+ yield* RepoHost.use((host) => host.create(repo)).pipe(Effect.orDie);250+251+ return yield* Upstream.use((upstream) =>252+ upstream.exchange(repo, advertise)253+ ).pipe(Effect.flip);254+ }).pipe(255+ Effect.provide(256+ UpstreamRepoHost.pipe(257+ Layer.provideMerge(Layer.mergeAll(store(minted), unreachable))258+ )259+ )260+ );261+262+ expect(failure).toStrictEqual(263+ new UpstreamFailure({ reason: "connection reset", repo })264+ );265+ })266+ );267+268 it.effect("passes RepoNotFound through for a repo the store lacks", () =>269 withUpstream(() =>270 Effect.gen(function* () {271 const upstream = yield* Upstream;14 unmodified lines