GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Migrate provider lookup tests to instance fixtures · sujee/opencode@88681d3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/test/provider
    • provider.test.ts
  • perf
    • test-suite.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/test/provider/provider.test.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/test/provider/provider.test.ts
+51-104Lines changed: 51 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ async function getModel(providerID: ProviderID, modelID: ModelID, ctx: InstanceC
8787
return run(ctx, (provider) => provider.getModel(providerID, modelID))
8888
}
8989

90-
async function getLanguage(model: Provider.Model, ctx: InstanceContext) {
91-
return run(ctx, (provider) => provider.getLanguage(model))
92-
}
93-
9490
async function closest(providerID: ProviderID, query: string[], ctx: InstanceContext) {
9591
return run(ctx, (provider) => provider.closest(providerID, query))
9692
}
@@ -99,10 +95,6 @@ async function getSmallModel(providerID: ProviderID, ctx: InstanceContext) {
9995
return run(ctx, (provider) => provider.getSmallModel(providerID))
10096
}
10197

102-
async function defaultModel(ctx: InstanceContext) {
103-
return run(ctx, (provider) => provider.defaultModel())
104-
}
105-
10698
function paid(providers: Awaited<ReturnType<typeof list>>) {
10799
const item = providers[ProviderID.make("opencode")]
108100
expect(item).toBeDefined()
@@ -361,62 +353,42 @@ it.instance(
361353
},
362354
)
363355

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,
378373
},
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+
},
392376
},
393-
})
394-
})
377+
},
378+
)
395379

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+
)
420392

421393
test("getModel throws ModelNotFoundError for invalid model", async () => {
422394
await using tmp = await tmpdir({
@@ -469,50 +441,25 @@ test("parseModel handles model IDs with slashes", () => {
469441
expect(String(result.modelID)).toBe("anthropic/claude-3-opus")
470442
})
471443

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+
)
493452

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+
)
516463

517464
it.instance(
518465
"provider with baseURL from config",
Collapse file

‎perf/test-suite.md‎

Copy file name to clipboardExpand all lines: perf/test-suite.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/
7070
| File watcher readiness can write before async native subscriptions are active | Retried short readiness writes and accepted symlink-realpath HEAD events | failed | 4.62s | keep | Three sequential focused watcher runs passed: 4.62s, 4.57s, 4.64s; full suite no longer failed in `watcher.test.ts`. |
7171
| First provider config/env/filtering block can use Effect-aware instance fixtures | Migrated six `tmpdir` + `withTestInstance` cases to `it.instance` | 6.06s | 6.07s | keep | Neutral timing, but removes manual config file writes and instance plumbing; use as the pattern for later provider slices. |
7272
| Custom provider/model config cases can use Effect-aware instance fixtures | Migrated three more config-heavy provider cases to `it.instance` | 6.07s | 6.12s | keep | Neutral timing within noise, but continues removing manual config file writes on top of the first provider fixture PR. |
73+
| Provider env precedence and model lookup cases can use Effect-aware instance fixtures | Migrated four more provider lookup/default-model cases to `it.instance` | 6.12s | 6.36s | keep | Noisy 5-run median; kept as a small stacked cleanup slice but do not claim speedup from this migration. |
7374

7475
## Profiling Results
7576

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.