@@ -21,22 +21,6 @@ function app() {
2121 return Server . Default ( ) . app
2222}
2323
24- function providerListHasFetch ( list : unknown ) {
25- if ( ! Array . isArray ( list ) ) return false
26- return list . some ( ( item : unknown ) => {
27- if ( typeof item !== "object" || item === null || ! ( "id" in item ) || ! ( "options" in item ) ) return false
28- if ( item . id !== "google" ) return false
29- if ( typeof item . options !== "object" || item . options === null ) return false
30- return "fetch" in item . options
31- } )
32- }
33-
34- function hasProviderWithFetch ( input : unknown , key : "all" | "providers" ) {
35- if ( typeof input !== "object" || input === null ) return false
36- if ( key === "all" ) return "all" in input && providerListHasFetch ( input . all )
37- return "providers" in input && providerListHasFetch ( input . providers )
38- }
39-
4024function requestAuthorize ( input : {
4125 app : ReturnType < typeof app >
4226 providerID : string
@@ -92,39 +76,6 @@ function writeProviderAuthPlugin(dir: string) {
9276 } )
9377}
9478
95- function writeFunctionOptionsPlugin ( dir : string ) {
96- return Effect . gen ( function * ( ) {
97- const fs = yield * FileSystem . FileSystem
98- const path = yield * Path . Path
99-
100- yield * fs . makeDirectory ( path . join ( dir , ".opencode" , "plugin" ) , { recursive : true } )
101- yield * fs . writeFileString (
102- path . join ( dir , ".opencode" , "plugin" , "provider-function-options.ts" ) ,
103- [
104- "export default {" ,
105- ' id: "test.provider-function-options",' ,
106- " server: async () => ({" ,
107- " auth: {" ,
108- ' provider: "google",' ,
109- " loader: async (_getAuth, provider) => {" ,
110- " for (const model of Object.values(provider.models ?? {})) {" ,
111- " model.cost = { input: 0, output: 0 }" ,
112- " }" ,
113- " return {" ,
114- ' apiKey: "",' ,
115- " fetch: async (input, init) => fetch(input, init)," ,
116- " }" ,
117- " }," ,
118- " methods: [{ type: 'api', label: 'API key' }]," ,
119- " }," ,
120- " })," ,
121- "}" ,
122- "" ,
123- ] . join ( "\n" ) ,
124- )
125- } )
126- }
127-
12879function withProviderProject < A , E , R > ( self : ( dir : string ) => Effect . Effect < A , E , R > ) {
12980 return Effect . gen ( function * ( ) {
13081 const fs = yield * FileSystem . FileSystem
@@ -185,43 +136,4 @@ describe("provider HttpApi", () => {
185136 } ) ,
186137 ) ,
187138 )
188-
189- it . live ( "serves provider lists when auth loaders add runtime fetch options" , ( ) =>
190- Effect . gen ( function * ( ) {
191- const fs = yield * FileSystem . FileSystem
192- const path = yield * Path . Path
193- const dir = yield * fs . makeTempDirectoryScoped ( { prefix : "opencode-test-" } )
194- const previous = process . env . OPENCODE_AUTH_CONTENT
195-
196- yield * fs . writeFileString (
197- path . join ( dir , "opencode.json" ) ,
198- JSON . stringify ( { $schema : "https://opencode.ai/config.json" , formatter : false , lsp : false } ) ,
199- )
200- yield * writeFunctionOptionsPlugin ( dir )
201- yield * Effect . sync ( ( ) => {
202- process . env . OPENCODE_AUTH_CONTENT = JSON . stringify ( {
203- google : { type : "oauth" , refresh : "dummy" , access : "dummy" , expires : 9999999999999 } ,
204- } )
205- } )
206- yield * Effect . addFinalizer ( ( ) =>
207- Effect . sync ( ( ) => {
208- if ( previous === undefined ) delete process . env . OPENCODE_AUTH_CONTENT
209- if ( previous !== undefined ) process . env . OPENCODE_AUTH_CONTENT = previous
210- } ) ,
211- )
212- const headers = { "x-opencode-directory" : dir }
213- const providerResponse = yield * Effect . promise ( ( ) => Promise . resolve ( app ( ) . request ( "/provider" , { headers } ) ) )
214- const configResponse = yield * Effect . promise ( ( ) =>
215- Promise . resolve ( app ( ) . request ( "/config/providers" , { headers } ) ) ,
216- )
217-
218- expect ( providerResponse . status ) . toBe ( 200 )
219- expect ( configResponse . status ) . toBe ( 200 )
220-
221- const providerBody = yield * Effect . promise ( ( ) => providerResponse . json ( ) )
222- const configBody = yield * Effect . promise ( ( ) => configResponse . json ( ) )
223- expect ( hasProviderWithFetch ( providerBody , "all" ) ) . toBe ( false )
224- expect ( hasProviderWithFetch ( configBody , "providers" ) ) . toBe ( false )
225- } ) ,
226- )
227139} )
0 commit comments