1import { Database } from "bun:sqlite";2import { beforeAll, describe, expect, test } from "bun:test";3import { cp, mkdir, mkdtemp, readFile, writeFile } from "node:fs/promises";4import { tmpdir } from "node:os";5import { join } from "node:path";6import { deflateSync } from "node:zlib";7import { type Bucket, openBucket } from "../src/bucket/reader.ts";8import { readSave } from "../src/bucket/repo.ts";9import { syncAll, syncRepo } from "../src/bucket/sync.ts";10import {11 fileAt,12 filesAt,13 flagReason,14 headId,15 history,16 objectBytes,17 repoStats,18 saveByPrefix,19 timeline,20} from "../src/mirror/queries.ts";21import { applyHidden, closeMirror, mirrorState, openMirror } from "../src/mirror/store.ts";22import { openKeprDb } from "../src/server/db.ts";23import { Browser, instance } from "./browser.ts";24import { type Fixture, makeKohBucket } from "./fixture.ts";2526const text = (bytes: Uint8Array | null) => new TextDecoder().decode(bytes ?? new Uint8Array());2728async function syncTarget(fx: Fixture) {29 const dataDir = await mkdtemp(join(tmpdir(), "kepr-data-"));30 const target = {31 bucket: openBucket({ kind: "folder", path: fx.bucketDir }),32 kepr: openKeprDb(dataDir),33 mirrorDir: join(dataDir, "mirror"),34 };35 return { ...target, mirror: () => openMirror(target.mirrorDir, fx.repo) };36}3738describe("a first sync of a koh bucket", () => {39 let fx: Fixture;40 let t: Awaited<ReturnType<typeof syncTarget>>;41 beforeAll(async () => {42 fx = await makeKohBucket();43 t = await syncTarget(fx);44 await syncAll(t);45 });46 const [head, checkpoint, second, first] = [0, 1, 2, 3].map((i) => () => fx.saveIds[i] as string);4748 test("registers the repo private, with a clean last sync", () => {49 const row = t.kepr.query("SELECT public, last_sync_at, last_sync_error FROM repos").get() as {50 public: number;51 last_sync_at: number;52 last_sync_error: string | null;53 };54 expect(row.public).toBe(0);55 expect(row.last_sync_error).toBeNull();56 expect(row.last_sync_at).toBeGreaterThan(0);57 });5859 test("history is newest first and leaves out the checkpoint", () => {60 expect(headId(t.mirror())).toBe(head());61 expect(history(t.mirror(), 10, 0).map((s) => s.id)).toEqual([head(), second(), first()]);62 expect(history(t.mirror(), 1, 1).map((s) => s.message)).toEqual(["add readme and entry point"]);63 expect(timeline(t.mirror()).map((s) => s.id)).toEqual([first(), second(), head()]);64 expect(saveByPrefix(t.mirror(), checkpoint())?.is_checkpoint).toBe(true);65 });6667 test("finds a save by a unique prefix of six or more characters", () => {68 const save = saveByPrefix(t.mirror(), second().slice(0, 6));69 expect([save?.id, save?.agent, save?.session]).toEqual([second(), "test-agent", "fixture"]);70 expect(saveByPrefix(t.mirror(), second().slice(0, 5))).toBeNull();71 expect(saveByPrefix(t.mirror(), "zzzzzz")).toBeNull();72 });7374 test("reads files and their bytes at any save", () => {75 const paths = filesAt(t.mirror(), head()).map((f) => f.path);76 expect(paths).toContain("src/lib/deep/util.ts");77 const now = fileAt(t.mirror(), head(), "src/main.ts");78 const then = fileAt(t.mirror(), second(), "src/main.ts");79 expect(text(objectBytes(t.mirror(), now?.hash as string))).toContain("hello");80 expect(text(objectBytes(t.mirror(), then?.hash as string))).toContain("'hi'");81 expect(fileAt(t.mirror(), first(), "src/main.ts")).toBeNull();82 expect(fileAt(t.mirror(), head(), "docs/logo.png")?.size).toBe(70);83 });8485 test("counts saves without checkpoints, and lines and language at head", () => {86 const stats = repoStats(t.mirror());87 expect(stats.saves).toBe(3);88 expect(stats.language).toBe("TypeScript");89 90 91 expect(stats.lines).toBe(4);92 expect(stats.updated).toBe(saveByPrefix(t.mirror(), head())?.created_at ?? -1);93 });9495 test("stores the flag event", () => {96 const flag = t.mirror().query("SELECT kind, save_id, reason FROM events").get();97 expect(flag).toEqual({ kind: "flag", save_id: first(), reason: "holds a secret" });98 });99100 test("a save's flag state is its newest flag or clear event, by time and then ID", async () => {101 expect(flagReason(t.mirror(), first())).toBe("holds a secret");102 expect(flagReason(t.mirror(), head())).toBeNull();103 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-flags-")), "flags");104 const event = mirror.query(105 "INSERT INTO events (id, kind, save_id, reason, created_at, machine) VALUES (?, ?, 'aaaaaaaaaaaa', ?, ?, 'm')",106 );107 event.run("000000000001", "flag", "first", 10);108 expect(flagReason(mirror, "aaaaaaaaaaaa")).toBe("first");109 event.run("000000000002", "clear", null, 20);110 expect(flagReason(mirror, "aaaaaaaaaaaa")).toBeNull();111 112 event.run("000000000003", "flag", "again", 20);113 expect(flagReason(mirror, "aaaaaaaaaaaa")).toBe("again");114 event.run("000000000000", "clear", null, 20);115 expect(flagReason(mirror, "aaaaaaaaaaaa")).toBe("again");116 });117118 test("a strip reaches the mirror and drops the object", async () => {119 const secret = fileAt(t.mirror(), head(), "secret.txt")?.hash as string;120 expect(objectBytes(t.mirror(), secret)).not.toBeNull();121 await fx.strip("secret.txt");122 await syncAll(t);123 for (const id of fx.saveIds) expect(fileAt(t.mirror(), id, "secret.txt")).toBeNull();124 expect(objectBytes(t.mirror(), secret)).toBeNull();125 expect(fileAt(t.mirror(), head(), "src/main.ts")).not.toBeNull();126 });127});128129test("a hidden path that is then stripped stays gone when it is unhidden", async () => {130 const fx = await makeKohBucket("hidden-strip");131 const t = await syncTarget(fx);132 await syncAll(t);133 const secret = fileAt(t.mirror(), fx.saveIds[0] as string, "secret.txt")?.hash as string;134 t.kepr.query("UPDATE repos SET hidden_paths = 'secret.txt' WHERE name = ?").run(fx.repo);135 await syncAll(t);136 for (const id of fx.saveIds) expect(fileAt(t.mirror(), id, "secret.txt")).toBeNull();137 expect(objectBytes(t.mirror(), secret)).not.toBeNull();138139 await fx.strip("secret.txt");140 await syncAll(t);141 applyHidden(t.mirror(), []);142 for (const id of fx.saveIds) expect(fileAt(t.mirror(), id, "secret.txt")).toBeNull();143 expect(objectBytes(t.mirror(), secret)).toBeNull();144 expect(fileAt(t.mirror(), fx.saveIds[0] as string, "src/main.ts")).not.toBeNull();145});146147test("a whole six-character ID finds its own save, not a longer one it begins", async () => {148 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-mirror-")), "ids");149 const add = mirror.query(150 "INSERT INTO saves (id, parent, message, created_at, machine) VALUES (?, NULL, ?, 1, 'm')",151 );152 add.run("af96c8", "migrated from Koh 2");153 add.run("af96c8123456", "made by Koh 3");154 expect(saveByPrefix(mirror, "af96c8")?.message).toBe("migrated from Koh 2");155 expect(saveByPrefix(mirror, "af96c81")?.message).toBe("made by Koh 3");156});157158test("a sync lands history in batches, so one cut short resumes where it stopped", async () => {159 const fx = await makeKohBucket("batched");160 const bucket = openBucket({ kind: "folder", path: fx.bucketDir });161 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-mirror-")), fx.repo);162 163 const failing: Bucket = {164 ...bucket,165 get: (key) =>166 key.includes("/objects/") && mirrorState(mirror, "head") !== null167 ? Promise.reject(new Error("connection reset"))168 : bucket.get(key),169 };170 await expect(syncRepo(failing, mirror, fx.repo, [], 1)).rejects.toThrow("connection reset");171 const first = fx.saveIds[3] as string;172 expect(mirrorState(mirror, "head")).toBe(first);173 expect(history(mirror, 10, 0).map((s) => s.id)).toEqual([first]);174175 await syncRepo(bucket, mirror, fx.repo, [], 1);176 expect(headId(mirror)).toBe(fx.saveIds[0] as string);177 expect(history(mirror, 10, 0)).toHaveLength(3);178 expect(flagReason(mirror, first)).toBe("holds a secret");179});180181test("a save larger than a batch is stored ahead of itself, and a sync cut short within it resumes", async () => {182 const fx = await makeKohBucket("ahead");183 const bucket = openBucket({ kind: "folder", path: fx.bucketDir });184 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-mirror-")), fx.repo);185 186 const first = await readSave(bucket, fx.repo, fx.saveIds.at(-1) as string);187 const firstObjects = new Set(first.files.map((file) => file.hash)).size;188 let objectGets = 0;189 const failing: Bucket = {190 ...bucket,191 get: (key) =>192 key.includes("/objects/") && ++objectGets > firstObjects193 ? Promise.reject(new Error("connection reset"))194 : bucket.get(key),195 };196 await expect(syncRepo(failing, mirror, fx.repo, [], 1)).rejects.toThrow("connection reset");197 const stored = () =>198 mirror.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM objects").get()?.n;199 expect(mirrorState(mirror, "head")).toBeNull();200 expect(stored()).toBe(firstObjects);201202 await syncRepo(bucket, mirror, fx.repo, [], 1);203 expect(headId(mirror)).toBe(fx.saveIds[0] as string);204 expect(history(mirror, 10, 0)).toHaveLength(3);205 const guide = fileAt(mirror, fx.saveIds[0] as string, "docs/guide.md");206 expect(text(objectBytes(mirror, guide?.hash as string))).toBe(207 "# Guide\n\nRead me. It is short.\n",208 );209});210211test("object reads overlap, but never past the bytes allowed in flight", async () => {212 const fx = await makeKohBucket("in-flight");213 const bucket = openBucket({ kind: "folder", path: fx.bucketDir });214 const peak = async (readBytes?: number) => {215 let reading = 0;216 let most = 0;217 const counting: Bucket = {218 ...bucket,219 get: async (key) => {220 if (!key.includes("/objects/")) return bucket.get(key);221 most = Math.max(most, ++reading);222 await Bun.sleep(5);223 reading--;224 return bucket.get(key);225 },226 };227 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-mirror-")), fx.repo);228 await syncRepo(counting, mirror, fx.repo, [], undefined, readBytes);229 expect(headId(mirror)).toBe(fx.saveIds[0] as string);230 return most;231 };232 expect(await peak()).toBeGreaterThan(1);233 234 expect(await peak(1)).toBe(1);235});236237test("a read the gate admits after the batch filled waits for the next batch", async () => {238 const fx = await makeKohBucket("deferred");239 const bucket = openBucket({ kind: "folder", path: fx.bucketDir });240 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-mirror-")), fx.repo);241 const stored = () =>242 mirror.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM objects").get()?.n ?? 0;243 let read = 0;244 const unstored: number[] = [];245 const counting: Bucket = {246 ...bucket,247 get: async (key) => {248 249 if (key.includes("/objects/")) unstored.push(read++ - stored());250 return bucket.get(key);251 },252 };253 await syncRepo(counting, mirror, fx.repo, [], 1, 1);254 expect(read).toBeGreaterThan(2);255 expect(new Set(unstored)).toEqual(new Set([0]));256});257258test("a failed read reports only once every other read has settled", async () => {259 const fx = await makeKohBucket("settled");260 const bucket = openBucket({ kind: "folder", path: fx.bucketDir });261 const mirror = openMirror(await mkdtemp(join(tmpdir(), "kepr-mirror-")), fx.repo);262 let reading = 0;263 let reads = 0;264 const failing: Bucket = {265 ...bucket,266 get: async (key) => {267 if (!key.includes("/objects/")) return bucket.get(key);268 if (reads++ === 0) throw new Error("connection reset");269 reading++;270 await Bun.sleep(30);271 reading--;272 return bucket.get(key);273 },274 };275 await expect(syncRepo(failing, mirror, fx.repo)).rejects.toThrow("connection reset");276 expect(reading).toBe(0);277});278279test("a new save syncs incrementally and a bad format is recorded as the last sync error", async () => {280 const fx = await makeKohBucket("growing");281 const t = await syncTarget(fx);282 await syncAll(t);283 await writeFile(join(fx.repoDir, "new.txt"), "new\n");284 Bun.spawnSync(["koh", "save", "add new"], {285 cwd: fx.repoDir,286 env: { PATH: process.env.PATH, HOME: join(fx.repoDir, "../../home"), NO_COLOR: "1" },287 });288 await syncAll(t);289 expect(history(t.mirror(), 1, 0)[0]?.message).toBe("add new");290291 await writeFile(join(fx.bucketDir, fx.repo, "format"), "koh-remote 2");292 293 294 await writeFile(join(fx.bucketDir, fx.repo, "head"), fx.saveIds[1] as string);295 await syncAll(t);296 const row = t.kepr.query("SELECT last_sync_error FROM repos").get() as {297 last_sync_error: string;298 };299 expect(row.last_sync_error).toContain('remote format "koh-remote 2"');300});301302test("a whole-history strip reaches every save, those arriving after it too, whatever their time (§10.2)", async () => {303 const fx = await makeKohBucket("late");304 const view = await mkdtemp(join(tmpdir(), "kepr-view-"));305 const viewRepo = join(view, fx.repo);306 await cp(join(fx.bucketDir, fx.repo), viewRepo, { recursive: true });307 308 309 await mkdir(join(viewRepo, "events"), { recursive: true });310 await writeFile(311 join(viewRepo, "events", "0000000000bb"),312 JSON.stringify({313 id: "0000000000bb",314 kind: "strip",315 save_id: "",316 path: "secret.txt",317 reason: "a secret got saved",318 created_at: 1,319 machine: "elsewhere",320 }),321 );322 const oldest = fx.saveIds.at(-1) as string;323 const newest = fx.saveIds[0] as string;324 325 await writeFile(join(viewRepo, "head"), oldest);326 const t = await syncTarget({ ...fx, bucketDir: view });327 await syncAll(t);328 expect(fileAt(t.mirror(), oldest, "secret.txt")).toBeNull();329 330 await writeFile(join(viewRepo, "head"), newest);331 await syncAll(t);332 expect(headId(t.mirror())).toBe(newest);333 for (const id of fx.saveIds) expect(fileAt(t.mirror(), id, "secret.txt")).toBeNull();334 expect(fileAt(t.mirror(), newest, "src/main.ts")).not.toBeNull();335});336337describe("the mirror's schema version", () => {338 test("a version 4 mirror reopens and any other version is refused as disposable", async () => {339 const dir = await mkdtemp(join(tmpdir(), "kepr-mirror-"));340 const created = openMirror(dir, "one");341 created.run("PRAGMA wal_checkpoint(TRUNCATE)");342 await Bun.write(join(dir, "copy.db"), Bun.file(join(dir, "one.db")));343 expect(openMirror(dir, "copy").query("PRAGMA user_version").get()).toEqual({344 user_version: 4,345 });346347 for (const version of [1, 5]) {348 const other = new Database(join(dir, `v${version}.db`));349 other.run(`PRAGMA user_version = ${version}`);350 other.close();351 expect(() => openMirror(dir, `v${version}`)).toThrow("disposable");352 }353 });354355 test("a version 2 mirror moves to 4 in place, emptied only when it deleted hidden rows", async () => {356 const dir = await mkdtemp(join(tmpdir(), "kepr-mirror-"));357 for (const [name, hidden] of [358 ["plain", ""],359 ["hiding", "secret.txt"],360 ] as const) {361 const db = openMirror(dir, name);362 for (const table of ["hidden_files", "touches", "facts", "known_objects"]) {363 db.run(`DROP TABLE ${table}`);364 }365 db.run("PRAGMA user_version = 2");366 db.query("INSERT INTO state (key, value) VALUES ('head', 'abcdef123456'), ('hidden', ?)").run(367 hidden,368 );369 closeMirror(dir, name);370 }371 const head = (name: string) => mirrorState(openMirror(dir, name), "head");372 expect(head("plain")).toBe("abcdef123456");373 expect(head("hiding")).toBeNull();374 for (const name of ["plain", "hiding"]) {375 const db = openMirror(dir, name);376 expect(db.query("PRAGMA user_version").get()).toEqual({ user_version: 4 });377 expect(db.query("SELECT COUNT(*) AS n FROM hidden_files").get()).toEqual({ n: 0 });378 }379 });380381 test("touches recorded save by save match touches worked out all at once", async () => {382 const fx = await makeKohBucket("stepwise");383 const t = await syncTarget(fx);384 await syncAll(t);385 await writeFile(join(fx.repoDir, "src/main.ts"), "// Entry point.\nconsole.log('again');\n");386 await writeFile(join(fx.repoDir, "added.txt"), "new\n");387 Bun.spawnSync(["koh", "save", "change main, add a file"], {388 cwd: fx.repoDir,389 env: { PATH: process.env.PATH, HOME: join(fx.repoDir, "../../home"), NO_COLOR: "1" },390 });391 Bun.spawnSync(["koh", "offer"], {392 cwd: fx.repoDir,393 env: { PATH: process.env.PATH, HOME: join(fx.repoDir, "../../home"), NO_COLOR: "1" },394 });395 await syncAll(t);396 const touches = () => t.mirror().query("SELECT path, n FROM touches ORDER BY n, path").all();397 const stepwise = touches();398 expect(stepwise).toContainEqual(expect.objectContaining({ path: "added.txt" }));399 400 for (const table of ["touches", "facts", "known_objects"]) {401 t.mirror().run(`DROP TABLE ${table}`);402 }403 t.mirror().run("PRAGMA user_version = 3");404 closeMirror(t.mirrorDir, fx.repo);405 expect(touches()).toEqual(stepwise);406 });407408 test("a recount cut short is done when the mirror next opens", async () => {409 const fx = await makeKohBucket("recount");410 const t = await syncTarget(fx);411 await syncAll(t);412 const known = () => t.mirror().query("SELECT COUNT(*) AS n FROM known_objects").get();413 const counted = known();414 415 t.mirror().run("DELETE FROM known_objects");416 t.mirror().run("DELETE FROM state WHERE key = 'stats_rule'");417 closeMirror(t.mirrorDir, fx.repo);418 expect(known()).toEqual(counted);419 });420421 test("a version 3 mirror gains the touches and facts a sync would have recorded", async () => {422 const fx = await makeKohBucket("derived");423 const t = await syncTarget(fx);424 await syncAll(t);425 const derived = () => [426 t.mirror().query("SELECT path, n FROM touches ORDER BY n, path").all(),427 t.mirror().query("SELECT * FROM facts ORDER BY path").all(),428 ];429 const recorded = derived();430 expect((recorded[0] as unknown[]).length).toBeGreaterThan(0);431 for (const table of ["touches", "facts", "known_objects"]) {432 t.mirror().run(`DROP TABLE ${table}`);433 }434 t.mirror().run("PRAGMA user_version = 3");435 closeMirror(t.mirrorDir, fx.repo);436 expect(derived()).toEqual(recorded);437 });438});439440test("a strip that arrives older than the saves already mirrored still strips them (§10.2, R6)", async () => {441 const fx = await makeKohBucket("older-strip");442 const t = await syncTarget(fx);443 await syncAll(t);444 445 for (const id of fx.saveIds) expect(fileAt(t.mirror(), id, "secret.txt")).not.toBeNull();446447 448 449 450 const events = join(fx.bucketDir, fx.repo, "events");451 await mkdir(events, { recursive: true });452 await writeFile(453 join(events, "0000000000aa"),454 JSON.stringify({455 id: "0000000000aa",456 kind: "strip",457 save_id: "",458 path: "secret.txt",459 reason: "a secret got saved",460 created_at: 1,461 machine: "elsewhere",462 }),463 );464 await syncAll(t);465466 for (const id of fx.saveIds) expect(fileAt(t.mirror(), id, "secret.txt")).toBeNull();467 expect(fileAt(t.mirror(), fx.saveIds[0] as string, "src/main.ts")).not.toBeNull();468});469470test("a save with an unsafe path lands without it, keeps syncing, and the admin status names it (A3)", async () => {471 const fx = await makeKohBucket("quarantine");472 const head = fx.saveIds[0] as string;473 const key = join(fx.bucketDir, fx.repo, "saves", head);474 const record = JSON.parse(await readFile(key, "utf8"));475 record.files.push({ ...record.files[0], path: "Icon\r" });476 await writeFile(key, JSON.stringify(record));477 const inst = await instance(fx.bucketDir);478 const mirror = openMirror(join(inst.dataDir, "mirror"), fx.repo);479 expect(inst.kepr.query("SELECT last_sync_error FROM repos").get()).toEqual({480 last_sync_error: null,481 });482 expect(filesAt(mirror, head).map((file) => file.path)).toContain("README.md");483 expect(filesAt(mirror, head).map((file) => file.path)).not.toContain("Icon\r");484485 await writeFile(join(fx.repoDir, "later.txt"), "later\n");486 const env = { PATH: process.env.PATH, HOME: join(fx.repoDir, "../../home"), NO_COLOR: "1" };487 Bun.spawnSync(["koh", "save", "a later save"], { cwd: fx.repoDir, env });488 Bun.spawnSync(["koh", "offer"], { cwd: fx.repoDir, env });489 await syncAll({490 bucket: openBucket({ kind: "folder", path: fx.bucketDir }),491 kepr: inst.kepr,492 mirrorDir: join(inst.dataDir, "mirror"),493 });494 expect(history(mirror, 1, 0)[0]?.message).toBe("a later save");495496 const browser = new Browser(inst.app);497 await browser.signIn();498 const page = await (await browser.get("/admin/repos")).text();499 expect(page).toContain("1 path quarantined: Icon\\x0d");500});501502test("a strip event with an illegal path is ignored, as Koh ignores it (§5.5)", async () => {503 const fx = await makeKohBucket("illegal-strip");504 for (const [id, path] of [505 ["aaaaaaaaaaaa", "src//"],506 ["bbbbbbbbbbbb", ""],507 ["cccccccccccc", "src\ud800"],508 ]) {509 const event = { id, kind: "strip", save_id: "", path, reason: "", created_at: 1, machine: "x" };510 await writeFile(join(fx.bucketDir, fx.repo, "events", id as string), JSON.stringify(event));511 }512 const t = await syncTarget(fx);513 await syncAll(t);514 expect(t.kepr.query("SELECT last_sync_error FROM repos").get()).toEqual({515 last_sync_error: null,516 });517 expect(filesAt(t.mirror(), fx.saveIds[0] as string).map((file) => file.path)).toContain(518 "src/main.ts",519 );520});521522test("an object that inflates past 512 MiB is quarantined without stopping the sync (A3)", async () => {523 const fx = await makeKohBucket("oversized");524 const head = fx.saveIds[0] as string;525 const key = join(fx.bucketDir, fx.repo, "saves", head);526 const record = JSON.parse(await readFile(key, "utf8"));527 const hash = "ab".repeat(32);528 record.files.push({ path: "huge.bin", hash, executable: false });529 await writeFile(key, JSON.stringify(record));530 await writeFile(531 join(fx.bucketDir, fx.repo, "objects", hash),532 deflateSync(new Uint8Array(512 * 1024 * 1024 + 1)),533 );534 const t = await syncTarget(fx);535 await syncAll(t);536 expect(t.kepr.query("SELECT last_sync_error FROM repos").get()).toEqual({537 last_sync_error: null,538 });539 expect(filesAt(t.mirror(), head).map((file) => file.path)).not.toContain("huge.bin");540 expect(JSON.parse(mirrorState(t.mirror(), "quarantined") ?? "[]")).toEqual(["huge.bin"]);541});542543test("the line count and the Atlas's facts skip a file over 8 MiB (A3)", async () => {544 const fx = await makeKohBucket("large-text");545 const t = await syncTarget(fx);546 await syncAll(t);547 const before = repoStats(t.mirror()).lines;548 await writeFile(join(fx.repoDir, "big.txt"), "x\n".repeat(4.5 * 1024 * 1024));549 const env = { PATH: process.env.PATH, HOME: join(fx.repoDir, "../../home"), NO_COLOR: "1" };550 Bun.spawnSync(["koh", "save", "add a big text file"], { cwd: fx.repoDir, env });551 Bun.spawnSync(["koh", "offer"], { cwd: fx.repoDir, env });552 await syncAll(t);553 expect(history(t.mirror(), 1, 0)[0]?.message).toBe("add a big text file");554 expect(repoStats(t.mirror()).lines).toBe(before);555 expect(556 t.mirror().query("SELECT lines, description FROM facts WHERE path = 'big.txt'").get(),557 ).toEqual({ lines: null, description: null });558});