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 config tests to instance fixtures · Integralist/opencode@762850d

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
+90-145Lines changed: 90 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ function rememberEnv(k: string) {
2929
if (!originalEnv.has(k)) originalEnv.set(k, process.env[k])
3030
}
3131

32+
const setProcessEnv = (k: string, v: string) =>
33+
Effect.sync(() => {
34+
rememberEnv(k)
35+
process.env[k] = v
36+
})
37+
3238
const set = (ctx: InstanceContext, k: string, v: string) => {
3339
rememberEnv(k)
3440
process.env[k] = v
@@ -128,160 +134,99 @@ const alphaProviderConfig = {
128134
},
129135
}
130136

131-
test("provider loaded from env variable", async () => {
132-
await using tmp = await tmpdir({
133-
init: async (dir) => {
134-
await Bun.write(
135-
path.join(dir, "opencode.json"),
136-
JSON.stringify({
137-
$schema: "https://opencode.ai/config.json",
138-
}),
139-
)
140-
},
141-
})
142-
await withTestInstance({
143-
directory: tmp.path,
144-
fn: async (ctx) => {
145-
await set(ctx, "ANTHROPIC_API_KEY", "test-api-key")
146-
const providers = await list(ctx)
147-
expect(providers[ProviderID.anthropic]).toBeDefined()
148-
// Provider should retain its connection source even if custom loaders
149-
// merge additional options.
150-
expect(providers[ProviderID.anthropic].source).toBe("env")
151-
expect(providers[ProviderID.anthropic].options.headers["anthropic-beta"]).toBeDefined()
152-
},
153-
})
154-
})
137+
it.instance("provider loaded from env variable", () =>
138+
Effect.gen(function* () {
139+
yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key")
140+
const providers = yield* Provider.Service.use((provider) => provider.list())
141+
expect(providers[ProviderID.anthropic]).toBeDefined()
142+
// Provider should retain its connection source even if custom loaders
143+
// merge additional options.
144+
expect(providers[ProviderID.anthropic].source).toBe("env")
145+
expect(providers[ProviderID.anthropic].options.headers["anthropic-beta"]).toBeDefined()
146+
}),
147+
)
155148

156-
test("provider loaded from config with apiKey option", async () => {
157-
await using tmp = await tmpdir({
158-
init: async (dir) => {
159-
await Bun.write(
160-
path.join(dir, "opencode.json"),
161-
JSON.stringify({
162-
$schema: "https://opencode.ai/config.json",
163-
provider: {
164-
anthropic: {
165-
options: {
166-
apiKey: "config-api-key",
167-
},
168-
},
149+
it.instance(
150+
"provider loaded from config with apiKey option",
151+
Effect.gen(function* () {
152+
const providers = yield* Provider.Service.use((provider) => provider.list())
153+
expect(providers[ProviderID.anthropic]).toBeDefined()
154+
}),
155+
{
156+
config: {
157+
provider: {
158+
anthropic: {
159+
options: {
160+
apiKey: "config-api-key",
169161
},
170-
}),
171-
)
172-
},
173-
})
174-
await withTestInstance({
175-
directory: tmp.path,
176-
fn: async (ctx) => {
177-
const providers = await list(ctx)
178-
expect(providers[ProviderID.anthropic]).toBeDefined()
162+
},
163+
},
179164
},
180-
})
181-
})
165+
},
166+
)
182167

183-
test("disabled_providers excludes provider", async () => {
184-
await using tmp = await tmpdir({
185-
init: async (dir) => {
186-
await Bun.write(
187-
path.join(dir, "opencode.json"),
188-
JSON.stringify({
189-
$schema: "https://opencode.ai/config.json",
190-
disabled_providers: ["anthropic"],
191-
}),
192-
)
193-
},
194-
})
195-
await withTestInstance({
196-
directory: tmp.path,
197-
fn: async (ctx) => {
198-
await set(ctx, "ANTHROPIC_API_KEY", "test-api-key")
199-
const providers = await list(ctx)
200-
expect(providers[ProviderID.anthropic]).toBeUndefined()
201-
},
202-
})
203-
})
168+
it.instance(
169+
"disabled_providers excludes provider",
170+
Effect.gen(function* () {
171+
yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key")
172+
const providers = yield* Provider.Service.use((provider) => provider.list())
173+
expect(providers[ProviderID.anthropic]).toBeUndefined()
174+
}),
175+
{ config: { disabled_providers: ["anthropic"] } },
176+
)
204177

205-
test("enabled_providers restricts to only listed providers", async () => {
206-
await using tmp = await tmpdir({
207-
init: async (dir) => {
208-
await Bun.write(
209-
path.join(dir, "opencode.json"),
210-
JSON.stringify({
211-
$schema: "https://opencode.ai/config.json",
212-
enabled_providers: ["anthropic"],
213-
}),
214-
)
215-
},
216-
})
217-
await withTestInstance({
218-
directory: tmp.path,
219-
fn: async (ctx) => {
220-
await set(ctx, "ANTHROPIC_API_KEY", "test-api-key")
221-
await set(ctx, "OPENAI_API_KEY", "test-openai-key")
222-
const providers = await list(ctx)
223-
expect(providers[ProviderID.anthropic]).toBeDefined()
224-
expect(providers[ProviderID.openai]).toBeUndefined()
225-
},
226-
})
227-
})
178+
it.instance(
179+
"enabled_providers restricts to only listed providers",
180+
Effect.gen(function* () {
181+
yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key")
182+
yield* setProcessEnv("OPENAI_API_KEY", "test-openai-key")
183+
const providers = yield* Provider.Service.use((provider) => provider.list())
184+
expect(providers[ProviderID.anthropic]).toBeDefined()
185+
expect(providers[ProviderID.openai]).toBeUndefined()
186+
}),
187+
{ config: { enabled_providers: ["anthropic"] } },
188+
)
228189

229-
test("model whitelist filters models for provider", async () => {
230-
await using tmp = await tmpdir({
231-
init: async (dir) => {
232-
await Bun.write(
233-
path.join(dir, "opencode.json"),
234-
JSON.stringify({
235-
$schema: "https://opencode.ai/config.json",
236-
provider: {
237-
anthropic: {
238-
whitelist: ["claude-sonnet-4-20250514"],
239-
},
240-
},
241-
}),
242-
)
243-
},
244-
})
245-
await withTestInstance({
246-
directory: tmp.path,
247-
fn: async (ctx) => {
248-
await set(ctx, "ANTHROPIC_API_KEY", "test-api-key")
249-
const providers = await list(ctx)
250-
expect(providers[ProviderID.anthropic]).toBeDefined()
251-
const models = Object.keys(providers[ProviderID.anthropic].models)
252-
expect(models).toContain("claude-sonnet-4-20250514")
253-
expect(models.length).toBe(1)
190+
it.instance(
191+
"model whitelist filters models for provider",
192+
Effect.gen(function* () {
193+
yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key")
194+
const providers = yield* Provider.Service.use((provider) => provider.list())
195+
expect(providers[ProviderID.anthropic]).toBeDefined()
196+
const models = Object.keys(providers[ProviderID.anthropic].models)
197+
expect(models).toContain("claude-sonnet-4-20250514")
198+
expect(models.length).toBe(1)
199+
}),
200+
{
201+
config: {
202+
provider: {
203+
anthropic: {
204+
whitelist: ["claude-sonnet-4-20250514"],
205+
},
206+
},
254207
},
255-
})
256-
})
208+
},
209+
)
257210

258-
test("model blacklist excludes specific models", async () => {
259-
await using tmp = await tmpdir({
260-
init: async (dir) => {
261-
await Bun.write(
262-
path.join(dir, "opencode.json"),
263-
JSON.stringify({
264-
$schema: "https://opencode.ai/config.json",
265-
provider: {
266-
anthropic: {
267-
blacklist: ["claude-sonnet-4-20250514"],
268-
},
269-
},
270-
}),
271-
)
272-
},
273-
})
274-
await withTestInstance({
275-
directory: tmp.path,
276-
fn: async (ctx) => {
277-
await set(ctx, "ANTHROPIC_API_KEY", "test-api-key")
278-
const providers = await list(ctx)
279-
expect(providers[ProviderID.anthropic]).toBeDefined()
280-
const models = Object.keys(providers[ProviderID.anthropic].models)
281-
expect(models).not.toContain("claude-sonnet-4-20250514")
211+
it.instance(
212+
"model blacklist excludes specific models",
213+
Effect.gen(function* () {
214+
yield* setProcessEnv("ANTHROPIC_API_KEY", "test-api-key")
215+
const providers = yield* Provider.Service.use((provider) => provider.list())
216+
expect(providers[ProviderID.anthropic]).toBeDefined()
217+
const models = Object.keys(providers[ProviderID.anthropic].models)
218+
expect(models).not.toContain("claude-sonnet-4-20250514")
219+
}),
220+
{
221+
config: {
222+
provider: {
223+
anthropic: {
224+
blacklist: ["claude-sonnet-4-20250514"],
225+
},
226+
},
282227
},
283-
})
284-
})
228+
},
229+
)
285230

286231
test("custom model alias via config", async () => {
287232
await using tmp = await tmpdir({
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
@@ -68,6 +68,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/
6868
| Session processor effect tests do not require repository state | Removed git setup from all processor-effect temp server fixtures | 12.500s | 9.230s | keep | Two targeted reruns passed after the change: 9.61s, 9.23s. |
6969
| HTTP listen PTY ticket tests restart the same listener topology twice | Folded directory-scoped ticket regression into the broader unsafe-ticket test | 7.051s | 6.170s | keep | Two targeted reruns passed after the change: 6.76s, 6.17s; still covers mint failure and successful same-directory upgrade. |
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`. |
71+
| 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. |
7172

7273
## Profiling Results
7374

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.