@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 54 lines 2.28 KB
Raw
1 import { describe, expect, it } from "vite-plus/test";
2
3 import { buildFileTreePathUpdates, shouldRebuildFileTree } from "./fileTreePathReconciliation";
4
5 const folder = (name: string, count: number) =>
6 Array.from({ length: count }, (_, index) => `${name}/entry-${index}`);
7
8 const decide = (previous: readonly string[], next: readonly string[]) =>
9 shouldRebuildFileTree(previous, next, buildFileTreePathUpdates(previous, next));
10
11 describe("buildFileTreePathUpdates", () => {
12 it("removes a folder once and skips the paths inside it", () => {
13 expect(
14 buildFileTreePathUpdates(["src/", "src/a/", "src/a/b/", "src/a/c.ts"], ["src/"]),
15 ).toEqual([{ type: "remove", path: "src/a/", recursive: true }]);
16 });
17
18 it("does not treat a sibling that shares a name prefix as inside a removed folder", () => {
19 expect(buildFileTreePathUpdates(["src/a/", "src/ab/", "src/a.ts"], [])).toEqual([
20 { type: "remove", path: "src/a/", recursive: true },
21 { type: "remove", path: "src/ab/", recursive: true },
22 { type: "remove", path: "src/a.ts" },
23 ]);
24 });
25 });
26
27 describe("shouldRebuildFileTree", () => {
28 it("rebuilds when many paths land in a folder that dominates the tree", () => {
29 const existing = folder("big", 50_000);
30 expect(decide(existing, [...existing, ...addTo("big", 301)])).toBe(true);
31 });
32
33 it("counts a folder's subfolders as siblings, whose paths end in a slash", () => {
34 const existing = folder("big", 50_000).map((path) => `${path}/`);
35 const added = addTo("big", 301).map((path) => `${path}/`);
36 expect(decide(existing, [...existing, ...added])).toBe(true);
37 expect(decide(existing, existing.slice(301))).toBe(true);
38 });
39
40 it("batches a few hundred paths into a small folder beside a large unrelated one", () => {
41 const existing = folder("big", 50_000);
42 expect(decide(existing, [...existing, ...folder("small", 301)])).toBe(false);
43 });
44
45 it("batches many operations spread thinly across many small folders", () => {
46 const existing = folder("big", 50_000);
47 const added = Array.from({ length: 1_000 }, (_, index) => `small-${index}/file.ts`);
48 expect(decide(existing, [...existing, ...added])).toBe(false);
49 });
50 });
51
52 function addTo(name: string, count: number) {
53 return Array.from({ length: count }, (_, index) => `${name}/added-${index}`);
54 }