From 9a19e842656bf82796b1e9c66778bd7d9662f8e9 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Mon, 18 May 2026 19:55:33 -0400 Subject: [PATCH] Migrate config agent tests to instance fixtures (#28213) --- packages/opencode/test/config/config.test.ts | 181 ++++++++----------- perf/test-suite.md | 1 + 2 files changed, 76 insertions(+), 106 deletions(-) diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts index 3abd62ba6d..ee55f939a3 100644 --- a/packages/opencode/test/config/config.test.ts +++ b/packages/opencode/test/config/config.test.ts @@ -602,118 +602,87 @@ it.instance("handles agent configuration", () => }), ) -test("treats agent variant as model-scoped setting (not provider option)", async () => { - await using tmp = await tmpdir({ - init: async (dir) => { - await writeConfig(dir, { - $schema: "https://opencode.ai/config.json", - agent: { - test_agent: { - model: "openai/gpt-5.2", - variant: "xhigh", - max_tokens: 123, - }, +it.instance("treats agent variant as model-scoped setting (not provider option)", () => + Effect.gen(function* () { + const test = yield* TestInstance + yield* writeConfigEffect(test.directory, { + $schema: "https://opencode.ai/config.json", + agent: { + test_agent: { + model: "openai/gpt-5.2", + variant: "xhigh", + max_tokens: 123, }, - }) - }, - }) + }, + }) + const config = yield* Config.Service.use((svc) => svc.get()) + const agent = config.agent?.["test_agent"] - await withTestInstance({ - directory: tmp.path, - fn: async (ctx) => { - const config = await load(ctx) - const agent = config.agent?.["test_agent"] + expect(agent?.variant).toBe("xhigh") + expect(agent?.options).toMatchObject({ + max_tokens: 123, + }) + expect(agent?.options).not.toHaveProperty("variant") + }), +) - expect(agent?.variant).toBe("xhigh") - expect(agent?.options).toMatchObject({ - max_tokens: 123, - }) - expect(agent?.options).not.toHaveProperty("variant") - }, - }) -}) - -test("handles command configuration", async () => { - await using tmp = await tmpdir({ - init: async (dir) => { - await writeConfig(dir, { - $schema: "https://opencode.ai/config.json", - command: { - test_command: { - template: "test template", - description: "test command", - agent: "test_agent", - }, +it.instance("handles command configuration", () => + Effect.gen(function* () { + const test = yield* TestInstance + yield* writeConfigEffect(test.directory, { + $schema: "https://opencode.ai/config.json", + command: { + test_command: { + template: "test template", + description: "test command", + agent: "test_agent", }, - }) - }, - }) - await withTestInstance({ - directory: tmp.path, - fn: async (ctx) => { - const config = await load(ctx) - expect(config.command?.["test_command"]).toEqual({ - template: "test template", - description: "test command", - agent: "test_agent", - }) - }, - }) -}) + }, + }) + const config = yield* Config.Service.use((svc) => svc.get()) + expect(config.command?.["test_command"]).toEqual({ + template: "test template", + description: "test command", + agent: "test_agent", + }) + }), +) -test("migrates autoshare to share field", async () => { - await using tmp = await tmpdir({ - init: async (dir) => { - await Filesystem.write( - path.join(dir, "opencode.json"), - JSON.stringify({ - $schema: "https://opencode.ai/config.json", - autoshare: true, - }), - ) - }, - }) - await withTestInstance({ - directory: tmp.path, - fn: async (ctx) => { - const config = await load(ctx) - expect(config.share).toBe("auto") - expect(config.autoshare).toBe(true) - }, - }) -}) +it.instance("migrates autoshare to share field", () => + Effect.gen(function* () { + const test = yield* TestInstance + yield* writeConfigEffect(test.directory, { + $schema: "https://opencode.ai/config.json", + autoshare: true, + }) + const config = yield* Config.Service.use((svc) => svc.get()) + expect(config.share).toBe("auto") + expect(config.autoshare).toBe(true) + }), +) -test("migrates mode field to agent field", async () => { - await using tmp = await tmpdir({ - init: async (dir) => { - await Filesystem.write( - path.join(dir, "opencode.json"), - JSON.stringify({ - $schema: "https://opencode.ai/config.json", - mode: { - test_mode: { - model: "test/model", - temperature: 0.5, - }, - }, - }), - ) - }, - }) - await withTestInstance({ - directory: tmp.path, - fn: async (ctx) => { - const config = await load(ctx) - expect(config.agent?.["test_mode"]).toEqual({ - model: "test/model", - temperature: 0.5, - mode: "primary", - options: {}, - permission: {}, - }) - }, - }) -}) +it.instance("migrates mode field to agent field", () => + Effect.gen(function* () { + const test = yield* TestInstance + yield* writeConfigEffect(test.directory, { + $schema: "https://opencode.ai/config.json", + mode: { + test_mode: { + model: "test/model", + temperature: 0.5, + }, + }, + }) + const config = yield* Config.Service.use((svc) => svc.get()) + expect(config.agent?.["test_mode"]).toEqual({ + model: "test/model", + temperature: 0.5, + mode: "primary", + options: {}, + permission: {}, + }) + }), +) test("loads config from .opencode directory", async () => { await using tmp = await tmpdir({ diff --git a/perf/test-suite.md b/perf/test-suite.md index e7420cd519..577d249cd6 100644 --- a/perf/test-suite.md +++ b/perf/test-suite.md @@ -73,6 +73,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/ | Provider env precedence and model lookup cases can use Effect-aware instance fixtures | Migrated four more provider lookup/default-model cases to `it.instance` | 6.12s | 6.36s | keep | Noisy 5-run median; kept as a small stacked cleanup slice but do not claim speedup from this migration. | | Simple config load cases can use Effect-aware instance fixtures | Migrated JSON, shell, formatter, and lsp config load cases to `it.instance` | 14.18s | 3.93s | keep | Three-run medians before/after; removes manual `tmpdir` + `withTestInstance` setup from the first simple config block. | | Config template, file include, and simple agent cases can use Effect-aware instance fixtures | Migrated JSONC, env/file substitution, invalid config, and agent config cases to `it.instance` | 1.87s | 1.90s | keep | Stacked on the first config slice; neutral timing but removes more manual `tmpdir` + instance plumbing. | +| Agent option, command, and legacy migration config cases can use Effect-aware instance fixtures | Migrated agent variant, command, autoshare, and mode migration cases to `it.instance` | 1.90s | 1.83s | keep | Stacked on the config template slice; small neutral-to-positive timing and less manual setup. | ## Profiling Results