Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
test(subagent): add coalescing announcement tests
yushen7f9a0181c84d
diff --git a/src/agent/subagent/announce.test.ts b/src/agent/subagent/announce.test.tsindex faf6ca352a..28fafee165 100644--- a/src/agent/subagent/announce.test.ts+++ b/src/agent/subagent/announce.test.ts@@ -1,6 +1,7 @@import { describe, it, expect } from "vitest";-import { buildSubagentSystemPrompt, formatAnnouncementMessage } from "./announce.js";+import { buildSubagentSystemPrompt, formatAnnouncementMessage, formatCoalescedAnnouncementMessage } from "./announce.js";import type { FormatAnnouncementParams } from "./announce.js";+import type { SubagentRunRecord } from "./types.js";describe("buildSubagentSystemPrompt", () => {it("includes task and session context", () => {@@ -126,3 +127,112 @@ describe("formatAnnouncementMessage", () => {expect(msg).toContain("NO_REPLY");});});++describe("formatCoalescedAnnouncementMessage", () => {+ function makeRecord(overrides: Partial<SubagentRunRecord> = {}): SubagentRunRecord {+ return {+ runId: "run-1",+ childSessionId: "child-1",+ requesterSessionId: "parent-1",+ task: "Default task",+ cleanup: "delete",+ createdAt: 1000000,+ startedAt: 1000000,+ endedAt: 1030000,+ outcome: { status: "ok" },+ findings: "Some findings",+ findingsCaptured: true,+ announced: false,+ ...overrides,+ };+ }++ it("delegates to formatAnnouncementMessage for a single record", () => {+ const record = makeRecord({ label: "Code Analysis" });+ const coalesced = formatCoalescedAnnouncementMessage([record]);+ const direct = formatAnnouncementMessage({+ runId: record.runId,+ childSessionId: record.childSessionId,+ requesterSessionId: record.requesterSessionId,+ task: record.task,+ label: record.label,+ cleanup: record.cleanup,+ outcome: record.outcome,+ startedAt: record.startedAt,+ endedAt: record.endedAt,+ findings: record.findings,+ });++ expect(coalesced).toBe(direct);+ });++ it("formats multiple records with all task findings and stats", () => {+ const records = [+ makeRecord({+ runId: "run-1",+ childSessionId: "child-1",+ label: "Task A",+ findings: "Found issue A",+ startedAt: 1000000,+ endedAt: 1030000,+ }),+ makeRecord({+ runId: "run-2",+ childSessionId: "child-2",+ label: "Task B",+ findings: "Found issue B",+ startedAt: 1000000,+ endedAt: 1045000, // 45 seconds+ }),+ ];++ const msg = formatCoalescedAnnouncementMessage(records);++ expect(msg).toContain("All 2 background tasks have completed");+ expect(msg).toContain('Task 1: "Task A"');+ expect(msg).toContain("Found issue A");+ expect(msg).toContain('Task 2: "Task B"');+ expect(msg).toContain("Found issue B");+ expect(msg).toContain("Total wall time: 45s");+ expect(msg).toContain("2 succeeded, 0 failed");+ });++ it("reports mixed outcomes correctly", () => {+ const records = [+ makeRecord({ runId: "run-1", label: "OK Task", outcome: { status: "ok" } }),+ makeRecord({ runId: "run-2", label: "Failed Task", outcome: { status: "error", error: "crash" } }),+ makeRecord({ runId: "run-3", label: "Timeout Task", outcome: { status: "timeout" } }),+ ];++ const msg = formatCoalescedAnnouncementMessage(records);++ expect(msg).toContain("completed successfully");+ expect(msg).toContain("failed: crash");+ expect(msg).toContain("timed out");+ expect(msg).toContain("1 succeeded, 2 failed");+ });++ it("shows (no output) for missing findings", () => {+ const records = [+ makeRecord({ runId: "run-1", findings: undefined }),+ makeRecord({ runId: "run-2", findings: "Has output" }),+ ];++ const msg = formatCoalescedAnnouncementMessage(records);++ expect(msg).toContain("(no output)");+ expect(msg).toContain("Has output");+ });++ it("includes combined summary instruction for multi-record", () => {+ const records = [+ makeRecord({ runId: "run-1" }),+ makeRecord({ runId: "run-2" }),+ ];++ const msg = formatCoalescedAnnouncementMessage(records);++ expect(msg).toContain("combined findings");+ expect(msg).toContain("NO_REPLY");+ });+});diff --git a/src/agent/subagent/registry-store.test.ts b/src/agent/subagent/registry-store.test.tsindex 7247203c87..bd7a5814e4 100644--- a/src/agent/subagent/registry-store.test.ts+++ b/src/agent/subagent/registry-store.test.ts@@ -78,4 +78,50 @@ describe("registry-store serialization", () => {expect(parsed.outcome?.status).toBe("error");expect(parsed.outcome?.error).toBe("Something went wrong");});++ it("round-trips coalescing fields (findings, findingsCaptured, announced)", () => {+ const record: SubagentRunRecord = {+ runId: "run-coalesce",+ childSessionId: "child-1",+ requesterSessionId: "parent-1",+ task: "Coalesce test",+ cleanup: "delete",+ createdAt: Date.now(),+ endedAt: Date.now() + 5000,+ outcome: { status: "ok" },+ findings: "Found 3 issues in auth module.",+ findingsCaptured: true,+ announced: true,+ };++ const json = JSON.stringify({ version: 1, runs: { "run-coalesce": record } });+ const parsed = JSON.parse(json);+ const restored = parsed.runs["run-coalesce"] as SubagentRunRecord;++ expect(restored.findings).toBe("Found 3 issues in auth module.");+ expect(restored.findingsCaptured).toBe(true);+ expect(restored.announced).toBe(true);+ });++ it("round-trips record with undefined coalescing fields", () => {+ const record: SubagentRunRecord = {+ runId: "run-old",+ childSessionId: "child-1",+ requesterSessionId: "parent-1",+ task: "Old record",+ cleanup: "delete",+ createdAt: Date.now(),+ cleanupHandled: true,+ // No findings, findingsCaptured, or announced fields (old format)+ };++ const json = JSON.stringify({ version: 1, runs: { "run-old": record } });+ const parsed = JSON.parse(json);+ const restored = parsed.runs["run-old"] as SubagentRunRecord;++ expect(restored.findings).toBeUndefined();+ expect(restored.findingsCaptured).toBeUndefined();+ expect(restored.announced).toBeUndefined();+ expect(restored.cleanupHandled).toBe(true);+ });});diff --git a/src/agent/subagent/registry.test.ts b/src/agent/subagent/registry.test.tsindex dda7891751..9d0fe93104 100644--- a/src/agent/subagent/registry.test.ts+++ b/src/agent/subagent/registry.test.ts@@ -159,3 +159,88 @@ describe("subagent registry", () => {expect(getSubagentRun("run-1")).toBeUndefined();});});++describe("subagent registry — coalescing", () => {+ // Without Hub, watchChildAgent ends runs immediately with "Hub not initialized".+ // This allows us to test the coalescing state transitions.++ it("captures findings when a run completes (no Hub)", () => {+ registerSubagentRun({+ runId: "run-1",+ childSessionId: "child-1",+ requesterSessionId: "parent-1",+ task: "Task 1",+ });++ const record = getSubagentRun("run-1");+ // Run ended immediately due to no Hub+ expect(record?.endedAt).toBeGreaterThan(0);+ expect(record?.findingsCaptured).toBe(true);+ });++ it("does not announce while sibling runs are still pending", () => {+ // Register first run — ends immediately (no Hub)+ registerSubagentRun({+ runId: "run-1",+ childSessionId: "child-1",+ requesterSessionId: "parent-1",+ task: "Task 1",+ });++ const record1 = getSubagentRun("run-1");+ expect(record1?.findingsCaptured).toBe(true);++ // Register second run — also ends immediately+ registerSubagentRun({+ runId: "run-2",+ childSessionId: "child-2",+ requesterSessionId: "parent-1",+ task: "Task 2",+ });++ const record2 = getSubagentRun("run-2");+ expect(record2?.findingsCaptured).toBe(true);++ // Both ended, but announce fails because no Hub for parent agent.+ // The key check: both records should have findings captured.+ // announced will be false because runCoalescedAnnounceFlow fails (no Hub).+ expect(record1?.announced).toBeUndefined();+ expect(record2?.announced).toBeUndefined();+ });++ it("single run captures findings immediately", () => {+ registerSubagentRun({+ runId: "run-solo",+ childSessionId: "child-solo",+ requesterSessionId: "parent-solo",+ task: "Solo task",+ });++ const record = getSubagentRun("run-solo");+ expect(record?.endedAt).toBeGreaterThan(0);+ expect(record?.findingsCaptured).toBe(true);+ expect(record?.outcome?.status).toBe("error");+ expect(record?.outcome?.error).toContain("Hub not initialized");+ });++ it("shutdownSubagentRegistry captures findings for ended-but-uncaptured runs", () => {+ registerSubagentRun({+ runId: "run-1",+ childSessionId: "child-1",+ requesterSessionId: "parent-1",+ task: "Task",+ });++ const record = getSubagentRun("run-1");+ if (record) {+ // Simulate: run ended but findings not yet captured+ record.endedAt = Date.now();+ record.outcome = { status: "ok" };+ record.findingsCaptured = undefined;+ }++ shutdownSubagentRegistry();++ expect(record?.findingsCaptured).toBe(true);+ });+});