repositories / pi-ext
pi-ext
bugabingas pi extensions
owned by admin
extensions/bak/__tests__/contract.test.ts
Rawimport { fileURLToPath } from "node:url";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
createPiSession,
type PiSession,
} from "../../../test/fixture/create-pi-session.ts";
let session: PiSession | undefined;
afterEach(async () => {
await session?.dispose();
session = undefined;
vi.unstubAllEnvs();
vi.unstubAllGlobals();
});
function bakPath(): string {
return fileURLToPath(new URL("../index.ts", import.meta.url));
}
describe("bak contract", () => {
it("performs no remote work during session startup", async () => {
vi.stubEnv("PI_BAK_S3_ENDPOINT", "https://example.invalid");
vi.stubEnv("PI_BAK_S3_ACCESS_KEY_ID", "id");
vi.stubEnv("PI_BAK_S3_SECRET_ACCESS_KEY", "secret");
const fetch = vi.fn();
vi.stubGlobal("fetch", fetch);
session = await createPiSession({ extensionPaths: [bakPath()] });
await new Promise((resolve) => setTimeout(resolve, 20));
expect(fetch).not.toHaveBeenCalled();
});
it("loads through Pi and registers the bak command", async () => {
session = await createPiSession({ extensionPaths: [bakPath()] });
const extension = session.extensions[0];
const command = extension?.commands.get("bak");
expect(session.extensions).toHaveLength(1);
expect(command).toBeDefined();
expect(command?.getArgumentCompletions?.("res")).toEqual([
{ value: "restore", label: "restore" },
]);
});
});