|
| 1 | +import { describe, expect, it } from "bun:test"; |
| 2 | +import { piModelRefToCanonical, resolveModelRefForPi } from "./harness-provider-map"; |
| 3 | + |
| 4 | +describe("harness-provider-map", () => { |
| 5 | + describe("resolveModelRefForPi (canonical -> Pi, used when spawning)", () => { |
| 6 | + it("maps the diverging auth-plugin providers, preserving the model id", () => { |
| 7 | + expect(resolveModelRefForPi("openai/gpt-5.5")).toBe("openai-codex/gpt-5.5"); |
| 8 | + expect(resolveModelRefForPi("google/antigravity-gemini-3.5-flash")).toBe( |
| 9 | + "google-antigravity/antigravity-gemini-3.5-flash", |
| 10 | + ); |
| 11 | + }); |
| 12 | + |
| 13 | + it("leaves anthropic and every other provider unchanged", () => { |
| 14 | + expect(resolveModelRefForPi("anthropic/claude-opus-4-8")).toBe( |
| 15 | + "anthropic/claude-opus-4-8", |
| 16 | + ); |
| 17 | + expect(resolveModelRefForPi("cerebras/gpt-oss-120b")).toBe("cerebras/gpt-oss-120b"); |
| 18 | + expect(resolveModelRefForPi("openrouter/openai/gpt-5.5")).toBe( |
| 19 | + "openrouter/openai/gpt-5.5", |
| 20 | + ); |
| 21 | + }); |
| 22 | + |
| 23 | + it("is idempotent: a config already in Pi form still resolves to Pi form", () => { |
| 24 | + expect(resolveModelRefForPi("openai-codex/gpt-5.5")).toBe("openai-codex/gpt-5.5"); |
| 25 | + expect(resolveModelRefForPi("google-antigravity/antigravity-gemini-3.1-pro")).toBe( |
| 26 | + "google-antigravity/antigravity-gemini-3.1-pro", |
| 27 | + ); |
| 28 | + }); |
| 29 | + |
| 30 | + it("preserves model ids that themselves contain slashes", () => { |
| 31 | + expect(resolveModelRefForPi("openai/some/nested/id")).toBe( |
| 32 | + "openai-codex/some/nested/id", |
| 33 | + ); |
| 34 | + }); |
| 35 | + |
| 36 | + it("passes through malformed refs (no slash, empty provider) unchanged", () => { |
| 37 | + expect(resolveModelRefForPi("gpt-5.5")).toBe("gpt-5.5"); |
| 38 | + expect(resolveModelRefForPi("/gpt-5.5")).toBe("/gpt-5.5"); |
| 39 | + expect(resolveModelRefForPi("")).toBe(""); |
| 40 | + }); |
| 41 | + }); |
| 42 | + |
| 43 | + describe("piModelRefToCanonical (Pi -> canonical, used by Pi setup write)", () => { |
| 44 | + it("normalizes Pi-native provider ids to the OpenCode form", () => { |
| 45 | + expect(piModelRefToCanonical("openai-codex/gpt-5.5")).toBe("openai/gpt-5.5"); |
| 46 | + expect(piModelRefToCanonical("google-antigravity/antigravity-gemini-3.5-flash")).toBe( |
| 47 | + "google/antigravity-gemini-3.5-flash", |
| 48 | + ); |
| 49 | + }); |
| 50 | + |
| 51 | + it("leaves already-canonical and unmapped providers unchanged", () => { |
| 52 | + expect(piModelRefToCanonical("anthropic/claude-opus-4-8")).toBe( |
| 53 | + "anthropic/claude-opus-4-8", |
| 54 | + ); |
| 55 | + expect(piModelRefToCanonical("openai/gpt-5.5")).toBe("openai/gpt-5.5"); |
| 56 | + }); |
| 57 | + |
| 58 | + it("round-trips with resolveModelRefForPi", () => { |
| 59 | + const piForm = "openai-codex/gpt-5.5"; |
| 60 | + expect(resolveModelRefForPi(piModelRefToCanonical(piForm))).toBe(piForm); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments