import { describe, expect, it } from "vitest"; import { parseZCodeBackgroundTaskNotificationText, zcodeBackgroundTaskNotificationToolUpdateStatus, } from "../src/background-task-notifications.js"; describe("background task notifications", () => { it("preserves stopped task-notification status and normalizes killed to stopped", () => { expect(zcodeBackgroundTaskNotificationToolUpdateStatus("stopped")).toBe("stopped"); expect(zcodeBackgroundTaskNotificationToolUpdateStatus("killed")).toBe("stopped"); }); it("normalizes terminal task-notification status", () => { expect(zcodeBackgroundTaskNotificationToolUpdateStatus("completed")).toBe("completed"); expect(zcodeBackgroundTaskNotificationToolUpdateStatus("failed")).toBe("failed"); expect(zcodeBackgroundTaskNotificationToolUpdateStatus("lost")).toBe("failed"); expect(zcodeBackgroundTaskNotificationToolUpdateStatus("unexpected")).toBe("completed"); expect(zcodeBackgroundTaskNotificationToolUpdateStatus(undefined)).toBe("completed"); }); it("parses failed notification error and decodes XML entities exactly once", () => { const providerMessage = "429 & retry; literal & marker"; const summary = `Agent general-purpose task "Review" failed. ${providerMessage}`; const parsed = parseZCodeBackgroundTaskNotificationText( [ "", "agent_429", "toolu_429", "failed", "Agent general-purpose task "Review" failed. 429 & retry; literal & marker", "429 & retry; literal & marker", "", ].join("\n"), ); expect(parsed).toMatchObject({ toolUseId: "toolu_429", notification: { taskId: "agent_429", status: "failed", summary, error: providerMessage, }, }); expect(parsed?.notification.error).toBe(providerMessage); }); });