Skip to content
Myr

code-history.test.ts

This file

Path

packages/project/test/code-history.test.ts

914 lines · 25.8 KiB · TypeScript

Last changed by

Merge build/comments-project into mainoscabrielbefore adoption49efd2a

History of this file

Take it

1import { describe, expect, it } from "@effect/vitest";2import { RepoHost, RepoSession, Revision } from "@repo/artifacts/repo-host";3import type { RepoSessionApi } from "@repo/artifacts/repo-host";4import { RepoHostMemory } from "@repo/artifacts/repo-host/memory";5import type { LandingView } from "@repo/protocol/domain/landing";6import {7  AskId,8  Handle,9  LandedSha,10  ProjectName,11  RepoName,12  RepoPath,13} from "@repo/protocol/ids";14import type { CommitSha } from "@repo/protocol/ids";15import { DateTime, Duration, Effect, Layer, Option, Ref, Schema } from "effect";1617import { CodeStore } from "../src/code-store.ts";18import { CodeStoreCounts, CodeStoreMemory } from "../src/code-store/memory.ts";19import { fileOf, logOf, whyOf } from "../src/code.ts";20import type { CodeProject } from "../src/code.ts";21import { CodeCache, CodeCacheLive } from "../src/code/cache.ts";22import type { CodeReads } from "../src/code/cache.ts";23import { FILE_WALK_CAP } from "../src/code/file-walk.ts";24import { keyOf, StoredWhy, whyKept } from "../src/code/history.ts";25import { WHY_SCAN } from "../src/code/why.ts";26import { Content, writer } from "./code-fixtures.ts";27import type { Tree } from "./code-fixtures.ts";2829const project = ProjectName.make("alice/histkit");3031const repo = RepoName.make("histkit");3233const format = RepoPath.make("src/format.ts");3435const text = (value: string) => Content.Text({ text: value });3637interface Seen {38  readonly trees: number;39  readonly blobs: number;40  readonly files: number;41  readonly commits: number;42  readonly logs: number;43  readonly peak: number;44  readonly events: readonly string[];45}4647const none: Seen = {48  blobs: 0,49  commits: 0,50  events: [],51  files: 0,52  logs: 0,53  peak: 0,54  trees: 0,55};5657type Delay = Option.Option<(id: string) => Duration.Duration>;5859const counted = (seen: Ref.Ref<Seen>, delay: Ref.Ref<Delay>) =>60  Layer.effect(61    RepoHost,62    Effect.gen(function* () {63      const host = yield* RepoHost;64      const under = yield* Ref.make(0);6566      const timed = <A, E>(67        kind: "blobs" | "commits" | "files" | "logs" | "trees",68        id: string,69        read: Effect.Effect<A, E>70      ) =>71        Effect.gen(function* () {72          const now = yield* Ref.updateAndGet(under, (count) => count + 1);7374          yield* Ref.update(seen, (was) => ({75            ...was,76            events: [...was.events, `+${id}`],77            [kind]: was[kind] + 1,78            peak: Math.max(was.peak, now),79          }));8081          const wait = yield* Ref.get(delay);8283          if (Option.isSome(wait)) {84            yield* Effect.sleep(wait.value(id));85          }8687          return yield* read;88        }).pipe(89          Effect.ensuring(90            Effect.andThen(91              Ref.update(under, (count) => count - 1),92              Ref.update(seen, (was) => ({93                ...was,94                events: [...was.events, `-${id}`],95              }))96            )97          )98        );99100      return RepoHost.of({101        ...host,102        log: (name, at, limit, offset) =>103          timed("logs", "log", host.log(name, at, limit, offset)),104        readBlob: (name, id) => timed("blobs", id, host.readBlob(name, id)),105        readCommit: (name, sha) =>106          timed("commits", sha, host.readCommit(name, sha)),107        readFile: (name, at, path) =>108          timed(109            "files",110            Revision.$match(at, {111              Branch: ({ name: branch }) => branch,112              Commit: ({ sha }) => sha,113            }),114            host.readFile(name, at, path)115          ),116        readTree: (name, id) => timed("trees", id, host.readTree(name, id)),117      });118    })119  ).pipe(Layer.provide(RepoHostMemory));120121const landingOf = (sha: CommitSha, ask: string): LandingView => ({122  ask: AskId.make(ask),123  assisted: [],124  author: Handle.make("bob"),125  credits: [],126  landedAt: DateTime.makeUnsafe("2026-10-07T12:00:00Z"),127  project,128  sha: LandedSha.make(sha),129});130131const recordOf = (head: CommitSha) =>132  Effect.gen(function* () {133    const landed = yield* Ref.make<readonly LandingView[]>([]);134    const asked = yield* Ref.make(0);135136    const code: CodeProject = {137      forks: Effect.succeed([]),138      head: Effect.succeedSome(LandedSha.make(head)),139      landings: (shas) =>140        Effect.gen(function* () {141          yield* Ref.update(asked, (count) => count + 1);142143          return (yield* Ref.get(landed)).filter(({ sha }) =>144            shas.includes(sha)145          );146        }),147      project,148      repo,149    };150151    return { asked, code, landed };152  });153154const filesOf = (formatted: string, readme: string): Tree => [155  ["README.md", text(readme)],156  ["src/format.ts", text(formatted)],157];158159const history = Effect.gen(function* () {160  const git = yield* writer;161162  const c1 = yield* git.commit("Adopt", filesOf("a\nb\n", "# one\n"), [], 1);163  const c2 = yield* git.commit("Readme", filesOf("a\nb\n", "# two\n"), [c1], 2);164165  const c3 = yield* git.commit(166    "Land iso",167    filesOf("a\niso\nb\n", "# two\n"),168    [c2],169    3170  );171172  const c4 = yield* git.commit(173    "Land week",174    filesOf("a\niso\nb\nweek\n", "# two\n"),175    [c3],176    4177  );178179  const grown = yield* git.commit(180    "Land more",181    filesOf("a\nx\ny\niso, changed\nb\nweek\n", "# two\n"),182    [c4],183    5184  );185186  const still = yield* git.commit(187    "Readme again",188    filesOf("a\niso\nb\nweek\n", "# three\n"),189    [c4],190    6191  );192193  yield* git.push(repo, [194    ["refs/heads/main", grown],195    ["refs/heads/still", still],196  ]);197198  return { c1, c3, c4, grown, still };199});200201const onIsolate = <A, E, R>(effect: Effect.Effect<A, E, R>) =>202  Effect.provide(effect, CodeCacheLive(100));203204const fromNothing = <A, E, R>(effect: Effect.Effect<A, E, R>) =>205  onIsolate(Effect.provide(effect, CodeStoreMemory));206207const whyOfView = (view: {208  readonly ranges: readonly unknown[];209  readonly commits: readonly { readonly sha: CommitSha }[];210  readonly stoppedAt?: CommitSha;211}) => ({212  commits: view.commits.map(({ sha }) => sha),213  ranges: view.ranges,214  stoppedAt: view.stoppedAt,215});216217const within = <A, E>(218  body: (counts: {219    readonly seen: Ref.Ref<Seen>;220    readonly delay: Ref.Ref<Delay>;221  }) => Effect.Effect<A, E, RepoHost | CodeStoreCounts>222) =>223  Effect.gen(function* () {224    const seen = yield* Ref.make(none);225    const delay = yield* Ref.make<Delay>(Option.none());226227    return yield* body({ delay, seen }).pipe(228      Effect.provide(Layer.merge(counted(seen, delay), CodeStoreMemory))229    );230  });231232const long = { timeout: 30_000 };233234describe("code history kept across isolates", () => {235  it.effect(236    "reads a why another isolate computed without a tree or a blob, asking only for its landings",237    () =>238      within(({ seen }) =>239        Effect.gen(function* () {240          const { grown } = yield* history;241          const { asked, code } = yield* recordOf(grown);242          const first = yield* onIsolate(whyOf(code, Option.none(), format));243244          yield* Ref.set(seen, none);245          yield* Ref.set(asked, 0);246247          const again = yield* onIsolate(whyOf(code, Option.none(), format));248          const { blobs, commits, files, logs, trees } = yield* Ref.get(seen);249250          expect(again).toStrictEqual(first);251          // The commits it names come from one page of the log, not one read each.252          expect({ blobs, commits, files, logs, trees }).toStrictEqual({253            blobs: 0,254            commits: 0,255            files: 0,256            logs: 1,257            trees: 0,258          });259          expect(yield* Ref.get(asked)).toBe(1);260        })261      )262  );263264  it.effect(265    "reads a path's log page another isolate computed without a tree or a blob",266    () =>267      within(({ seen }) =>268        Effect.gen(function* () {269          const { grown } = yield* history;270          const { code } = yield* recordOf(grown);271272          const page = {273            at: Option.none(),274            from: 0,275            limit: 2,276            path: Option.some(format),277          };278279          const first = yield* onIsolate(logOf(code, page));280281          yield* Ref.set(seen, none);282283          const again = yield* onIsolate(logOf(code, page));284          const { blobs, files, trees } = yield* Ref.get(seen);285286          expect(again).toStrictEqual(first);287          expect(first.commits).toHaveLength(2);288          expect({ blobs, files, trees }).toStrictEqual({289            blobs: 0,290            files: 0,291            trees: 0,292          });293        })294      )295  );296});297298const formatLog = (from: CommitSha) => ({299  at: Option.some(from),300  from: 0,301  limit: 30,302  path: Option.some(format),303});304305describe("code history one landing past a kept result", () => {306  it.effect(307    "reads only the two versions' blobs for a why, and agrees with the whole walk",308    () =>309      within(({ seen }) =>310        Effect.gen(function* () {311          const { c4, grown } = yield* history;312          const { code } = yield* recordOf(grown);313314          yield* onIsolate(whyOf(code, Option.some(c4), format));315          yield* Ref.set(seen, none);316317          const next = yield* onIsolate(318            whyOf(code, Option.some(grown), format)319          );320321          const counts = yield* Ref.get(seen);322          const whole = yield* fromNothing(whyOf(code, Option.none(), format));323324          expect(counts.blobs).toBeLessThanOrEqual(2);325          expect(whyOfView(next)).toStrictEqual(whyOfView(whole));326          expect(whyOfView(next).commits).toContain(grown);327        })328      )329  );330331  it.effect(332    "reads no blob for a why when the landing left the file alone",333    () =>334      within(({ seen }) =>335        Effect.gen(function* () {336          const { c4, grown, still } = yield* history;337          const { code } = yield* recordOf(grown);338          const kept = yield* onIsolate(whyOf(code, Option.some(c4), format));339340          yield* Ref.set(seen, none);341342          const next = yield* onIsolate(343            whyOf(code, Option.some(still), format)344          );345346          expect((yield* Ref.get(seen)).blobs).toBe(0);347          expect(whyOfView(next)).toStrictEqual(whyOfView(kept));348          expect(next.at).toBe(still);349        })350      )351  );352353  it.effect(354    "reads only the new commits' entries for a path's log, and agrees with the whole scan",355    () =>356      within(({ seen }) =>357        Effect.gen(function* () {358          const { c4, grown } = yield* history;359          const { code } = yield* recordOf(grown);360361          yield* onIsolate(logOf(code, formatLog(c4)));362          yield* Ref.set(seen, none);363364          const next = yield* onIsolate(logOf(code, formatLog(grown)));365          const counts = yield* Ref.get(seen);366          const whole = yield* fromNothing(logOf(code, formatLog(grown)));367368          expect(counts.trees).toBeLessThanOrEqual(4);369          expect(next).toStrictEqual(whole);370          expect(next.commits.map(({ sha }) => sha)[0]).toBe(grown);371        })372      )373  );374});375376describe("landings beside kept history", () => {377  it.effect("show on the next view once the record has them", () =>378    within(() =>379      Effect.gen(function* () {380        const { c1, grown } = yield* history;381        const { code, landed } = yield* recordOf(grown);382383        const [before, after] = yield* onIsolate(384          Effect.gen(function* () {385            const first = yield* whyOf(code, Option.none(), format);386387            yield* Ref.set(landed, [landingOf(c1, "adopt")]);388389            return [first, yield* whyOf(code, Option.none(), format)] as const;390          })391        );392393        expect(before.landings).toStrictEqual([]);394        expect(after.landings.map(({ ask, sha }) => [sha, ask])).toStrictEqual([395          [c1, "adopt"],396        ]);397      })398    )399  );400});401402const deepHistory = (count: number) =>403  Effect.gen(function* () {404    const git = yield* writer;405    const shas: CommitSha[] = [];406407    for (let at = 1; at <= count; at += 1) {408      shas.push(409        yield* git.commit(410          `Commit ${at}`,411          [412            ["a/b/c/d/deep.txt", text("deep\n")],413            ["count.txt", text(`${at}\n`)],414          ],415          shas.slice(-1),416          at417        )418      );419    }420421    const head = shas.at(-1);422423    if (head === undefined) {424      return yield* Effect.die("no commits");425    }426427    yield* git.push(repo, [["refs/heads/main", head]]);428429    return { head, shas };430  });431432describe("a cold walk", () => {433  it.live(434    "keeps at least 40 reads under way when each takes 50 ms",435    () =>436      within(({ delay, seen }) =>437        Effect.gen(function* () {438          const { head, shas } = yield* deepHistory(64);439          const { code } = yield* recordOf(head);440441          yield* Ref.set(seen, none);442          yield* Ref.set(443            delay,444            Option.some(() => Duration.millis(50))445          );446447          const view = yield* whyOf(448            code,449            Option.none(),450            RepoPath.make("a/b/c/d/deep.txt")451          );452453          expect(view.ranges).toStrictEqual([454            { end: 1, sha: shas[0], start: 1 },455          ]);456          expect((yield* Ref.get(seen)).peak).toBeGreaterThanOrEqual(40);457        })458      ),459    long460  );461462  // Counted, not timed: a batch of 16 waits for its slowest read, so while one463  // commit's file takes a second, at most its 15 neighbours finish; with no464  // barrier, every other commit does.465  it.live(466    "goes on past a slow read: every other commit's file is read while one takes a second",467    () =>468      within(({ delay, seen }) =>469        Effect.gen(function* () {470          const { head, shas } = yield* deepHistory(64);471          const { code } = yield* recordOf(head);472473          const slow = shas[62] ?? "";474475          yield* Ref.set(seen, none);476          yield* Ref.set(477            delay,478            Option.some((id) => Duration.millis(id === slow ? 1000 : 10))479          );480481          yield* whyOf(code, Option.none(), RepoPath.make("a/b/c/d/deep.txt"));482483          const { events } = yield* Ref.get(seen);484485          const during = events.slice(486            events.indexOf(`+${slow}`),487            events.indexOf(`-${slow}`)488          );489490          const others = new Set(shas.slice(0, 62).map((sha) => `-${sha}`));491492          expect(493            during.filter((event) => others.has(event)).length494          ).toBeGreaterThanOrEqual(60);495        })496      ),497    long498  );499500  it.effect(501    "reads each commit's file once in a path's log",502    () =>503      within(({ seen }) =>504        Effect.gen(function* () {505          const { head } = yield* deepHistory(200);506          const { code } = yield* recordOf(head);507508          yield* Ref.set(seen, none);509510          const { commits } = yield* logOf(code, {511            at: Option.none(),512            from: 0,513            limit: 30,514            path: Option.some(RepoPath.make("count.txt")),515          });516517          const { files, trees } = yield* Ref.get(seen);518519          expect(commits).toHaveLength(30);520          expect({ files, trees }).toStrictEqual({ files: 200, trees: 0 });521        })522      ),523    long524  );525526  it.effect(527    "looks each commit's folder up once in a folder's log",528    () =>529      within(({ seen }) =>530        Effect.gen(function* () {531          const { head } = yield* deepHistory(200);532          const { code } = yield* recordOf(head);533534          yield* Ref.set(seen, none);535536          const { commits } = yield* logOf(code, {537            at: Option.none(),538            from: 0,539            limit: 30,540            path: Option.some(RepoPath.make("a/b")),541          });542543          expect(commits).toHaveLength(1);544          // Each commit's root tree once, and `a`, the same tree in every commit,545          // once: in-flight tree reads are shared among the view's fibers.546          expect((yield* Ref.get(seen)).trees).toBe(201);547        })548      ),549    long550  );551552  it.live(553    "keeps at least 40 folder reads under way in a folder's log when each takes 50 ms",554    () =>555      within(({ delay, seen }) =>556        Effect.gen(function* () {557          const { head } = yield* deepHistory(64);558          const { code } = yield* recordOf(head);559560          yield* Ref.set(seen, none);561          yield* Ref.set(562            delay,563            Option.some(() => Duration.millis(50))564          );565566          yield* logOf(code, {567            at: Option.none(),568            from: 0,569            limit: 30,570            path: Option.some(RepoPath.make("a/b")),571          });572573          const { files, peak } = yield* Ref.get(seen);574575          expect(files).toBe(1);576          expect(peak).toBeGreaterThanOrEqual(40);577        })578      ),579    long580  );581});582583describe("a kept value that no longer decodes", () => {584  it.effect("is computed again and replaced", () =>585    within(({ seen }) =>586      Effect.gen(function* () {587        const { grown } = yield* history;588        const { code } = yield* recordOf(grown);589        const store = yield* CodeStore;590591        const key = yield* keyOf(whyKept, {592          commit: grown,593          path: format,594          repo,595          scan: WHY_SCAN,596        });597598        yield* store.put(key, '{"blob":"not an id"}');599600        const view = yield* onIsolate(whyOf(code, Option.none(), format));601        const replaced = yield* store.get(key);602603        const { blobs, files } = yield* Ref.get(seen);604605        expect(blobs + files).toBeGreaterThan(0);606        expect(view.ranges.length).toBeGreaterThan(0);607        expect(608          Option.flatMap(609            replaced,610            Schema.decodeUnknownOption(Schema.fromJsonString(StoredWhy))611          ).pipe(Option.map(({ ranges }) => ranges))612        ).toStrictEqual(Option.some(view.ranges));613        expect(614          (yield* CodeStoreCounts.use(({ counts }) => counts)).puts615        ).toBeGreaterThanOrEqual(2);616      })617    )618  );619});620621describe("what the store keeps", () => {622  it.effect(623    "is keyed under the project's own repo alone, and holds no landing",624    () =>625      Effect.gen(function* () {626        const kept = yield* Ref.make<ReadonlyMap<string, string>>(new Map());627628        const recording = Layer.succeed(CodeStore, {629          get: (key) =>630            Effect.map(Ref.get(kept), (all) =>631              Option.fromUndefinedOr(all.get(key))632            ),633          put: (key, value) =>634            Ref.update(kept, (all) => new Map([...all, [key, value]])),635        });636637        yield* Effect.gen(function* () {638          const { grown } = yield* history;639          const { code, landed } = yield* recordOf(grown);640641          yield* Ref.set(landed, [landingOf(grown, "grow-format")]);642          yield* onIsolate(whyOf(code, Option.none(), format));643          yield* onIsolate(logOf(code, formatLog(grown)));644        }).pipe(Effect.provide(Layer.merge(RepoHostMemory, recording)));645646        const all = [...(yield* Ref.get(kept))];647648        expect(all.length).toBeGreaterThan(0);649        expect(650          all.filter(([key]) => !key.startsWith(`${repo}/`))651        ).toStrictEqual([]);652        expect(653          all.filter(654            ([, value]) =>655              value.includes("grow-format") || value.includes("landedAt")656          )657        ).toStrictEqual([]);658      })659  );660});661662const sessioned = (663  sessions: Ref.Ref<readonly Option.Option<RepoSessionApi>[]>664) => {665  const noted = <A, E>(read: Effect.Effect<A, E>) =>666    Effect.flatMap(RepoSession, (session) =>667      Effect.andThen(668        Ref.update(sessions, (was) => [...was, session]),669        read670      )671    );672673  return Layer.effect(674    RepoHost,675    Effect.gen(function* () {676      const host = yield* RepoHost;677678      return RepoHost.of({679        ...host,680        log: (name, at, limit, offset) =>681          noted(host.log(name, at, limit, offset)),682        readBlob: (name, id) => noted(host.readBlob(name, id)),683        readCommit: (name, sha) => noted(host.readCommit(name, sha)),684        readFile: (name, at, path) => noted(host.readFile(name, at, path)),685        readTree: (name, id) => noted(host.readTree(name, id)),686      });687    })688  ).pipe(Layer.provide(RepoHostMemory));689};690691const sessionsIn = (sessions: readonly Option.Option<RepoSessionApi>[]) => ({692  outside: sessions.some(Option.isNone),693  sessions: new Set(sessions.flatMap(Option.toArray)).size,694});695696describe("one view's reads", () => {697  it.effect("of a cold why all run in one session", () =>698    Effect.gen(function* () {699      const sessions = yield* Ref.make<700        readonly Option.Option<RepoSessionApi>[]701      >([]);702703      yield* Effect.gen(function* () {704        const { grown } = yield* history;705        const { code } = yield* recordOf(grown);706707        yield* Ref.set(sessions, []);708        yield* onIsolate(whyOf(code, Option.none(), format));709      }).pipe(710        Effect.provide(Layer.merge(sessioned(sessions), CodeStoreMemory))711      );712713      expect(sessionsIn(yield* Ref.get(sessions))).toStrictEqual({714        outside: false,715        sessions: 1,716      });717    })718  );719720  it.effect("of a cold path's log page all run in one session", () =>721    Effect.gen(function* () {722      const sessions = yield* Ref.make<723        readonly Option.Option<RepoSessionApi>[]724      >([]);725726      yield* Effect.gen(function* () {727        const { grown } = yield* history;728        const { code } = yield* recordOf(grown);729730        yield* Ref.set(sessions, []);731        yield* onIsolate(logOf(code, formatLog(grown)));732      }).pipe(733        Effect.provide(Layer.merge(sessioned(sessions), CodeStoreMemory))734      );735736      expect(sessionsIn(yield* Ref.get(sessions))).toStrictEqual({737        outside: false,738        sessions: 1,739      });740    })741  );742});743744describe("kept history in the isolate's cache", () => {745  it.effect(746    "is kept with the heavy reads: a why's ranges grow with its file",747    () =>748      within(() =>749        Effect.gen(function* () {750          const { grown } = yield* history;751          const { code } = yield* recordOf(grown);752753          const seen = yield* Ref.make<readonly (readonly [string, boolean])[]>(754            []755          );756757          const spy: CodeReads = {758            through: (key, read, keeping = {}) =>759              Effect.andThen(760                Ref.update(seen, (was) => [761                  ...was,762                  [key, keeping.heavy === true] as const,763                ]),764                read765              ),766          };767768          yield* Effect.all([769            whyOf(code, Option.none(), format),770            logOf(code, formatLog(grown)),771          ]).pipe(Effect.provideService(CodeCache, spy));772773          const kept = (yield* Ref.get(seen)).filter(([key]) =>774            /\/(?:why|path-log)\/v\d+\//u.test(key)775          );776777          expect(kept.length).toBeGreaterThan(0);778          expect(kept.filter(([, heavy]) => !heavy)).toStrictEqual([]);779        })780      )781  );782});783784describe("a cold walk over a file", () => {785  it.effect(786    "reads the file once at each commit of a why and no folder past the head's",787    () =>788      within(({ seen }) =>789        Effect.gen(function* () {790          const { head } = yield* deepHistory(20);791          const { code } = yield* recordOf(head);792793          yield* Ref.set(seen, none);794          yield* whyOf(code, Option.none(), RepoPath.make("a/b/c/d/deep.txt"));795796          const { blobs, files, trees } = yield* Ref.get(seen);797798          expect({ blobs, files }).toStrictEqual({ blobs: 0, files: 20 });799          expect(trees).toBeLessThanOrEqual(5);800        })801      )802  );803804  it.effect(805    "reads the file once at each commit of a path's log and no folder",806    () =>807      within(({ seen }) =>808        Effect.gen(function* () {809          const { head } = yield* deepHistory(20);810          const { code } = yield* recordOf(head);811812          yield* Ref.set(seen, none);813814          const { commits } = yield* logOf(code, {815            at: Option.none(),816            from: 0,817            limit: 30,818            path: Option.some(RepoPath.make("a/b/c/d/deep.txt")),819          });820821          const { files, trees } = yield* Ref.get(seen);822823          expect(commits).toHaveLength(1);824          expect(files).toBeLessThanOrEqual(21);825          expect(trees).toBe(0);826        })827      )828  );829830  it.effect(831    "looks a file past the cap up by its folders, never reading it whole at each commit",832    () =>833      within(({ seen }) =>834        Effect.gen(function* () {835          const git = yield* writer;836          const big = "x".repeat(FILE_WALK_CAP);837838          const c1 = yield* git.commit(839            "One",840            [["big.txt", text(`${big}\n`)]],841            [],842            1843          );844845          const c2 = yield* git.commit(846            "Two",847            [["big.txt", text(`${big}\nmore\n`)]],848            [c1],849            2850          );851852          yield* git.push(repo, [["refs/heads/main", c2]]);853854          const { code } = yield* recordOf(c2);855856          yield* Ref.set(seen, none);857858          const view = yield* whyOf(859            code,860            Option.none(),861            RepoPath.make("big.txt")862          );863864          expect(view.ranges).toStrictEqual([865            { end: 1, sha: c1, start: 1 },866            { end: 2, sha: c2, start: 2 },867          ]);868          expect((yield* Ref.get(seen)).files).toBeLessThanOrEqual(1);869        })870      )871  );872});873874describe("a file's view", () => {875  it.effect(876    "reads the file in one call on a cold isolate, and nothing again on the same isolate",877    () =>878      within(({ seen }) =>879        Effect.gen(function* () {880          const { grown } = yield* history;881          const { code } = yield* recordOf(grown);882883          yield* Ref.set(seen, none);884885          const { first, again, cold } = yield* onIsolate(886            Effect.gen(function* () {887              const read = yield* fileOf(code, Option.none(), format);888              const coldReads = yield* Ref.get(seen);889890              yield* Ref.set(seen, none);891892              return {893                again: yield* fileOf(code, Option.none(), format),894                cold: coldReads,895                first: read,896              };897            })898          );899900          const { blobs, commits, files, trees } = cold;901902          expect(first.text).toBe("a\nx\ny\niso, changed\nb\nweek\n");903          expect(again).toStrictEqual(first);904          expect({ blobs, commits, files, trees }).toStrictEqual({905            blobs: 0,906            commits: 0,907            files: 1,908            trees: 0,909          });910          expect(yield* Ref.get(seen)).toStrictEqual(none);911        })912      )913  );914});