Add unit tests for git persistence
This commit is contained in:
parent
ae0251b6d3
commit
c0387ff0d3
1 changed files with 59 additions and 0 deletions
|
|
@ -14,6 +14,7 @@ import {
|
|||
initDb,
|
||||
respondToPrompt,
|
||||
updateLastSeen,
|
||||
updateSessionStats,
|
||||
} from "./db";
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
@ -280,3 +281,61 @@ test("getSessionOutput only returns output for specific session", () => {
|
|||
expect(output1[0]?.line).toBe("Session 1 output");
|
||||
expect(output2[0]?.line).toBe("Session 2 output");
|
||||
});
|
||||
|
||||
// Git persistence tests
|
||||
|
||||
test("updateSessionStats persists git branch and files", () => {
|
||||
const device = createDevice("secret123");
|
||||
const session = createSession(device.id);
|
||||
|
||||
updateSessionStats(session.id, {
|
||||
state: "ready",
|
||||
prompts: 0,
|
||||
completions: 0,
|
||||
tools: 0,
|
||||
compressions: 0,
|
||||
thinking_seconds: 0,
|
||||
work_seconds: 0,
|
||||
mode: "normal",
|
||||
model: null,
|
||||
idle_since: null,
|
||||
git_branch: "feature/test",
|
||||
git_files_json: JSON.stringify([
|
||||
{ path: "src/test.ts", status: "M", additions: 5, deletions: 2 },
|
||||
]),
|
||||
});
|
||||
|
||||
const updated = getSession(session.id);
|
||||
expect(updated?.git_branch).toBe("feature/test");
|
||||
|
||||
const files = JSON.parse(updated?.git_files_json || "[]");
|
||||
expect(files).toHaveLength(1);
|
||||
expect(files[0].path).toBe("src/test.ts");
|
||||
expect(files[0].status).toBe("M");
|
||||
expect(files[0].additions).toBe(5);
|
||||
expect(files[0].deletions).toBe(2);
|
||||
});
|
||||
|
||||
test("updateSessionStats handles null git data", () => {
|
||||
const device = createDevice("secret123");
|
||||
const session = createSession(device.id);
|
||||
|
||||
updateSessionStats(session.id, {
|
||||
state: "ready",
|
||||
prompts: 1,
|
||||
completions: 1,
|
||||
tools: 1,
|
||||
compressions: 0,
|
||||
thinking_seconds: 10,
|
||||
work_seconds: 30,
|
||||
mode: "normal",
|
||||
model: "claude-sonnet",
|
||||
idle_since: Date.now(),
|
||||
git_branch: null,
|
||||
git_files_json: null,
|
||||
});
|
||||
|
||||
const updated = getSession(session.id);
|
||||
expect(updated?.git_branch).toBeNull();
|
||||
expect(updated?.git_files_json).toBeNull();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue