-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.test.ts
More file actions
91 lines (81 loc) · 2.72 KB
/
Copy pathgit.test.ts
File metadata and controls
91 lines (81 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import assert from "node:assert/strict";
import { after, describe, it } from "node:test";
import {
cleanupBranches,
createWorktree,
getDiff,
getDiffStats,
getRepoRoot,
removeWorktree,
} from "./git.js";
describe("getRepoRoot", () => {
it("returns the repository root", async () => {
const root = await getRepoRoot();
assert.ok(root.length > 0);
assert.ok(root.includes("thinktank"));
});
});
describe("worktree lifecycle", () => {
let worktreePath: string;
it("creates a worktree", async () => {
worktreePath = await createWorktree(99);
assert.ok(worktreePath.length > 0);
assert.ok(worktreePath.includes("thinktank-agent-99"));
});
it("gets empty diff for unchanged worktree", async () => {
const diff = await getDiff(worktreePath);
assert.equal(diff, "");
});
it("gets empty diff stats for unchanged worktree", async () => {
const stats = await getDiffStats(worktreePath);
assert.deepEqual(stats.filesChanged, []);
assert.equal(stats.linesAdded, 0);
assert.equal(stats.linesRemoved, 0);
});
it("removes the worktree", async () => {
await removeWorktree(worktreePath);
// Should not throw
});
after(async () => {
// Clean up any leftover branches
await cleanupBranches().catch(() => {});
});
});
describe("cleanupBranches", () => {
it("runs without error even when no thinktank branches exist", async () => {
await cleanupBranches();
// Should not throw
});
});
describe("getDiff warning on failure", () => {
it("warns to stderr and returns empty string for invalid worktree path", async () => {
const warnings: string[] = [];
const originalWarn = console.warn;
console.warn = (...args: unknown[]) => warnings.push(args.join(" "));
try {
const result = await getDiff("/nonexistent/path/thinktank-test");
assert.equal(result, "");
assert.ok(warnings.length >= 1);
assert.ok(warnings[0]!.includes("getDiff"));
assert.ok(warnings[0]!.includes("thinktank-test"));
} finally {
console.warn = originalWarn;
}
});
});
describe("getDiffStats warning on failure", () => {
it("warns to stderr and returns empty stats for invalid worktree path", async () => {
const warnings: string[] = [];
const originalWarn = console.warn;
console.warn = (...args: unknown[]) => warnings.push(args.join(" "));
try {
const result = await getDiffStats("/nonexistent/path/thinktank-test");
assert.deepEqual(result, { filesChanged: [], linesAdded: 0, linesRemoved: 0 });
assert.ok(warnings.length >= 1);
assert.ok(warnings[0]!.includes("getDiffStats"));
assert.ok(warnings[0]!.includes("thinktank-test"));
} finally {
console.warn = originalWarn;
}
});
});