variant.shared.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { describe, expect, test } from "bun:test"
  2. import { cycleVariant, formatModelLabel, pickVariant, resolveVariant } from "../../src/mini/variant.shared"
  3. import type { RunSession } from "../../src/mini/session.shared"
  4. import type { RunProvider } from "../../src/mini/types"
  5. const model = {
  6. providerID: "openai",
  7. modelID: "gpt-5",
  8. }
  9. const providers: RunProvider[] = [
  10. {
  11. id: "openai",
  12. name: "OpenAI",
  13. models: {
  14. "gpt-5": {
  15. name: "GPT-5",
  16. },
  17. },
  18. },
  19. ]
  20. describe("run variant shared", () => {
  21. test("prefers cli then session then saved variants", () => {
  22. expect(resolveVariant("max", "high", "low", ["low", "high"])).toBe("max")
  23. expect(resolveVariant("default", "high", "low", ["low", "high"])).toBeUndefined()
  24. expect(resolveVariant(undefined, "high", "low", ["low", "high"])).toBe("high")
  25. expect(resolveVariant(undefined, "missing", "low", ["low", "high"])).toBe("low")
  26. })
  27. test("cycles through variants and back to default", () => {
  28. expect(cycleVariant(undefined, ["low", "high"])).toBe("low")
  29. expect(cycleVariant("default", ["low", "high"])).toBe("low")
  30. expect(cycleVariant("low", ["low", "high"])).toBe("high")
  31. expect(cycleVariant("high", ["low", "high"])).toBeUndefined()
  32. expect(cycleVariant(undefined, [])).toBeUndefined()
  33. })
  34. test("formats model labels", () => {
  35. expect(formatModelLabel(model, undefined)).toBe("gpt-5 · openai")
  36. expect(formatModelLabel(model, "high")).toBe("gpt-5 · openai · high")
  37. expect(formatModelLabel(model, undefined, providers)).toBe("GPT-5 · OpenAI")
  38. expect(formatModelLabel(model, "high", providers)).toBe("GPT-5 · OpenAI · high")
  39. })
  40. test("picks the latest matching variant from session history", () => {
  41. const session: RunSession = {
  42. first: false,
  43. turns: [
  44. { prompt: { text: "one", parts: [] }, provider: "openai", model: "gpt-5", variant: "high" },
  45. { prompt: { text: "two", parts: [] }, provider: "anthropic", model: "sonnet", variant: "max" },
  46. { prompt: { text: "three", parts: [] }, provider: "openai", model: "gpt-5", variant: "minimal" },
  47. ],
  48. }
  49. expect(pickVariant(model, session)).toBe("minimal")
  50. })
  51. })