55 lines · 3.6 KBRaw
| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | import { framesFor, type DeliverableRow } from "../deliveries.ts"; |
| 4 | |
| 5 | const me = { session: "s1", branchRef: "refs/heads/tasks/52" }; |
| 6 | const idle = { session: "s1", branchRef: null }; |
| 7 | const push = (session: string | null, ref = "refs/heads/tasks/52"): DeliverableRow => ({ |
| 8 | id: 10, |
| 9 | kind: "repo.pushed", |
| 10 | data: JSON.stringify({ updates: [{ ref, from: "a", to: "b" }] }), |
| 11 | session_id: session, |
| 12 | actor: session ? "codex" : "Aman", |
| 13 | }); |
| 14 | |
| 15 | test("delivers pushes to the current task branch by others, never the session's own", () => { |
| 16 | assert.deepEqual(framesFor(push("s2"), me), [{ type: "event", id: "10", event: "repo.pushed", ref: "refs/heads/tasks/52", from: "a", to: "b", by: { session: "s2", actor: "codex" } }]); |
| 17 | const human = framesFor(push(null), me)[0]; |
| 18 | assert.deepEqual(human.type === "event" && human.by, { session: null, actor: "Aman" }); |
| 19 | assert.deepEqual(framesFor(push("s1"), me), []); |
| 20 | assert.deepEqual(framesFor(push("s2", "refs/heads/main"), me), []); |
| 21 | }); |
| 22 | |
| 23 | test("an idle session receives no pushes", () => { |
| 24 | assert.deepEqual(framesFor(push("s2"), idle), []); |
| 25 | }); |
| 26 | |
| 27 | test("delivers problems only to the session that pushed the commit", () => { |
| 28 | const problem: DeliverableRow = { id: 11, kind: "session.problem", data: JSON.stringify({ commit: "c3", message: "reason is required." }), session_id: "s1", actor: "claude-code" }; |
| 29 | assert.deepEqual(framesFor(problem, me), [{ type: "problem", id: "11", commit: "c3", message: "reason is required." }]); |
| 30 | assert.deepEqual(framesFor({ ...problem, session_id: "s2" }, me), []); |
| 31 | }); |
| 32 | |
| 33 | test("delivers instructions and stop only to the session they address, idle or not", () => { |
| 34 | const instructed: DeliverableRow = { id: 12, kind: "session.instructed", data: JSON.stringify({ session: "s1", body: "Use KV" }), session_id: null, actor: "Aman" }; |
| 35 | assert.deepEqual(framesFor(instructed, idle), [{ type: "instruction", id: "12", body: "Use KV", by: { person: "Aman" } }]); |
| 36 | assert.deepEqual(framesFor(instructed, { ...me, session: "s2" }), []); |
| 37 | |
| 38 | const ended: DeliverableRow = { id: 13, kind: "session.ended", data: JSON.stringify({ session: "s1", outcome: "finished", reason: "Stopped by a human." }), session_id: null, actor: "Aman" }; |
| 39 | assert.deepEqual(framesFor(ended, idle), [{ type: "stop", id: "13", reason: "Stopped by a human." }]); |
| 40 | assert.deepEqual(framesFor(ended, { ...me, session: "s2" }), []); |
| 41 | }); |
| 42 | |
| 43 | test("delivers mentions to the session they name", () => { |
| 44 | const mentioned: DeliverableRow = { id: 14, kind: "agent.mentioned", data: JSON.stringify({ session: "s1", pull: 7, title: "Fix login", comment: 99, body: "@agent/s1 look", assigned: true }), session_id: null, actor: "Aman" }; |
| 45 | assert.deepEqual(framesFor(mentioned, idle), [{ type: "mention", id: "14", pull: 7, title: "Fix login", body: "@agent/s1 look", assigned: true, run: false, by: { person: "Aman" } }]); |
| 46 | assert.deepEqual(framesFor(mentioned, { ...me, session: "s2" }), []); |
| 47 | }); |
| 48 | |
| 49 | test("tells the parent session when its sub-agent finishes", () => { |
| 50 | const finished: DeliverableRow = { id: 15, kind: "agent.run_finished", data: JSON.stringify({ session: "s1", run: "s9", mention: "14", ok: true, summary: "Answered." }), session_id: "s9", actor: "claude-code" }; |
| 51 | assert.deepEqual(framesFor(finished, idle), [{ type: "run", id: "15", mention: "14", ok: true, summary: "Answered." }]); |
| 52 | assert.deepEqual(framesFor(finished, { ...me, session: "s2" }), []); |
| 53 | const own: DeliverableRow = { ...finished, data: JSON.stringify({ session: "s1", run: "s1", mention: "14", ok: true, summary: "Answered." }), session_id: "s1" }; |
| 54 | assert.deepEqual(framesFor(own, idle), []); |
| 55 | }); |