|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | + |
| 3 | +vi.mock("@mariozechner/pi-ai/oauth", () => ({ |
| 4 | + getOAuthApiKey: vi.fn(), |
| 5 | + getOAuthProviders: vi.fn(() => []), |
| 6 | +})); |
| 7 | + |
| 8 | +vi.mock("openclaw/plugin-sdk/provider-models", () => ({ |
| 9 | + normalizeModelCompat: (model: Record<string, unknown>) => model, |
| 10 | +})); |
| 11 | + |
| 12 | +import type { ProviderResolveDynamicModelContext } from "openclaw/plugin-sdk/core"; |
| 13 | +import { resolveCopilotForwardCompatModel } from "./models.js"; |
| 14 | + |
| 15 | +function createMockCtx( |
| 16 | + modelId: string, |
| 17 | + registryModels: Record<string, Record<string, unknown>> = {}, |
| 18 | +): ProviderResolveDynamicModelContext { |
| 19 | + return { |
| 20 | + modelId, |
| 21 | + provider: "github-copilot", |
| 22 | + config: {}, |
| 23 | + modelRegistry: { |
| 24 | + find: (provider: string, id: string) => registryModels[`${provider}/${id}`] ?? null, |
| 25 | + }, |
| 26 | + } as unknown as ProviderResolveDynamicModelContext; |
| 27 | +} |
| 28 | + |
| 29 | +describe("resolveCopilotForwardCompatModel", () => { |
| 30 | + it("returns undefined for empty modelId", () => { |
| 31 | + expect(resolveCopilotForwardCompatModel(createMockCtx(""))).toBeUndefined(); |
| 32 | + expect(resolveCopilotForwardCompatModel(createMockCtx(" "))).toBeUndefined(); |
| 33 | + }); |
| 34 | + |
| 35 | + it("returns undefined when model is already in registry", () => { |
| 36 | + const ctx = createMockCtx("gpt-4o", { |
| 37 | + "github-copilot/gpt-4o": { id: "gpt-4o", name: "gpt-4o" }, |
| 38 | + }); |
| 39 | + expect(resolveCopilotForwardCompatModel(ctx)).toBeUndefined(); |
| 40 | + }); |
| 41 | + |
| 42 | + it("clones gpt-5.2-codex template for gpt-5.3-codex", () => { |
| 43 | + const template = { |
| 44 | + id: "gpt-5.2-codex", |
| 45 | + name: "gpt-5.2-codex", |
| 46 | + provider: "github-copilot", |
| 47 | + api: "openai-responses", |
| 48 | + reasoning: true, |
| 49 | + contextWindow: 200_000, |
| 50 | + }; |
| 51 | + const ctx = createMockCtx("gpt-5.3-codex", { |
| 52 | + "github-copilot/gpt-5.2-codex": template, |
| 53 | + }); |
| 54 | + const result = resolveCopilotForwardCompatModel(ctx); |
| 55 | + expect(result).toBeDefined(); |
| 56 | + expect(result!.id).toBe("gpt-5.3-codex"); |
| 57 | + expect(result!.name).toBe("gpt-5.3-codex"); |
| 58 | + expect((result as unknown as Record<string, unknown>).reasoning).toBe(true); |
| 59 | + }); |
| 60 | + |
| 61 | + it("falls through to synthetic catch-all when codex template is missing", () => { |
| 62 | + const ctx = createMockCtx("gpt-5.3-codex"); |
| 63 | + const result = resolveCopilotForwardCompatModel(ctx); |
| 64 | + expect(result).toBeDefined(); |
| 65 | + expect(result!.id).toBe("gpt-5.3-codex"); |
| 66 | + }); |
| 67 | + |
| 68 | + it("creates synthetic model for arbitrary unknown model ID", () => { |
| 69 | + const ctx = createMockCtx("gpt-5.4-mini"); |
| 70 | + const result = resolveCopilotForwardCompatModel(ctx); |
| 71 | + expect(result).toBeDefined(); |
| 72 | + expect(result!.id).toBe("gpt-5.4-mini"); |
| 73 | + expect(result!.name).toBe("gpt-5.4-mini"); |
| 74 | + expect((result as unknown as Record<string, unknown>).api).toBe("openai-responses"); |
| 75 | + expect((result as unknown as Record<string, unknown>).input).toEqual(["text", "image"]); |
| 76 | + }); |
| 77 | + |
| 78 | + it("infers reasoning=true for o1/o3 model IDs", () => { |
| 79 | + for (const id of ["o1", "o3", "o3-mini", "o1-preview"]) { |
| 80 | + const ctx = createMockCtx(id); |
| 81 | + const result = resolveCopilotForwardCompatModel(ctx); |
| 82 | + expect(result).toBeDefined(); |
| 83 | + expect((result as unknown as Record<string, unknown>).reasoning).toBe(true); |
| 84 | + } |
| 85 | + }); |
| 86 | + |
| 87 | + it("sets reasoning=false for non-reasoning model IDs including mid-string o1/o3", () => { |
| 88 | + for (const id of [ |
| 89 | + "gpt-5.4-mini", |
| 90 | + "claude-sonnet-4.6", |
| 91 | + "gpt-4o", |
| 92 | + "audio-o1-hd", |
| 93 | + "turbo-o3-voice", |
| 94 | + ]) { |
| 95 | + const ctx = createMockCtx(id); |
| 96 | + const result = resolveCopilotForwardCompatModel(ctx); |
| 97 | + expect(result).toBeDefined(); |
| 98 | + expect((result as unknown as Record<string, unknown>).reasoning).toBe(false); |
| 99 | + } |
| 100 | + }); |
| 101 | +}); |
0 commit comments