@@ -87,10 +87,6 @@ async function getModel(providerID: ProviderID, modelID: ModelID, ctx: InstanceC |
87 | 87 | return run(ctx, (provider) => provider.getModel(providerID, modelID)) |
88 | 88 | } |
89 | 89 |
|
90 | | -async function getLanguage(model: Provider.Model, ctx: InstanceContext) { |
91 | | - return run(ctx, (provider) => provider.getLanguage(model)) |
92 | | -} |
93 | | - |
94 | 90 | async function closest(providerID: ProviderID, query: string[], ctx: InstanceContext) { |
95 | 91 | return run(ctx, (provider) => provider.closest(providerID, query)) |
96 | 92 | } |
@@ -99,10 +95,6 @@ async function getSmallModel(providerID: ProviderID, ctx: InstanceContext) { |
99 | 95 | return run(ctx, (provider) => provider.getSmallModel(providerID)) |
100 | 96 | } |
101 | 97 |
|
102 | | -async function defaultModel(ctx: InstanceContext) { |
103 | | - return run(ctx, (provider) => provider.defaultModel()) |
104 | | -} |
105 | | - |
106 | 98 | function paid(providers: Awaited<ReturnType<typeof list>>) { |
107 | 99 | const item = providers[ProviderID.make("opencode")] |
108 | 100 | expect(item).toBeDefined() |
@@ -361,62 +353,42 @@ it.instance( |
361 | 353 | }, |
362 | 354 | ) |
363 | 355 |
|
364 | | -test("env variable takes precedence, config merges options", async () => { |
365 | | - await using tmp = await tmpdir({ |
366 | | - init: async (dir) => { |
367 | | - await Bun.write( |
368 | | - path.join(dir, "opencode.json"), |
369 | | - JSON.stringify({ |
370 | | - $schema: "https://opencode.ai/config.json", |
371 | | - provider: { |
372 | | - anthropic: { |
373 | | - options: { |
374 | | - timeout: 60000, |
375 | | - chunkTimeout: 15000, |
376 | | - }, |
377 | | - }, |
| 356 | +it.instance( |
| 357 | + "env variable takes precedence, config merges options", |
| 358 | + Effect.gen(function* () { |
| 359 | + yield* setProcessEnv("ANTHROPIC_API_KEY", "env-api-key") |
| 360 | + const providers = yield* Provider.Service.use((provider) => provider.list()) |
| 361 | + expect(providers[ProviderID.anthropic]).toBeDefined() |
| 362 | + // Config options should be merged |
| 363 | + expect(providers[ProviderID.anthropic].options.timeout).toBe(60000) |
| 364 | + expect(providers[ProviderID.anthropic].options.chunkTimeout).toBe(15000) |
| 365 | + }), |
| 366 | + { |
| 367 | + config: { |
| 368 | + provider: { |
| 369 | + anthropic: { |
| 370 | + options: { |
| 371 | + timeout: 60000, |
| 372 | + chunkTimeout: 15000, |
378 | 373 | }, |
379 | | - }), |
380 | | - ) |
381 | | - }, |
382 | | - }) |
383 | | - await withTestInstance({ |
384 | | - directory: tmp.path, |
385 | | - fn: async (ctx) => { |
386 | | - await set(ctx, "ANTHROPIC_API_KEY", "env-api-key") |
387 | | - const providers = await list(ctx) |
388 | | - expect(providers[ProviderID.anthropic]).toBeDefined() |
389 | | - // Config options should be merged |
390 | | - expect(providers[ProviderID.anthropic].options.timeout).toBe(60000) |
391 | | - expect(providers[ProviderID.anthropic].options.chunkTimeout).toBe(15000) |
| 374 | + }, |
| 375 | + }, |
392 | 376 | }, |
393 | | - }) |
394 | | -}) |
| 377 | + }, |
| 378 | +) |
395 | 379 |
|
396 | | -test("getModel returns model for valid provider/model", async () => { |
397 | | - await using tmp = await tmpdir({ |
398 | | - init: async (dir) => { |
399 | | - await Bun.write( |
400 | | - path.join(dir, "opencode.json"), |
401 | | - JSON.stringify({ |
402 | | - $schema: "https://opencode.ai/config.json", |
403 | | - }), |
404 | | - ) |
405 | | - }, |
406 | | - }) |
407 | | - await withTestInstance({ |
408 | | - directory: tmp.path, |
409 | | - fn: async (ctx) => { |
410 | | - await set(ctx, "ANTHROPIC_API_KEY", "test-api-key") |
411 | | - const model = await getModel(ProviderID.anthropic, ModelID.make("claude-sonnet-4-20250514"), ctx) |
412 | | - expect(model).toBeDefined() |
413 | | - expect(String(model.providerID)).toBe("anthropic") |
414 | | - expect(String(model.id)).toBe("claude-sonnet-4-20250514") |
415 | | - const language = await getLanguage(model, ctx) |
416 | | - expect(language).toBeDefined() |
417 | | - }, |
418 | | - }) |
419 | | -}) |
| 380 | +it.instance("getModel returns model for valid provider/model", () => |
| 381 | + Effect.gen(function* () { |
| 382 | + yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key") |
| 383 | + const provider = yield* Provider.Service |
| 384 | + const model = yield* provider.getModel(ProviderID.anthropic, ModelID.make("claude-sonnet-4-20250514")) |
| 385 | + expect(model).toBeDefined() |
| 386 | + expect(String(model.providerID)).toBe("anthropic") |
| 387 | + expect(String(model.id)).toBe("claude-sonnet-4-20250514") |
| 388 | + const language = yield* provider.getLanguage(model) |
| 389 | + expect(language).toBeDefined() |
| 390 | + }), |
| 391 | +) |
420 | 392 |
|
421 | 393 | test("getModel throws ModelNotFoundError for invalid model", async () => { |
422 | 394 | await using tmp = await tmpdir({ |
@@ -469,50 +441,25 @@ test("parseModel handles model IDs with slashes", () => { |
469 | 441 | expect(String(result.modelID)).toBe("anthropic/claude-3-opus") |
470 | 442 | }) |
471 | 443 |
|
472 | | -test("defaultModel returns first available model when no config set", async () => { |
473 | | - await using tmp = await tmpdir({ |
474 | | - init: async (dir) => { |
475 | | - await Bun.write( |
476 | | - path.join(dir, "opencode.json"), |
477 | | - JSON.stringify({ |
478 | | - $schema: "https://opencode.ai/config.json", |
479 | | - }), |
480 | | - ) |
481 | | - }, |
482 | | - }) |
483 | | - await withTestInstance({ |
484 | | - directory: tmp.path, |
485 | | - fn: async (ctx) => { |
486 | | - await set(ctx, "ANTHROPIC_API_KEY", "test-api-key") |
487 | | - const model = await defaultModel(ctx) |
488 | | - expect(model.providerID).toBeDefined() |
489 | | - expect(model.modelID).toBeDefined() |
490 | | - }, |
491 | | - }) |
492 | | -}) |
| 444 | +it.instance("defaultModel returns first available model when no config set", () => |
| 445 | + Effect.gen(function* () { |
| 446 | + yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key") |
| 447 | + const model = yield* Provider.Service.use((provider) => provider.defaultModel()) |
| 448 | + expect(model.providerID).toBeDefined() |
| 449 | + expect(model.modelID).toBeDefined() |
| 450 | + }), |
| 451 | +) |
493 | 452 |
|
494 | | -test("defaultModel respects config model setting", async () => { |
495 | | - await using tmp = await tmpdir({ |
496 | | - init: async (dir) => { |
497 | | - await Bun.write( |
498 | | - path.join(dir, "opencode.json"), |
499 | | - JSON.stringify({ |
500 | | - $schema: "https://opencode.ai/config.json", |
501 | | - model: "anthropic/claude-sonnet-4-20250514", |
502 | | - }), |
503 | | - ) |
504 | | - }, |
505 | | - }) |
506 | | - await withTestInstance({ |
507 | | - directory: tmp.path, |
508 | | - fn: async (ctx) => { |
509 | | - await set(ctx, "ANTHROPIC_API_KEY", "test-api-key") |
510 | | - const model = await defaultModel(ctx) |
511 | | - expect(String(model.providerID)).toBe("anthropic") |
512 | | - expect(String(model.modelID)).toBe("claude-sonnet-4-20250514") |
513 | | - }, |
514 | | - }) |
515 | | -}) |
| 453 | +it.instance( |
| 454 | + "defaultModel respects config model setting", |
| 455 | + Effect.gen(function* () { |
| 456 | + yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key") |
| 457 | + const model = yield* Provider.Service.use((provider) => provider.defaultModel()) |
| 458 | + expect(String(model.providerID)).toBe("anthropic") |
| 459 | + expect(String(model.modelID)).toBe("claude-sonnet-4-20250514") |
| 460 | + }), |
| 461 | + { config: { model: "anthropic/claude-sonnet-4-20250514" } }, |
| 462 | +) |
516 | 463 |
|
517 | 464 | it.instance( |
518 | 465 | "provider with baseURL from config", |
|