model.test.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. import { describe, expect, test } from "bun:test"
  2. import { ConfigModel } from "@opencode-ai/core/config/model"
  3. import { Model } from "@opencode-ai/schema/model"
  4. import { Provider } from "@opencode-ai/schema/provider"
  5. import { Schema } from "effect"
  6. const decode = Schema.decodeUnknownSync(ConfigModel.Selection)
  7. describe("ConfigModel.Selection", () => {
  8. test("normalizes short and explicit model selections", () => {
  9. expect(decode("openrouter/openai/gpt-5#high")).toEqual({
  10. providerID: Provider.ID.make("openrouter"),
  11. model: Model.ID.make("openai/gpt-5"),
  12. variant: Model.VariantID.make("high"),
  13. })
  14. expect(decode({ providerID: "anthropic", model: "claude-sonnet", variant: "high" })).toEqual({
  15. providerID: Provider.ID.make("anthropic"),
  16. model: Model.ID.make("claude-sonnet"),
  17. variant: Model.VariantID.make("high"),
  18. })
  19. })
  20. test("rejects malformed selections and reserved fragments", () => {
  21. expect(() => decode("gpt-5")).toThrow()
  22. expect(() => decode("openai/gpt-5#")).toThrow()
  23. expect(() => decode({ providerID: "openai", model: "gpt-5#high" })).toThrow()
  24. })
  25. })