Skip to content

Commit 9a19e84

Browse files
authored
Migrate config agent tests to instance fixtures (anomalyco#28213)
1 parent 338666d commit 9a19e84

2 files changed

Lines changed: 76 additions & 106 deletions

File tree

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

Lines changed: 75 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -602,118 +602,87 @@ it.instance("handles agent configuration", () =>
602602
}),
603603
)
604604

605-
test("treats agent variant as model-scoped setting (not provider option)", async () => {
606-
await using tmp = await tmpdir({
607-
init: async (dir) => {
608-
await writeConfig(dir, {
609-
$schema: "https://opencode.ai/config.json",
610-
agent: {
611-
test_agent: {
612-
model: "openai/gpt-5.2",
613-
variant: "xhigh",
614-
max_tokens: 123,
615-
},
605+
it.instance("treats agent variant as model-scoped setting (not provider option)", () =>
606+
Effect.gen(function* () {
607+
const test = yield* TestInstance
608+
yield* writeConfigEffect(test.directory, {
609+
$schema: "https://opencode.ai/config.json",
610+
agent: {
611+
test_agent: {
612+
model: "openai/gpt-5.2",
613+
variant: "xhigh",
614+
max_tokens: 123,
616615
},
617-
})
618-
},
619-
})
620-
621-
await withTestInstance({
622-
directory: tmp.path,
623-
fn: async (ctx) => {
624-
const config = await load(ctx)
625-
const agent = config.agent?.["test_agent"]
616+
},
617+
})
618+
const config = yield* Config.Service.use((svc) => svc.get())
619+
const agent = config.agent?.["test_agent"]
626620

627-
expect(agent?.variant).toBe("xhigh")
628-
expect(agent?.options).toMatchObject({
629-
max_tokens: 123,
630-
})
631-
expect(agent?.options).not.toHaveProperty("variant")
632-
},
633-
})
634-
})
621+
expect(agent?.variant).toBe("xhigh")
622+
expect(agent?.options).toMatchObject({
623+
max_tokens: 123,
624+
})
625+
expect(agent?.options).not.toHaveProperty("variant")
626+
}),
627+
)
635628

636-
test("handles command configuration", async () => {
637-
await using tmp = await tmpdir({
638-
init: async (dir) => {
639-
await writeConfig(dir, {
640-
$schema: "https://opencode.ai/config.json",
641-
command: {
642-
test_command: {
643-
template: "test template",
644-
description: "test command",
645-
agent: "test_agent",
646-
},
629+
it.instance("handles command configuration", () =>
630+
Effect.gen(function* () {
631+
const test = yield* TestInstance
632+
yield* writeConfigEffect(test.directory, {
633+
$schema: "https://opencode.ai/config.json",
634+
command: {
635+
test_command: {
636+
template: "test template",
637+
description: "test command",
638+
agent: "test_agent",
647639
},
648-
})
649-
},
650-
})
651-
await withTestInstance({
652-
directory: tmp.path,
653-
fn: async (ctx) => {
654-
const config = await load(ctx)
655-
expect(config.command?.["test_command"]).toEqual({
656-
template: "test template",
657-
description: "test command",
658-
agent: "test_agent",
659-
})
660-
},
661-
})
662-
})
640+
},
641+
})
642+
const config = yield* Config.Service.use((svc) => svc.get())
643+
expect(config.command?.["test_command"]).toEqual({
644+
template: "test template",
645+
description: "test command",
646+
agent: "test_agent",
647+
})
648+
}),
649+
)
663650

664-
test("migrates autoshare to share field", async () => {
665-
await using tmp = await tmpdir({
666-
init: async (dir) => {
667-
await Filesystem.write(
668-
path.join(dir, "opencode.json"),
669-
JSON.stringify({
670-
$schema: "https://opencode.ai/config.json",
671-
autoshare: true,
672-
}),
673-
)
674-
},
675-
})
676-
await withTestInstance({
677-
directory: tmp.path,
678-
fn: async (ctx) => {
679-
const config = await load(ctx)
680-
expect(config.share).toBe("auto")
681-
expect(config.autoshare).toBe(true)
682-
},
683-
})
684-
})
651+
it.instance("migrates autoshare to share field", () =>
652+
Effect.gen(function* () {
653+
const test = yield* TestInstance
654+
yield* writeConfigEffect(test.directory, {
655+
$schema: "https://opencode.ai/config.json",
656+
autoshare: true,
657+
})
658+
const config = yield* Config.Service.use((svc) => svc.get())
659+
expect(config.share).toBe("auto")
660+
expect(config.autoshare).toBe(true)
661+
}),
662+
)
685663

686-
test("migrates mode field to agent field", async () => {
687-
await using tmp = await tmpdir({
688-
init: async (dir) => {
689-
await Filesystem.write(
690-
path.join(dir, "opencode.json"),
691-
JSON.stringify({
692-
$schema: "https://opencode.ai/config.json",
693-
mode: {
694-
test_mode: {
695-
model: "test/model",
696-
temperature: 0.5,
697-
},
698-
},
699-
}),
700-
)
701-
},
702-
})
703-
await withTestInstance({
704-
directory: tmp.path,
705-
fn: async (ctx) => {
706-
const config = await load(ctx)
707-
expect(config.agent?.["test_mode"]).toEqual({
708-
model: "test/model",
709-
temperature: 0.5,
710-
mode: "primary",
711-
options: {},
712-
permission: {},
713-
})
714-
},
715-
})
716-
})
664+
it.instance("migrates mode field to agent field", () =>
665+
Effect.gen(function* () {
666+
const test = yield* TestInstance
667+
yield* writeConfigEffect(test.directory, {
668+
$schema: "https://opencode.ai/config.json",
669+
mode: {
670+
test_mode: {
671+
model: "test/model",
672+
temperature: 0.5,
673+
},
674+
},
675+
})
676+
const config = yield* Config.Service.use((svc) => svc.get())
677+
expect(config.agent?.["test_mode"]).toEqual({
678+
model: "test/model",
679+
temperature: 0.5,
680+
mode: "primary",
681+
options: {},
682+
permission: {},
683+
})
684+
}),
685+
)
717686

718687
test("loads config from .opencode directory", async () => {
719688
await using tmp = await tmpdir({

perf/test-suite.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/
7373
| 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. |
7474
| 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. |
7575
| 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. |
76+
| 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. |
7677

7778
## Profiling Results
7879

0 commit comments

Comments
 (0)