Skip to content

Commit ec0bed6

Browse files
committed
fix: respect dynamic config content override
1 parent 1f76d6c commit ec0bed6

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/opencode/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export const layer = Layer.effect(
411411
let result: Info = {}
412412
// Seed the default global config with the schema for editor completion, but avoid writing when the user
413413
// explicitly routes config through env-provided paths or content.
414-
if (!Flag.OPENCODE_CONFIG && !Flag.OPENCODE_CONFIG_DIR && !Flag.OPENCODE_CONFIG_CONTENT) {
414+
if (!Flag.OPENCODE_CONFIG && !Flag.OPENCODE_CONFIG_DIR && !process.env.OPENCODE_CONFIG_CONTENT) {
415415
const file = globalConfigFile()
416416
if (!existsSync(file)) {
417417
yield* fs

packages/opencode/test/config/config.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,32 @@ test("does not create global config when OPENCODE_CONFIG_DIR is set", async () =
189189
}
190190
})
191191

192+
test("does not create global config when OPENCODE_CONFIG_CONTENT is set", async () => {
193+
await using tmp = await tmpdir()
194+
const prevConfig = Global.Path.config
195+
const prevEnv = process.env.OPENCODE_CONFIG_CONTENT
196+
;(Global.Path as { config: string }).config = tmp.path
197+
process.env.OPENCODE_CONFIG_CONTENT = JSON.stringify({ model: "test/model" })
198+
await clear(true)
199+
200+
try {
201+
await WithInstance.provide({
202+
directory: tmp.path,
203+
fn: async () => {
204+
const config = await load()
205+
expect(config.model).toBe("test/model")
206+
},
207+
})
208+
209+
expect(await Filesystem.exists(path.join(tmp.path, "opencode.jsonc"))).toBe(false)
210+
} finally {
211+
;(Global.Path as { config: string }).config = prevConfig
212+
if (prevEnv === undefined) delete process.env.OPENCODE_CONFIG_CONTENT
213+
else process.env.OPENCODE_CONFIG_CONTENT = prevEnv
214+
await clear(true)
215+
}
216+
})
217+
192218
test("loads JSON config file", async () => {
193219
await using tmp = await tmpdir({
194220
init: async (dir) => {

0 commit comments

Comments
 (0)