fabro/apps/fabro-web/app/routes/run-files/cache-keys.test.ts
Bryan Helmkamp 603a64810c
Some checks are pending
Rust / Format (push) Waiting to run
Rust / Clippy (push) Waiting to run
Rust / Generated Docs (push) Waiting to run
Rust / Test (Linux) (push) Waiting to run
Rust / Test (macOS) (push) Waiting to run
TypeScript / Typecheck (push) Waiting to run
TypeScript / Test (push) Waiting to run
TypeScript / Build (push) Waiting to run
fix(web): virtualize run file diffs consistently
Always route non-empty Files Changed views through Pierre's Virtualizer and worker pool, with full-height layout propagation and stable per-file cache keys. Copy Pierre worker assets during the web build so the static worker URL resolves in production.
2026-05-05 16:41:39 -04:00

64 lines
1.7 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { fileCacheKey } from "./cache-keys";
describe("fileCacheKey", () => {
test("identical inputs produce the same key", () => {
const first = fileCacheKey({
runId: "run_1",
toSha: "abc1234",
side: "old",
path: "src/app.ts",
contents: "export const value = 1;\n",
});
const second = fileCacheKey({
runId: "run_1",
toSha: "abc1234",
side: "old",
path: "src/app.ts",
contents: "export const value = 1;\n",
});
expect(second).toBe(first);
});
test("changing file contents changes the key", () => {
const base = {
runId: "run_1",
toSha: "abc1234",
side: "new" as const,
path: "src/app.ts",
};
expect(fileCacheKey({ ...base, contents: "one" })).not.toBe(
fileCacheKey({ ...base, contents: "two" }),
);
});
test("changing file name or side changes the key", () => {
const base = {
runId: "run_1",
toSha: "abc1234",
contents: "same",
};
expect(fileCacheKey({ ...base, side: "old", path: "src/a.ts" })).not.toBe(
fileCacheKey({ ...base, side: "old", path: "src/b.ts" }),
);
expect(fileCacheKey({ ...base, side: "old", path: "src/a.ts" })).not.toBe(
fileCacheKey({ ...base, side: "new", path: "src/a.ts" }),
);
});
test("missing toSha still produces a deterministic key", () => {
expect(
fileCacheKey({
runId: "run_1",
toSha: null,
side: "new",
path: "src/app.ts",
contents: "same",
}),
).toMatch(/^fabro-run-file:run_1:no-sha:new:src\/app\.ts:[0-9a-f]{8}$/);
});
});