repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/overkill/__tests__/aftermath-commands.test.ts
RawFile outline
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("uses the active configured session directory and fails closed when listing fails", async () => {
const listAll = vi.fn(async () => {
throw new Error("unavailable");
});
await expect(
harvestAftermath({
ctx: {
cwd: "/work",
sessionManager: {
getSessionDir: () => "/configured/sessions",
getSessionId: () => "current",
getBranch: () => [],
},
} as never,
knownSkillPaths: new Map(),
sessionApi: {
listAll,
open: () => {
throw new Error("unreachable");
},
},
}),
).rejects.toThrow("unavailable");
expect(listAll).toHaveBeenCalledWith("/configured/sessions");
});
it("rejects an invalid explicit Aftermath path before harvesting session data", async () => {
let command:
| { handler: (args: string, ctx: any) => Promise<void> }
| undefined;
const listAll = vi.spyOn(SessionManager, "listAll").mockResolvedValue([]);
overkill({
on() {},
registerCommand(
_name: string,
value: { handler: (args: string, ctx: any) => Promise<void> },
) {
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")).toBeNull();
expect(command?.getArgumentCompletions?.("aftermath re")).toEqual([
{ value: "aftermath resume", label: "aftermath resume" },
{ value: "aftermath review", label: "aftermath review" },
]);
});