model-variant.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { describe, expect, test } from "bun:test"
  2. import { cycleModelVariant, getConfiguredAgentVariant, resolveModelVariant } from "./model-variant"
  3. describe("model variant", () => {
  4. test("resolves configured agent variant when model matches", () => {
  5. const value = getConfiguredAgentVariant({
  6. agent: {
  7. model: { providerID: "openai", modelID: "gpt-5.2" },
  8. variant: "xhigh",
  9. },
  10. model: {
  11. providerID: "openai",
  12. modelID: "gpt-5.2",
  13. variants: { low: {}, high: {}, xhigh: {} },
  14. },
  15. })
  16. expect(value).toBe("xhigh")
  17. })
  18. test("ignores configured variant when model does not match", () => {
  19. const value = getConfiguredAgentVariant({
  20. agent: {
  21. model: { providerID: "openai", modelID: "gpt-5.2" },
  22. variant: "xhigh",
  23. },
  24. model: {
  25. providerID: "anthropic",
  26. modelID: "claude-sonnet-4",
  27. variants: { low: {}, high: {}, xhigh: {} },
  28. },
  29. })
  30. expect(value).toBeUndefined()
  31. })
  32. test("prefers selected variant over configured variant", () => {
  33. const value = resolveModelVariant({
  34. variants: ["low", "high", "xhigh"],
  35. selected: "high",
  36. configured: "xhigh",
  37. })
  38. expect(value).toBe("high")
  39. })
  40. test("lets an explicit default override the configured variant", () => {
  41. const value = resolveModelVariant({
  42. variants: ["low", "high", "xhigh"],
  43. selected: null,
  44. configured: "xhigh",
  45. })
  46. expect(value).toBeUndefined()
  47. })
  48. test("cycles from configured variant to next", () => {
  49. const value = cycleModelVariant({
  50. variants: ["low", "high", "xhigh"],
  51. selected: undefined,
  52. configured: "high",
  53. })
  54. expect(value).toBe("xhigh")
  55. })
  56. test("wraps from configured last variant to first", () => {
  57. const value = cycleModelVariant({
  58. variants: ["low", "high", "xhigh"],
  59. selected: undefined,
  60. configured: "xhigh",
  61. })
  62. expect(value).toBe("low")
  63. })
  64. test("cycles from an explicit default to the first variant", () => {
  65. const value = cycleModelVariant({
  66. variants: ["low", "high", "xhigh"],
  67. selected: null,
  68. configured: "xhigh",
  69. })
  70. expect(value).toBe("low")
  71. })
  72. })