@@ -7,9 +7,11 @@ import { Credential } from "@opencode-ai/core/credential"
77import { EventV2 } from "@opencode-ai/core/event"
88import { Flag } from "@opencode-ai/core/flag/flag"
99import { Location } from "@opencode-ai/core/location"
10+ import { ModelV2 } from "@opencode-ai/core/model"
1011import { ModelsDev } from "@opencode-ai/core/models-dev"
1112import { ModelsDevPlugin } from "@opencode-ai/core/plugin/models-dev"
1213import { Policy } from "@opencode-ai/core/policy"
14+ import { ProviderV2 } from "@opencode-ai/core/provider"
1315import { AbsolutePath } from "@opencode-ai/core/schema"
1416import { location } from "../fixture/location"
1517import { testEffect } from "../lib/effect"
@@ -29,48 +31,87 @@ const catalog = Catalog.layer.pipe(
2931const layer = Layer . mergeAll ( catalog . pipe ( Layer . provide ( connections ) ) , integrations , connections , events , locationLayer )
3032const it = testEffect ( layer )
3133
34+ const withFixture = < A , E , R > ( use : Effect . Effect < A , E , R > ) =>
35+ Effect . acquireUseRelease (
36+ Effect . sync ( ( ) => {
37+ const previous = {
38+ path : Flag . OPENCODE_MODELS_PATH ,
39+ disabled : Flag . OPENCODE_DISABLE_MODELS_FETCH ,
40+ }
41+ Flag . OPENCODE_MODELS_PATH = path . join ( import . meta. dir , "fixtures" , "models-dev.json" )
42+ Flag . OPENCODE_DISABLE_MODELS_FETCH = true
43+ return previous
44+ } ) ,
45+ ( ) => use . pipe ( Effect . provide ( ModelsDev . defaultLayer ) ) ,
46+ ( previous ) =>
47+ Effect . sync ( ( ) => {
48+ Flag . OPENCODE_MODELS_PATH = previous . path
49+ Flag . OPENCODE_DISABLE_MODELS_FETCH = previous . disabled
50+ } ) ,
51+ )
52+
3253describe ( "ModelsDevPlugin" , ( ) => {
3354 it . effect ( "registers key methods for providers with environment variables" , ( ) =>
34- Effect . acquireUseRelease (
35- Effect . sync ( ( ) => {
36- const previous = {
37- path : Flag . OPENCODE_MODELS_PATH ,
38- disabled : Flag . OPENCODE_DISABLE_MODELS_FETCH ,
39- }
40- Flag . OPENCODE_MODELS_PATH = path . join ( import . meta. dir , "fixtures" , "models-dev.json" )
41- Flag . OPENCODE_DISABLE_MODELS_FETCH = true
42- return previous
55+ withFixture (
56+ Effect . gen ( function * ( ) {
57+ const integrations = yield * Integration . Service
58+ const catalog = yield * Catalog . Service
59+ yield * ModelsDevPlugin . effect (
60+ host ( {
61+ catalog : catalogHost ( catalog ) ,
62+ integration : integrationHost ( integrations ) ,
63+ } ) ,
64+ )
65+ expect ( yield * integrations . list ( ) ) . toEqual ( [
66+ new Integration . Info ( {
67+ id : Integration . ID . make ( "acme" ) ,
68+ name : "Acme" ,
69+ methods : [
70+ { type : "key" } ,
71+ {
72+ type : "env" ,
73+ names : [ "ACME_API_KEY" ] ,
74+ } ,
75+ ] ,
76+ connections : [ ] ,
77+ } ) ,
78+ new Integration . Info ( {
79+ id : Integration . ID . make ( "mammouth-ai" ) ,
80+ name : "Mammouth AI" ,
81+ methods : [
82+ { type : "key" } ,
83+ {
84+ type : "env" ,
85+ names : [ "MAMMOUTH_API_KEY" ] ,
86+ } ,
87+ ] ,
88+ connections : [ ] ,
89+ } ) ,
90+ ] )
91+ } ) ,
92+ ) ,
93+ )
94+
95+ it . effect ( "maps explicit model efforts to reasoning_effort variants" , ( ) =>
96+ withFixture (
97+ Effect . gen ( function * ( ) {
98+ const integrations = yield * Integration . Service
99+ const catalog = yield * Catalog . Service
100+ yield * ModelsDevPlugin . effect (
101+ host ( {
102+ catalog : catalogHost ( catalog ) ,
103+ integration : integrationHost ( integrations ) ,
104+ } ) ,
105+ )
106+ const model = yield * catalog . model . get ( ProviderV2 . ID . make ( "acme" ) , ModelV2 . ID . make ( "deluxe" ) )
107+ expect ( model ?. variants ) . toEqual ( [
108+ expect . objectContaining ( { id : "low" , body : { reasoning_effort : "low" } } ) ,
109+ expect . objectContaining ( { id : "medium" , body : { reasoning_effort : "medium" } } ) ,
110+ expect . objectContaining ( { id : "high" , body : { reasoning_effort : "high" } } ) ,
111+ expect . objectContaining ( { id : "xhigh" , body : { reasoning_effort : "xhigh" } } ) ,
112+ expect . objectContaining ( { id : "max" , body : { reasoning_effort : "max" } } ) ,
113+ ] )
43114 } ) ,
44- ( ) =>
45- Effect . gen ( function * ( ) {
46- const integrations = yield * Integration . Service
47- const catalog = yield * Catalog . Service
48- yield * ModelsDevPlugin . effect (
49- host ( {
50- catalog : catalogHost ( catalog ) ,
51- integration : integrationHost ( integrations ) ,
52- } ) ,
53- )
54- expect ( yield * integrations . list ( ) ) . toEqual ( [
55- new Integration . Info ( {
56- id : Integration . ID . make ( "acme" ) ,
57- name : "Acme" ,
58- methods : [
59- { type : "key" } ,
60- {
61- type : "env" ,
62- names : [ "ACME_API_KEY" ] ,
63- } ,
64- ] ,
65- connections : [ ] ,
66- } ) ,
67- ] )
68- } ) . pipe ( Effect . provide ( ModelsDev . defaultLayer ) ) ,
69- ( previous ) =>
70- Effect . sync ( ( ) => {
71- Flag . OPENCODE_MODELS_PATH = previous . path
72- Flag . OPENCODE_DISABLE_MODELS_FETCH = previous . disabled
73- } ) ,
74115 ) ,
75116 )
76117} )
0 commit comments