import { SessionManager } from "@earendil-works/pi-coding-agent"; import { afterEach, expect, it, vi } from "vitest"; import overkill, { harvestAftermath } from "../index.ts"; afterEach(() => vi.restoreAllMocks()); type Command = { getArgumentCompletions?: (prefix: string) => unknown; }; it("fails closed when persisted session listing fails", async () => { await expect( harvestAftermath({ ctx: { cwd: "/work", sessionManager: { getSessionId: () => "current", getBranch: () => [], }, } as never, knownSkillPaths: new Map(), sessionApi: { listAll: async () => { throw new Error("unavailable"); }, open: () => { throw new Error("unreachable"); }, }, }), ).rejects.toThrow("unavailable"); }); it("rejects an invalid explicit Aftermath path before harvesting session data", async () => { let command: | { handler: (args: string, ctx: any) => Promise } | undefined; const listAll = vi.spyOn(SessionManager, "listAll").mockResolvedValue([]); overkill({ on() {}, registerCommand( _name: string, value: { handler: (args: string, ctx: any) => Promise }, ) { command = value; }, registerEntryRenderer() {}, getCommands() { return [ { name: "skill:missing", source: "skill", sourceInfo: { path: "/missing/SKILL.md" }, }, ]; }, } as never); const notices: string[] = []; await command?.handler("aftermath /missing/SKILL.md", { cwd: "/", mode: "json", modelRegistry: { getAvailable: async () => [] }, isProjectTrusted: () => true, sessionManager: { getSessionId: () => "current", getBranch: () => [] }, ui: { notify: (message: string) => notices.push(message) }, }); expect(listAll).not.toHaveBeenCalled(); expect(notices).toEqual([ "Overkill Aftermath failed: explicit Aftermath skill path is not a loaded skill", ]); }); it("completes nested Aftermath commands", () => { let command: Command | undefined; overkill({ on() {}, registerCommand(_name: string, value: Command) { command = value; }, registerEntryRenderer() {}, } as never); expect(command?.getArgumentCompletions?.("aftermath re")).toEqual([ { value: "aftermath resume", label: "aftermath resume" }, { value: "aftermath review", label: "aftermath review" }, ]); });