import path from "node:path"; import { afterEach, describe, expect, it, vi } from "vitest"; import { createTestSession, type TestSession } from "../../../test/harness.js"; describe("bak pi-test-harness", () => { let session: TestSession | undefined; afterEach(() => { session?.dispose(); session = undefined; vi.unstubAllEnvs(); vi.unstubAllGlobals(); }); 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); const extensionPath = path.resolve(import.meta.dirname, "../index.ts"); session = await createTestSession({ extensions: [extensionPath] }); await new Promise((resolve) => setTimeout(resolve, 20)); expect(fetch).not.toHaveBeenCalled(); }); it("loads through Pi and registers the bak command", async () => { const extensionPath = path.resolve(import.meta.dirname, "../index.ts"); session = await createTestSession({ extensions: [extensionPath] }); const extension = session.session.extensionRunner.extensions[0]; const command = extension?.commands.get("bak"); expect(session.session.extensionRunner.extensions).toHaveLength(1); expect(command).toBeDefined(); expect(command?.getArgumentCompletions?.("res")).toEqual([ { value: "restore", label: "restore" }, ]); }); });