variant.test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import { describe, expect } from "bun:test"
  2. import { Catalog } from "@opencode-ai/core/catalog"
  3. import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
  4. import { LayerNode } from "@opencode-ai/core/effect/layer-node"
  5. import { Location } from "@opencode-ai/core/location"
  6. import { ModelV2 } from "@opencode-ai/core/model"
  7. import { VariantPlugin } from "@opencode-ai/core/plugin/variant"
  8. import { ProviderV2 } from "@opencode-ai/core/provider"
  9. import { AbsolutePath } from "@opencode-ai/core/schema"
  10. import { Effect, Layer } from "effect"
  11. import { location } from "../fixture/location"
  12. import { testEffect } from "../lib/effect"
  13. import { catalogHost, host } from "./host"
  14. const locationLayer = Layer.succeed(
  15. Location.Service,
  16. Location.Service.of(location({ directory: AbsolutePath.make(import.meta.dir) })),
  17. )
  18. const it = testEffect(
  19. AppNodeBuilder.build(
  20. Catalog.node,
  21. [[Location.node, locationLayer]],
  22. ),
  23. )
  24. describe("VariantPlugin", () => {
  25. it.effect("adds GLM 5.2 variants after catalog sources", () =>
  26. Effect.gen(function* () {
  27. const service = yield* Catalog.Service
  28. yield* service.transform((catalog) => {
  29. catalog.provider.update(ProviderV2.ID.opencode, (provider) => {
  30. provider.api = { type: "aisdk", package: "@ai-sdk/openai-compatible" }
  31. })
  32. catalog.model.update(ProviderV2.ID.opencode, ModelV2.ID.make("glm-5.2"), (model) => {
  33. model.api = {
  34. id: ModelV2.ID.make("glm-5.2"),
  35. type: "aisdk",
  36. package: "@ai-sdk/openai-compatible",
  37. }
  38. })
  39. })
  40. yield* VariantPlugin.Plugin.effect(host({ catalog: catalogHost(service) }))
  41. expect((yield* service.model.get(ProviderV2.ID.opencode, ModelV2.ID.make("glm-5.2")))?.variants).toEqual([
  42. expect.objectContaining({ id: "high", body: { reasoning_effort: "high" } }),
  43. expect.objectContaining({ id: "max", body: { reasoning_effort: "max" } }),
  44. ])
  45. }),
  46. )
  47. it.effect("keeps explicit variants over generated defaults", () =>
  48. Effect.gen(function* () {
  49. const service = yield* Catalog.Service
  50. yield* service.transform((catalog) => {
  51. catalog.model.update(ProviderV2.ID.opencode, ModelV2.ID.make("glm-5.2"), (model) => {
  52. model.api = {
  53. id: ModelV2.ID.make("glm-5.2"),
  54. type: "aisdk",
  55. package: "@ai-sdk/openai-compatible",
  56. }
  57. model.variants = [{ id: ModelV2.VariantID.make("high"), headers: { custom: "true" }, body: {} }]
  58. })
  59. })
  60. yield* VariantPlugin.Plugin.effect(host({ catalog: catalogHost(service) }))
  61. expect((yield* service.model.get(ProviderV2.ID.opencode, ModelV2.ID.make("glm-5.2")))?.variants).toEqual([
  62. expect.objectContaining({ id: "high", headers: { custom: "true" } }),
  63. expect.objectContaining({ id: "max", body: { reasoning_effort: "max" } }),
  64. ])
  65. }),
  66. )
  67. })