Skip to content

Commit d9d43d8

Browse files
authored
test: migrate plugin config fixtures
1 parent bcc69f0 commit d9d43d8

2 files changed

Lines changed: 47 additions & 69 deletions

File tree

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

Lines changed: 46 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -925,49 +925,35 @@ test("installs dependencies in writable OPENCODE_CONFIG_DIR", async () => {
925925
// core Npm.Service (via EffectFlock). Those behaviors are tested in the core
926926
// package's npm tests, not here.
927927

928-
test("resolves scoped npm plugins in config", async () => {
929-
await using tmp = await tmpdir({
930-
init: async (dir) => {
931-
const pluginDir = path.join(dir, "node_modules", "@scope", "plugin")
932-
await fs.mkdir(pluginDir, { recursive: true })
933-
934-
await Filesystem.write(
935-
path.join(dir, "package.json"),
936-
JSON.stringify({ name: "config-fixture", version: "1.0.0", type: "module" }, null, 2),
937-
)
938-
939-
await Filesystem.write(
940-
path.join(pluginDir, "package.json"),
941-
JSON.stringify(
942-
{
943-
name: "@scope/plugin",
944-
version: "1.0.0",
945-
type: "module",
946-
main: "./index.js",
947-
},
948-
null,
949-
2,
950-
),
951-
)
952-
953-
await Filesystem.write(path.join(pluginDir, "index.js"), "export default {}\n")
954-
955-
await Filesystem.write(
956-
path.join(dir, "opencode.json"),
957-
JSON.stringify({ $schema: "https://opencode.ai/config.json", plugin: ["@scope/plugin"] }, null, 2),
958-
)
959-
},
960-
})
928+
it.instance("resolves scoped npm plugins in config", () =>
929+
Effect.gen(function* () {
930+
const test = yield* TestInstance
931+
const pluginDir = path.join(test.directory, "node_modules", "@scope", "plugin")
932+
yield* mkdirEffect(pluginDir)
933+
yield* writeTextEffect(
934+
path.join(test.directory, "package.json"),
935+
JSON.stringify({ name: "config-fixture", version: "1.0.0", type: "module" }, null, 2),
936+
)
937+
yield* writeTextEffect(
938+
path.join(pluginDir, "package.json"),
939+
JSON.stringify(
940+
{
941+
name: "@scope/plugin",
942+
version: "1.0.0",
943+
type: "module",
944+
main: "./index.js",
945+
},
946+
null,
947+
2,
948+
),
949+
)
950+
yield* writeTextEffect(path.join(pluginDir, "index.js"), "export default {}\n")
951+
yield* writeConfigEffect(test.directory, { plugin: ["@scope/plugin"] })
961952

962-
await provideTestInstance({
963-
directory: tmp.path,
964-
fn: async (ctx) => {
965-
const config = await load(ctx)
966-
const pluginEntries = config.plugin ?? []
967-
expect(pluginEntries).toContain("@scope/plugin")
968-
},
969-
})
970-
})
953+
const config = yield* Config.Service.use((svc) => svc.get())
954+
expect(config.plugin ?? []).toContain("@scope/plugin")
955+
}),
956+
)
971957

972958
test("merges plugin arrays from global and local configs", async () => {
973959
await using tmp = await tmpdir({
@@ -1015,37 +1001,28 @@ test("merges plugin arrays from global and local configs", async () => {
10151001
})
10161002
})
10171003

1018-
test("does not error when only custom agent is a subagent", async () => {
1019-
await using tmp = await tmpdir({
1020-
init: async (dir) => {
1021-
const opencodeDir = path.join(dir, ".opencode")
1022-
await fs.mkdir(opencodeDir, { recursive: true })
1023-
const agentDir = path.join(opencodeDir, "agent")
1024-
await fs.mkdir(agentDir, { recursive: true })
1025-
1026-
await Filesystem.write(
1027-
path.join(agentDir, "helper.md"),
1028-
`---
1004+
it.instance("does not error when only custom agent is a subagent", () =>
1005+
Effect.gen(function* () {
1006+
const test = yield* TestInstance
1007+
yield* mkdirEffect(path.join(test.directory, ".opencode", "agent"))
1008+
yield* writeTextEffect(
1009+
path.join(test.directory, ".opencode", "agent", "helper.md"),
1010+
`---
10291011
model: test/model
10301012
mode: subagent
10311013
---
10321014
Helper subagent prompt`,
1033-
)
1034-
},
1035-
})
1036-
await withTestInstance({
1037-
directory: tmp.path,
1038-
fn: async (ctx) => {
1039-
const config = await load(ctx)
1040-
expect(config.agent?.["helper"]).toMatchObject({
1041-
name: "helper",
1042-
model: "test/model",
1043-
mode: "subagent",
1044-
prompt: "Helper subagent prompt",
1045-
})
1046-
},
1047-
})
1048-
})
1015+
)
1016+
1017+
const config = yield* Config.Service.use((svc) => svc.get())
1018+
expect(config.agent?.["helper"]).toMatchObject({
1019+
name: "helper",
1020+
model: "test/model",
1021+
mode: "subagent",
1022+
prompt: "Helper subagent prompt",
1023+
})
1024+
}),
1025+
)
10491026

10501027
test("merges instructions arrays from global and local configs", async () => {
10511028
await using tmp = await tmpdir({

perf/test-suite.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/
7979
| Legacy tools and permission-order config cases can use Effect-aware instance fixtures | Migrated legacy `tools` migration and permission order cases to `it.instance` | 1.87s | 1.87s | keep | Neutral timing; removes more manual temp-instance plumbing from legacy config migration coverage. |
8080
| Remaining simple config load cases can use Effect-aware instance fixtures | Migrated default config load and legacy TUI-key cases to `it.instance` | 7.78s | 6.39s | keep | Single baseline before edit; after median from three sequential reruns (5.76, 6.39, 6.53). Keep as cleanup with cautious timing. |
8181
| Managed settings config cases can use Effect-aware instance fixtures | Migrated managed override and missing-managed-file cases to `it.instance` | 2.40s | 1.76s | keep | Single baseline before edit; after median from three sequential reruns (1.75, 1.76, 1.80). |
82+
| Local plugin and subagent config fixtures can use Effect-aware instance fixtures | Migrated scoped npm plugin and custom subagent markdown cases to `it.instance` | 2.37s | 1.67s | keep | Single baseline before edit; after median from three sequential reruns (1.66, 1.67, 1.67). |
8283

8384
## Profiling Results
8485

0 commit comments

Comments
 (0)