| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import path from "path"
- import { describe, expect } from "bun:test"
- import { Effect, Layer } from "effect"
- import { Catalog } from "@opencode-ai/core/catalog"
- import { Integration } from "@opencode-ai/core/integration"
- import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
- import { LayerNode } from "@opencode-ai/core/effect/layer-node"
- import { EventV2 } from "@opencode-ai/core/event"
- import { Flag } from "@opencode-ai/core/flag/flag"
- import { Location } from "@opencode-ai/core/location"
- import { ModelsDev } from "@opencode-ai/core/models-dev"
- import { ModelsDevPlugin } from "@opencode-ai/core/plugin/models-dev"
- import { AbsolutePath } from "@opencode-ai/core/schema"
- import { location } from "../fixture/location"
- import { testEffect } from "../lib/effect"
- import { catalogHost, host, integrationHost } from "./host"
- const locationLayer = Layer.succeed(
- Location.Service,
- Location.Service.of(location({ directory: AbsolutePath.make(import.meta.dir) })),
- )
- const layer = AppNodeBuilder.build(LayerNode.group([Catalog.node, Integration.node, EventV2.node]), [
- [Location.node, locationLayer],
- ])
- const it = testEffect(layer)
- describe("ModelsDevPlugin", () => {
- it.effect("registers key methods for providers with environment variables", () =>
- Effect.acquireUseRelease(
- Effect.sync(() => {
- const previous = {
- path: Flag.OPENCODE_MODELS_PATH,
- disabled: Flag.OPENCODE_DISABLE_MODELS_FETCH,
- }
- Flag.OPENCODE_MODELS_PATH = path.join(import.meta.dir, "fixtures", "models-dev.json")
- Flag.OPENCODE_DISABLE_MODELS_FETCH = true
- return previous
- }),
- () =>
- Effect.gen(function* () {
- const integrations = yield* Integration.Service
- const catalog = yield* Catalog.Service
- yield* ModelsDevPlugin.effect(
- host({
- catalog: catalogHost(catalog),
- integration: integrationHost(integrations),
- }),
- )
- expect(yield* integrations.list()).toEqual([
- new Integration.Info({
- id: Integration.ID.make("acme"),
- name: "Acme",
- methods: [
- { type: "key" },
- {
- type: "env",
- names: ["ACME_API_KEY"],
- },
- ],
- connections: [],
- }),
- ])
- }).pipe(Effect.provide(AppNodeBuilder.build(ModelsDev.node))),
- (previous) =>
- Effect.sync(() => {
- Flag.OPENCODE_MODELS_PATH = previous.path
- Flag.OPENCODE_DISABLE_MODELS_FETCH = previous.disabled
- }),
- ),
- )
- })
|