repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by bugabinga
extensions/overkill/__tests__/harness.test.ts
RawFile outline
- session line 9
- afterEach line 11
- extensionPath line 16
- command line 20
- overkill Phase 3 harness line 31
- loads through the real Pi extension runtime line 32
- renders compact and expanded run entries without trusting entry-supplied artifact paths line 41
- keeps a provider-free resume boundary when no branch run exists line 75
- renders provider-free checkpoint progress and staged results from real branch entries line 84
import { fileURLToPath } from "node:url";
import { initTheme } from "@earendil-works/pi-coding-agent";
import {
createTestSession,
type TestSession,
} from "@marcfargas/pi-test-harness";
import { afterEach, describe, expect, it } from "vitest";
let session: TestSession | undefined;
afterEach(() => {
session?.dispose();
session = undefined;
});
function extensionPath(): string {
return fileURLToPath(new URL("../index.ts", import.meta.url));
}
async function command(args: string): Promise<void> {
if (!session) throw new Error("missing harness session");
const extension = session.session.extensionRunner.extensions[0];
const overkillCommand = extension?.commands.get("overkill");
if (!overkillCommand) throw new Error("overkill command unavailable");
await overkillCommand.handler(
args,
session.session.extensionRunner.createCommandContext(),
);
}
describe("overkill Phase 3 harness", () => {
it("loads through the real Pi extension runtime", async () => {
session = await createTestSession({ extensions: [extensionPath()] });
const [extension] = session.session.extensionRunner.extensions;
expect(extension.path).toBe(extensionPath());
expect(extension.commands.has("overkill")).toBe(true);
expect(extension.tools.size).toBe(0);
expect(extension.entryRenderers?.has("overkill-run")).toBe(true);
});
it("renders compact and expanded run entries without trusting entry-supplied artifact paths", async () => {
session = await createTestSession({ extensions: [extensionPath()] });
initTheme();
const [extension] = session.session.extensionRunner.extensions;
const renderer = extension.entryRenderers?.get("overkill-run");
if (!renderer) throw new Error("overkill renderer unavailable");
const entry = {
id: "run",
type: "custom",
customType: "overkill-run",
data: {
version: 1,
runId: "123e4567-e89b-12d3-a456-426614174000",
kind: "suite",
stage: "training",
terminal: null,
sourcePath: "/forged/source.md",
reportPath: "/forged/report.json",
stagedPath: "/forged/staged.md",
},
};
const theme = { fg: (_color: string, text: string) => text };
const compact = renderer(entry, { expanded: false }, theme)
?.render(120)
.join("\n");
expect(compact).toContain("Overkill training");
expect(compact).toContain("to expand");
const expanded = renderer(entry, { expanded: true }, theme)
?.render(120)
.join("\n");
expect(expanded).toContain("Review artifacts unavailable.");
expect(expanded).not.toContain("/forged/staged.md");
});
it("keeps a provider-free resume boundary when no branch run exists", async () => {
session = await createTestSession({ extensions: [extensionPath()] });
await command("resume");
expect(session.events.uiCallsFor("notify").at(-1)?.args).toEqual([
"No Overkill suite run is linked to this branch.",
"info",
]);
});
it("renders provider-free checkpoint progress and staged results from real branch entries", async () => {
session = await createTestSession({ extensions: [extensionPath()] });
(session.session.sessionManager as any).appendCustomEntry("overkill-run", {
version: 1,
runId: "123e4567-e89b-12d3-a456-426614174000",
kind: "suite",
stage: "training",
terminal: null,
completed: 1,
total: 2,
currentScore: 0.5,
bestScore: 0.75,
reportPath: null,
stagedPath: null,
});
await command("status");
expect(session.events.uiCallsFor("notify")).toEqual([]);
await command("cancel");
expect(session.events.uiCallsFor("notify").at(-1)?.args).toEqual([
"No Overkill rollout is active.",
"info",
]);
});
});