|
| 1 | +import { describe, expect, test } from "bun:test"; |
| 2 | +import { pendingAskSnapshot, pendingAskWakeText, type FleetLane } from "./fleet-report.js"; |
| 3 | + |
| 4 | +function lane(overrides: Partial<FleetLane> & { id: string }): FleetLane { |
| 5 | + return { |
| 6 | + description: overrides.id, |
| 7 | + status: "running", |
| 8 | + startedAt: 0, |
| 9 | + lastActivityAt: 0, |
| 10 | + currentToolName: null, |
| 11 | + currentToolPreview: null, |
| 12 | + currentToolStartedAt: null, |
| 13 | + ...overrides, |
| 14 | + }; |
| 15 | +} |
| 16 | + |
| 17 | +describe("pendingAskSnapshot", () => { |
| 18 | + test("repeated calls return complete identical snapshots for distinct sessions sharing a catalog", () => { |
| 19 | + const lanes = [ |
| 20 | + lane({ id: "a1", agentId: "builder", description: "Build the thing" }), |
| 21 | + lane({ id: "a2", agentId: "builder" }), |
| 22 | + ]; |
| 23 | + const peek = () => ({ question: "Which port?", questionId: "q1" }); |
| 24 | + const expected = lanes.map((worker) => ({ |
| 25 | + sessionId: worker.id, |
| 26 | + agentId: "builder", |
| 27 | + description: worker.description, |
| 28 | + question: "Which port?", |
| 29 | + questionId: "q1", |
| 30 | + })); |
| 31 | + expect(pendingAskSnapshot(lanes, peek)).toEqual(expected); |
| 32 | + expect(pendingAskSnapshot(lanes, peek)).toEqual(expected); |
| 33 | + }); |
| 34 | + |
| 35 | + test("resolution, removal and replacement are reflected without prior watch state", () => { |
| 36 | + const lanes = [lane({ id: "a1" })]; |
| 37 | + const asks = new Map([["a1", { question: "A?", questionId: "q1" }]]); |
| 38 | + const peek = (id: string) => asks.get(id); |
| 39 | + expect(pendingAskSnapshot(lanes, peek)[0]?.questionId).toBe("q1"); |
| 40 | + expect(pendingAskSnapshot([], peek)).toEqual([]); |
| 41 | + asks.clear(); |
| 42 | + expect(pendingAskSnapshot(lanes, peek)).toEqual([]); |
| 43 | + asks.set("a1", { question: "B?", questionId: "q2" }); |
| 44 | + expect(pendingAskSnapshot(lanes, peek)[0]).toMatchObject({ |
| 45 | + sessionId: "a1", |
| 46 | + question: "B?", |
| 47 | + questionId: "q2", |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + test("only running root workers with a pending question are included", () => { |
| 52 | + const lanes = [ |
| 53 | + lane({ id: "root" }), |
| 54 | + lane({ id: "child", parentSessionId: "orchestrator" }), |
| 55 | + lane({ id: "done", status: "done" }), |
| 56 | + lane({ id: "cancelled", status: "cancelled" }), |
| 57 | + lane({ id: "no-ask" }), |
| 58 | + ]; |
| 59 | + const asks = pendingAskSnapshot(lanes, (id) => |
| 60 | + id === "no-ask" ? undefined : { question: "Q?", questionId: "q1" }, |
| 61 | + ); |
| 62 | + expect(asks.map((ask) => ask.sessionId)).toEqual(["root"]); |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
| 66 | +describe("pendingAskWakeText", () => { |
| 67 | + test("names agent, description, question and question id, and routes to send_input", () => { |
| 68 | + const text = pendingAskWakeText({ |
| 69 | + sessionId: "a1", |
| 70 | + agentId: "builder", |
| 71 | + description: "Build the thing", |
| 72 | + question: "Which port?", |
| 73 | + questionId: "q1", |
| 74 | + }); |
| 75 | + expect(text).toContain("builder"); |
| 76 | + expect(text).toContain("Build the thing"); |
| 77 | + expect(text).toContain("Which port?"); |
| 78 | + expect(text).toContain("q1"); |
| 79 | + expect(text).toContain("send_input"); |
| 80 | + expect(text).toContain("using target a1"); |
| 81 | + expect(text.toLowerCase()).toContain("worker"); |
| 82 | + }); |
| 83 | +}); |
0 commit comments