Skip to content

Commit c032e82

Browse files
authored
Migrate config update tests to instance fixtures (anomalyco#28266)
1 parent 6f160bb commit c032e82

2 files changed

Lines changed: 58 additions & 74 deletions

File tree

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

Lines changed: 34 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,6 @@ const load = (ctx: InstanceContext) =>
6868
Effect.runPromise(
6969
Config.Service.use((svc) => provideCurrentInstance(svc.get(), ctx)).pipe(Effect.scoped, Effect.provide(layer)),
7070
)
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-
)
7871
const saveGlobal = (config: Config.Info) =>
7972
Effect.runPromise(
8073
Config.Service.use((svc) => svc.updateGlobal(config)).pipe(
@@ -240,29 +233,23 @@ it.instance(
240233
{ config: { shell: "bash" } },
241234
)
242235

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+
)
260244

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+
)
266253

267254
test("updates global config and omits empty shell key in json", async () => {
268255
await using tmp = await tmpdir({
@@ -884,30 +871,26 @@ Nested command template`,
884871
})
885872
})
886873

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+
)
894880

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+
)
900887

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+
)
911894

912895
test("does not try to install dependencies in read-only OPENCODE_CONFIG_DIR", async () => {
913896
if (process.platform === "win32") return

0 commit comments

Comments
 (0)