model.test.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { describe, expect, test } from "bun:test"
  2. import { Schema } from "effect"
  3. import { Model } from "../src/model.js"
  4. describe("Model.Ref", () => {
  5. test("parses model references with optional variants", () => {
  6. const variant = Model.Ref.parse("openrouter/openai/gpt-5#high")
  7. expect(String(variant.providerID)).toBe("openrouter")
  8. expect(String(variant.id)).toBe("openai/gpt-5")
  9. expect(String(variant.variant)).toBe("high")
  10. const standard = Model.Ref.parse("anthropic/claude-sonnet")
  11. expect(String(standard.providerID)).toBe("anthropic")
  12. expect(String(standard.id)).toBe("claude-sonnet")
  13. expect(standard.variant).toBeUndefined()
  14. })
  15. test("rejects malformed model references", () => {
  16. expect(() => Model.Ref.parse("gpt-5")).toThrow()
  17. expect(() => Model.Ref.parse("openai/gpt-5#")).toThrow()
  18. expect(() => Model.Ref.parse("openai/gpt-5#high#extra")).toThrow()
  19. })
  20. })
  21. describe("Model.ReasoningField", () => {
  22. test("accepts suggested and custom fields", () => {
  23. const decode = Schema.decodeUnknownSync(Model.ReasoningField)
  24. for (const field of ["reasoning", "reasoning_content", "reasoning_text", "vendor_reasoning"])
  25. expect(decode(field)).toBe(field)
  26. })
  27. })
  28. describe("Model.Compatibility", () => {
  29. test("decodes model compatibility overrides", () => {
  30. const decode = Schema.decodeUnknownSync(Model.Compatibility)
  31. expect(decode({})).toEqual({})
  32. expect(
  33. decode({
  34. reasoningField: "vendor_reasoning",
  35. maxTokensField: "max_completion_tokens",
  36. requireFinishReason: false,
  37. }),
  38. ).toEqual({
  39. reasoningField: "vendor_reasoning",
  40. maxTokensField: "max_completion_tokens",
  41. requireFinishReason: false,
  42. })
  43. })
  44. })