| import { beforeEach, describe, expect, it, vi } from "vitest"; |
| import { createTestHarness } from "@paperclipai/plugin-sdk/testing"; |
| import { FETCH_MODELS_ACTION } from "../src/constants.js"; |
| import manifest from "../src/manifest.js"; |
| import plugin from "../src/worker.js"; |
|
|
| describe("plugin worker", () => { |
| beforeEach(() => { |
| vi.restoreAllMocks(); |
| }); |
|
|
| it("registers the fetch-models action and returns normalized models", async () => { |
| const fetchSpy = vi.spyOn(globalThis, "fetch").mockResolvedValue({ |
| ok: true, |
| json: async () => ({ |
| data: [ |
| { id: "gpt-5.4" }, |
| { id: "gpt-5.3-codex", name: "GPT-5.3 Codex" }, |
| ], |
| }), |
| } as Response); |
|
|
| const harness = createTestHarness({ |
| manifest, |
| capabilities: [...manifest.capabilities], |
| }); |
| await plugin.definition.setup(harness.ctx); |
|
|
| const result = await harness.performAction<{ |
| baseUrl: string; |
| modelCatalog: Array<{ id: string; label: string }>; |
| }>(FETCH_MODELS_ACTION, { |
| baseUrl: "https://example.test/v1/", |
| apiKey: "sk-provider", |
| }); |
|
|
| expect(fetchSpy).toHaveBeenCalledOnce(); |
| expect(result.baseUrl).toBe("https://example.test/v1"); |
| expect(result.modelCatalog.map((entry) => entry.id)).toEqual([ |
| "gpt-5.3-codex", |
| "gpt-5.4", |
| ]); |
| }); |
| }); |
|
|