@@ -68,13 +68,6 @@ const load = (ctx: InstanceContext) => |
68 | 68 | Effect.runPromise( |
69 | 69 | Config.Service.use((svc) => provideCurrentInstance(svc.get(), ctx)).pipe(Effect.scoped, Effect.provide(layer)), |
70 | 70 | ) |
71 | | -const save = (config: Config.Info, ctx: InstanceContext) => |
72 | | - Effect.runPromise( |
73 | | - Config.Service.use((svc) => provideCurrentInstance(svc.update(config), ctx)).pipe( |
74 | | - Effect.scoped, |
75 | | - Effect.provide(layer), |
76 | | - ), |
77 | | - ) |
78 | 71 | const saveGlobal = (config: Config.Info) => |
79 | 72 | Effect.runPromise( |
80 | 73 | Config.Service.use((svc) => svc.updateGlobal(config)).pipe( |
@@ -240,29 +233,23 @@ it.instance( |
240 | 233 | { config: { shell: "bash" } }, |
241 | 234 | ) |
242 | 235 |
|
243 | | -test("updates config and preserves empty shell sentinel", async () => { |
244 | | - await using tmp = await tmpdir({ |
245 | | - init: async (dir) => { |
246 | | - await writeConfig( |
247 | | - dir, |
248 | | - { |
249 | | - $schema: "https://opencode.ai/config.json", |
250 | | - shell: "bash", |
251 | | - }, |
252 | | - "config.json", |
253 | | - ) |
254 | | - }, |
255 | | - }) |
256 | | - await withTestInstance({ |
257 | | - directory: tmp.path, |
258 | | - fn: async (ctx) => { |
259 | | - await save({ shell: "" }, ctx) |
| 236 | +it.instance("updates config and preserves empty shell sentinel", () => |
| 237 | + Effect.gen(function* () { |
| 238 | + const test = yield* TestInstance |
| 239 | + yield* writeConfigEffect( |
| 240 | + test.directory, |
| 241 | + { $schema: "https://opencode.ai/config.json", shell: "bash" }, |
| 242 | + "config.json", |
| 243 | + ) |
260 | 244 |
|
261 | | - const writtenConfig = await Filesystem.readJson<{ shell?: string }>(path.join(tmp.path, "config.json")) |
262 | | - expect(writtenConfig.shell).toBe("") |
263 | | - }, |
264 | | - }) |
265 | | -}) |
| 245 | + yield* Config.Service.use((svc) => svc.update(ConfigParse.schema(Config.Info, { shell: "" }, "test:config"))) |
| 246 | + |
| 247 | + const writtenConfig = yield* Effect.promise(() => |
| 248 | + Filesystem.readJson<{ shell?: string }>(path.join(test.directory, "config.json")), |
| 249 | + ) |
| 250 | + expect(writtenConfig.shell).toBe("") |
| 251 | + }), |
| 252 | +) |
266 | 253 |
|
267 | 254 | test("updates global config and omits empty shell key in json", async () => { |
268 | 255 | await using tmp = await tmpdir({ |
@@ -884,30 +871,26 @@ Nested command template`, |
884 | 871 | }) |
885 | 872 | }) |
886 | 873 |
|
887 | | -test("updates config and writes to file", async () => { |
888 | | - await using tmp = await tmpdir() |
889 | | - await withTestInstance({ |
890 | | - directory: tmp.path, |
891 | | - fn: async (ctx) => { |
892 | | - const newConfig = { model: "updated/model" } |
893 | | - await save(newConfig as any, ctx) |
| 874 | +it.instance("updates config and writes to file", () => |
| 875 | + Effect.gen(function* () { |
| 876 | + const test = yield* TestInstance |
| 877 | + yield* Config.Service.use((svc) => |
| 878 | + svc.update(ConfigParse.schema(Config.Info, { model: "updated/model" }, "test:config")), |
| 879 | + ) |
894 | 880 |
|
895 | | - const writtenConfig = await Filesystem.readJson<{ model: string }>(path.join(tmp.path, "config.json")) |
896 | | - expect(writtenConfig.model).toBe("updated/model") |
897 | | - }, |
898 | | - }) |
899 | | -}) |
| 881 | + const writtenConfig = yield* Effect.promise(() => |
| 882 | + Filesystem.readJson<{ model: string }>(path.join(test.directory, "config.json")), |
| 883 | + ) |
| 884 | + expect(writtenConfig.model).toBe("updated/model") |
| 885 | + }), |
| 886 | +) |
900 | 887 |
|
901 | | -test("gets config directories", async () => { |
902 | | - await using tmp = await tmpdir() |
903 | | - await withTestInstance({ |
904 | | - directory: tmp.path, |
905 | | - fn: async (ctx) => { |
906 | | - const dirs = await listDirs(ctx) |
907 | | - expect(dirs.length).toBeGreaterThanOrEqual(1) |
908 | | - }, |
909 | | - }) |
910 | | -}) |
| 888 | +it.instance("gets config directories", () => |
| 889 | + Effect.gen(function* () { |
| 890 | + const dirs = yield* Config.Service.use((svc) => svc.directories()) |
| 891 | + expect(dirs.length).toBeGreaterThanOrEqual(1) |
| 892 | + }), |
| 893 | +) |
911 | 894 |
|
912 | 895 | test("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR", async () => { |
913 | 896 | if (process.platform === "win32") return |
|