Skip to content
refs
History
62 lines · 4.2 KBRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { framesFor, type DeliverableRow } from "../deliveries.ts";
4
5const me = { session: "s1", branchRef: "refs/heads/tasks/52", baseRef: "refs/heads/main" };
6const idle = { session: "s1", branchRef: null, baseRef: "refs/heads/main" };
7const 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
15test("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" }, base: false }]);
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/other"), me), []);
21});
22
23test("tells a working session when the default branch moves, so it rebases onto merged work", () => {
24 assert.deepEqual(framesFor(push("s2", "refs/heads/main"), me), [{ type: "event", id: "10", event: "repo.pushed", ref: "refs/heads/main", from: "a", to: "b", by: { session: "s2", actor: "codex" }, base: true }]);
25 assert.equal(framesFor(push(null, "refs/heads/main"), me).length, 1);
26 assert.deepEqual(framesFor(push("s1", "refs/heads/main"), me), []);
27 assert.deepEqual(framesFor(push("s2", "refs/heads/main"), idle), []);
28});
29
30test("an idle session receives no pushes", () => {
31 assert.deepEqual(framesFor(push("s2"), idle), []);
32});
33
34test("delivers problems only to the session that pushed the commit", () => {
35 const problem: DeliverableRow = { id: 11, kind: "session.problem", data: JSON.stringify({ commit: "c3", message: "reason is required." }), session_id: "s1", actor: "claude-code" };
36 assert.deepEqual(framesFor(problem, me), [{ type: "problem", id: "11", commit: "c3", message: "reason is required." }]);
37 assert.deepEqual(framesFor({ ...problem, session_id: "s2" }, me), []);
38});
39
40test("delivers instructions and stop only to the session they address, idle or not", () => {
41 const instructed: DeliverableRow = { id: 12, kind: "session.instructed", data: JSON.stringify({ session: "s1", body: "Use KV" }), session_id: null, actor: "Aman" };
42 assert.deepEqual(framesFor(instructed, idle), [{ type: "instruction", id: "12", body: "Use KV", by: { person: "Aman" } }]);
43 assert.deepEqual(framesFor(instructed, { ...me, session: "s2" }), []);
44
45 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" };
46 assert.deepEqual(framesFor(ended, idle), [{ type: "stop", id: "13", reason: "Stopped by a human." }]);
47 assert.deepEqual(framesFor(ended, { ...me, session: "s2" }), []);
48});
49
50test("delivers mentions to the session they name", () => {
51 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" };
52 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" } }]);
53 assert.deepEqual(framesFor(mentioned, { ...me, session: "s2" }), []);
54});
55
56test("tells the parent session when its sub-agent finishes", () => {
57 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" };
58 assert.deepEqual(framesFor(finished, idle), [{ type: "run", id: "15", mention: "14", ok: true, summary: "Answered." }]);
59 assert.deepEqual(framesFor(finished, { ...me, session: "s2" }), []);
60 const own: DeliverableRow = { ...finished, data: JSON.stringify({ session: "s1", run: "s1", mention: "14", ok: true, summary: "Answered." }), session_id: "s1" };
61 assert.deepEqual(framesFor(own, idle), []);
62});