File size: 1,339 Bytes
df23150
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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",
    ]);
  });
});