model.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { describe, expect, test } from "bun:test"
  2. import { formatRef, parse, switchLabel } from "../../src/util/model"
  3. describe("util.model", () => {
  4. test("splits provider from a nested model identifier", () => {
  5. expect(parse("provider/org/model")).toEqual({ providerID: "provider", modelID: "org/model" })
  6. expect(parse("invalid")).toEqual({ providerID: "invalid", modelID: "" })
  7. })
  8. test("includes the selected variant in model refs", () => {
  9. expect(formatRef({ providerID: "anthropic", id: "sonnet", variant: "thinking" })).toBe("anthropic/sonnet/thinking")
  10. expect(formatRef({ providerID: "anthropic", id: "sonnet" })).toBe("anthropic/sonnet")
  11. })
  12. test("includes the selected variant in model switch notices", () => {
  13. expect(switchLabel({ providerID: "anthropic", id: "sonnet", variant: "thinking" })).toBe(
  14. "Switched model to anthropic/sonnet/thinking",
  15. )
  16. })
  17. test("uses the catalog display name in model switch notices", () => {
  18. const models = [
  19. { providerID: "openai", id: "gpt-5.5-fast", name: "GPT-5.5 Fast" },
  20. { providerID: "anthropic", id: "sonnet", name: "Claude Sonnet" },
  21. ]
  22. expect(switchLabel({ providerID: "openai", id: "gpt-5.5-fast", variant: "high" }, models)).toBe(
  23. "Switched model to GPT-5.5 Fast (high)",
  24. )
  25. expect(switchLabel({ providerID: "anthropic", id: "sonnet" }, models)).toBe("Switched model to Claude Sonnet")
  26. expect(switchLabel({ providerID: "anthropic", id: "sonnet", variant: "default" }, models)).toBe(
  27. "Switched model to Claude Sonnet",
  28. )
  29. expect(switchLabel({ providerID: "removed", id: "gone", variant: "high" }, models)).toBe(
  30. "Switched model to removed/gone/high",
  31. )
  32. })
  33. test("distinguishes variant-only switches from model switches", () => {
  34. const previous = { providerID: "openai", id: "gpt-5.5", variant: "medium" }
  35. expect(switchLabel({ ...previous, variant: "high" }, undefined, previous)).toBe("Switched variant to high")
  36. expect(switchLabel({ providerID: "openai", id: "gpt-5.5" }, undefined, previous)).toBe(
  37. "Switched variant to default",
  38. )
  39. expect(switchLabel({ providerID: "anthropic", id: "sonnet", variant: "high" }, undefined, previous)).toBe(
  40. "Switched model to anthropic/sonnet/high",
  41. )
  42. })
  43. })