From 4be7b3592e5d9037ded22179e212ba44460e95f6 Mon Sep 17 00:00:00 2001 From: liyiwei <979621500@qq.com> Date: Thu, 2 Apr 2026 16:09:14 +0800 Subject: [PATCH] fix: Config.update writes to correct file and clears cache - Change config file path from config.json to opencode.json to match the auto-loader which reads from .opencode/opencode.json - Add invalidate() call to clear config cache after writing - Add integration test for patch then get config flow --- packages/opencode/src/config/config.ts | 3 ++- packages/opencode/test/config/config.test.ts | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts index 3cae1af4bdb2..38f009b0af9d 100644 --- a/packages/opencode/src/config/config.ts +++ b/packages/opencode/src/config/config.ts @@ -1422,11 +1422,12 @@ export namespace Config { const update = Effect.fn("Config.update")(function* (config: Info) { const dir = yield* InstanceState.directory - const file = path.join(dir, "config.json") + const file = path.join(dir, "opencode.json") const existing = yield* loadFile(file) yield* fs .writeFileString(file, JSON.stringify(mergeDeep(writable(existing), writable(config)), null, 2)) .pipe(Effect.orDie) + yield* invalidate() yield* Effect.promise(() => Instance.dispose()) }) diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index be2a6b11be51..4b79b8c2d192 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -710,12 +710,25 @@ test("updates config and writes to file", async () => { const newConfig = { model: "updated/model" } await Config.update(newConfig as any) - const writtenConfig = await Filesystem.readJson(path.join(tmp.path, "config.json")) + const writtenConfig = await Filesystem.readJson(path.join(tmp.path, "opencode.json")) expect(writtenConfig.model).toBe("updated/model") }, }) }) +test("patch then get returns updated config", async () => { + await using tmp = await tmpdir() + await Instance.provide({ + directory: tmp.path, + fn: async () => { + await Config.update({ agent: { testAgent: { model: "test/model" } } } as any) + + const config = await Config.get() + expect(config.agent?.testAgent?.model).toBe("test/model") + }, + }) +}) + test("gets config directories", async () => { await using tmp = await tmpdir() await Instance.provide({