summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorDax Raad <[email protected]>2025-12-14 21:23:45 -0500
committerDax Raad <[email protected]>2025-12-14 21:23:45 -0500
commite22af250760e99c3f4cc88f48ef430e60e43d0a7 (patch)
treef41783ace0f8070779a7c5ff352068a3904ba7fa /packages
parent622caae9c99bd182d62ea016fafbacd211e113d6 (diff)
downloadopencode-e22af250760e99c3f4cc88f48ef430e60e43d0a7.tar.gz
opencode-e22af250760e99c3f4cc88f48ef430e60e43d0a7.zip
ci: fix test failures in CI by pre-populating models cache
Tests were failing in CI because the models.json cache file doesn't exist and the data() macro fallback only works at build time, not runtime. The preload now pre-fetches models.json and disables the background refresh to prevent race conditions during test execution.
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/flag/flag.ts1
-rw-r--r--packages/opencode/src/provider/models.ts2
-rw-r--r--packages/opencode/test/preload.ts12
3 files changed, 15 insertions, 0 deletions
diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.ts
index ca1af6d84..d7a24708a 100644
--- a/packages/opencode/src/flag/flag.ts
+++ b/packages/opencode/src/flag/flag.ts
@@ -11,6 +11,7 @@ export namespace Flag {
export const OPENCODE_DISABLE_LSP_DOWNLOAD = truthy("OPENCODE_DISABLE_LSP_DOWNLOAD")
export const OPENCODE_ENABLE_EXPERIMENTAL_MODELS = truthy("OPENCODE_ENABLE_EXPERIMENTAL_MODELS")
export const OPENCODE_DISABLE_AUTOCOMPACT = truthy("OPENCODE_DISABLE_AUTOCOMPACT")
+ export const OPENCODE_DISABLE_MODELS_FETCH = truthy("OPENCODE_DISABLE_MODELS_FETCH")
export const OPENCODE_FAKE_VCS = process.env["OPENCODE_FAKE_VCS"]
export const OPENCODE_CLIENT = process.env["OPENCODE_CLIENT"] ?? "cli"
diff --git a/packages/opencode/src/provider/models.ts b/packages/opencode/src/provider/models.ts
index c523725ec..c58638d28 100644
--- a/packages/opencode/src/provider/models.ts
+++ b/packages/opencode/src/provider/models.ts
@@ -4,6 +4,7 @@ import path from "path"
import z from "zod"
import { data } from "./models-macro" with { type: "macro" }
import { Installation } from "../installation"
+import { Flag } from "../flag/flag"
export namespace ModelsDev {
const log = Log.create({ service: "models.dev" })
@@ -83,6 +84,7 @@ export namespace ModelsDev {
}
export async function refresh() {
+ if (Flag.OPENCODE_DISABLE_MODELS_FETCH) return
const file = Bun.file(filepath)
log.info("refreshing", {
file,
diff --git a/packages/opencode/test/preload.ts b/packages/opencode/test/preload.ts
index c2a294ab2..08316a23f 100644
--- a/packages/opencode/test/preload.ts
+++ b/packages/opencode/test/preload.ts
@@ -11,6 +11,18 @@ process.env["XDG_CACHE_HOME"] = path.join(dir, "cache")
process.env["XDG_CONFIG_HOME"] = path.join(dir, "config")
process.env["XDG_STATE_HOME"] = path.join(dir, "state")
+// Pre-fetch models.json so tests don't need the macro fallback
+// Also write the cache version file to prevent global/index.ts from clearing the cache
+const cacheDir = path.join(dir, "cache", "opencode")
+await fs.mkdir(cacheDir, { recursive: true })
+await fs.writeFile(path.join(cacheDir, "version"), "14")
+const response = await fetch("https://models.dev/api.json")
+if (response.ok) {
+ await fs.writeFile(path.join(cacheDir, "models.json"), await response.text())
+}
+// Disable models.dev refresh to avoid race conditions during tests
+process.env["OPENCODE_DISABLE_MODELS_FETCH"] = "true"
+
// Clear provider env vars to ensure clean test state
delete process.env["ANTHROPIC_API_KEY"]
delete process.env["OPENAI_API_KEY"]