Skip to content

Commit 4b7e42e

Browse files
committed
test(models): save/restore Flag mutations to keep them suite-local
Mutating Flag.OPENCODE_MODELS_PATH at module-load time leaked the change into every subsequent test file in the same bun process — Provider state init then read undefined, fell into the snapshot/fetch fallback, and on slower CI lanes timed out or returned empty providers (surfacing as the "no providers found" failure on Windows for the SDK no-reply parity test). Wrap both mutations in beforeAll/afterAll so they only apply while this suite runs.
1 parent c50d53f commit 4b7e42e

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

packages/opencode/test/provider/models.test.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expect, beforeEach, afterAll } from "bun:test"
1+
import { describe, expect, beforeAll, beforeEach, afterAll } from "bun:test"
22
import { Effect, Layer, Ref } from "effect"
33
import { HttpClient, HttpClientResponse } from "effect/unstable/http"
44
import { AppFileSystem } from "@opencode-ai/core/filesystem"
@@ -9,12 +9,21 @@ import { it } from "../lib/effect"
99
import { rm, writeFile, utimes, mkdir } from "fs/promises"
1010
import path from "path"
1111

12-
// test/preload.ts sets OPENCODE_MODELS_PATH to a static fixture and leaves
13-
// MODELS_FETCH enabled — both flags are captured at flag-module load time,
14-
// which is too early for env mutation to take effect. Mutate the resolved Flag
15-
// values directly; they're read inside Layer.effect when each test builds.
16-
Flag.OPENCODE_DISABLE_MODELS_FETCH = true
17-
Flag.OPENCODE_MODELS_PATH = undefined
12+
// test/preload.ts pins OPENCODE_MODELS_PATH to a fixture so other tests can
13+
// resolve providers without network. These tests need to drive the on-disk
14+
// cache themselves and silence the eager refresh fork. Save/restore around
15+
// the suite — never leak the mutation to subsequent test files in the same
16+
// bun process.
17+
const ORIGINAL_MODELS_PATH = Flag.OPENCODE_MODELS_PATH
18+
const ORIGINAL_DISABLE_FETCH = Flag.OPENCODE_DISABLE_MODELS_FETCH
19+
beforeAll(() => {
20+
Flag.OPENCODE_MODELS_PATH = undefined
21+
Flag.OPENCODE_DISABLE_MODELS_FETCH = true
22+
})
23+
afterAll(() => {
24+
Flag.OPENCODE_MODELS_PATH = ORIGINAL_MODELS_PATH
25+
Flag.OPENCODE_DISABLE_MODELS_FETCH = ORIGINAL_DISABLE_FETCH
26+
})
1827

1928
const cacheFile = path.join(Global.Path.cache, "models.json")
2029

0 commit comments

Comments
 (0)