repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/git-safe/__tests__/debug.test.ts
Rawimport { mkdtempSync, readdirSync, readFileSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { createTestSession, type TestSession } from "../../../test/harness";
const extensionPath = path.resolve(import.meta.dirname, "../index.ts");
let root: string | undefined;
let t: TestSession | undefined;
afterEach(() => {
t?.dispose();
if (root) rmSync(root, { recursive: true, force: true });
t = undefined;
root = undefined;
});
describe("git-safe debug harness", () => {
it("writes its lifecycle records in the isolated sandbox", async () => {
root = mkdtempSync(path.join(tmpdir(), "pi-ext-git-safe-debug-"));
t = await createTestSession({
cwd: root,
env: { PI_GIT_SAFE_DEBUG: "1" },
extensions: [extensionPath],
});
await t.session.extensionRunner.emit({
type: "session_start",
reason: "startup",
});
await t.session.extensionRunner.emitToolResult({
type: "tool_result",
toolName: "read",
toolCallId: "missing-read",
input: { path: path.join(root, "missing") },
content: [],
isError: true,
} as never);
await t.session.extensionRunner.emit({
type: "session_shutdown",
reason: "quit",
});
const directory = path.join(
root,
".test-state",
"pi-ext",
"debug",
"git-safe",
);
const records = readdirSync(directory).flatMap((file) =>
readFileSync(path.join(directory, file), "utf8")
.trim()
.split("\n")
.filter(Boolean)
.map(
(line) => JSON.parse(line) as { event: string; extension: string },
),
);
expect(records).toContainEqual(
expect.objectContaining({
event: "session.start",
extension: "git-safe",
}),
);
expect(records).toContainEqual(
expect.objectContaining({
event: "session.shutdown",
extension: "git-safe",
}),
);
expect(records).toContainEqual(
expect.objectContaining({
event: "read.spotlight.error",
type: "readpath",
}),
);
});
});