-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautopilot-dashboard.test.ts
More file actions
84 lines (73 loc) · 3.38 KB
/
Copy pathautopilot-dashboard.test.ts
File metadata and controls
84 lines (73 loc) · 3.38 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
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { CommandCenterDashboard } from "../src/core/dashboard.js";
import { AutoPilotStatus } from "../src/core/autopilot-status.js";
import { EventStore } from "../src/history/event-store.js";
describe("/api/autopilot dashboard route (AUTO-05, AUTO-06)", () => {
const testDir = path.join(os.tmpdir(), `refiner-autopilot-${Date.now()}`);
beforeEach(() => {
fs.mkdirSync(testDir, { recursive: true });
process.env.PROMPT_REFINER_GLOBAL_DIR = path.join(testDir, "global");
(EventStore as any).instance = null;
AutoPilotStatus.reset();
});
afterEach(() => {
const instance = (EventStore as any).instance as EventStore | null;
instance?.close();
(EventStore as any).instance = null;
delete process.env.PROMPT_REFINER_GLOBAL_DIR;
fs.rmSync(testDir, { recursive: true, force: true });
AutoPilotStatus.reset();
});
it("returns idle state when no cycle has run (AUTO-05)", async () => {
const app = CommandCenterDashboard.createApp(testDir);
const res = await app.request("/api/autopilot");
expect(res.status).toBe(200);
const body = await res.json() as { state: string };
expect(body.state).toBe("idle");
});
it("reflects busy state set by BackgroundAutonomyService (AUTO-05)", async () => {
AutoPilotStatus.setBusy();
const app = CommandCenterDashboard.createApp(testDir);
const res = await app.request("/api/autopilot");
const body = await res.json() as { state: string };
expect(body.state).toBe("busy");
});
it("includes activity feed in response (AUTO-06)", async () => {
AutoPilotStatus.record("Ingested 2 commits", "git_commit");
AutoPilotStatus.record("Cycle complete", "cycle_complete");
const app = CommandCenterDashboard.createApp(testDir);
const res = await app.request("/api/autopilot");
const body = await res.json() as { activity: Array<{ message: string }> };
expect(body.activity[0].message).toBe("Cycle complete");
expect(body.activity[1].message).toBe("Ingested 2 commits");
});
it("includes stats counters in response", async () => {
AutoPilotStatus.addCommits(5);
AutoPilotStatus.incrementCycles();
const app = CommandCenterDashboard.createApp(testDir);
const res = await app.request("/api/autopilot");
const body = await res.json() as { stats: { commitsIngested: number; cyclesCompleted: number } };
expect(body.stats.commitsIngested).toBe(5);
expect(body.stats.cyclesCompleted).toBe(1);
});
it("includes lastCycleAt when a cycle has completed (AUTO-05)", async () => {
AutoPilotStatus.setActive();
const app = CommandCenterDashboard.createApp(testDir);
const res = await app.request("/api/autopilot");
const body = await res.json() as { lastCycleAt: string | null };
expect(body.lastCycleAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
});
it("returns a sanitized autopilot route failure", async () => {
vi.spyOn(AutoPilotStatus, "getSnapshot").mockImplementationOnce(() => {
throw new Error("autopilot secret");
});
const app = CommandCenterDashboard.createApp(testDir);
const res = await app.request("/api/autopilot");
const body = await res.json() as { error: string };
expect(res.status).toBe(500);
expect(body.error).toBe("Auto-pilot status unavailable");
});
});