test: migrate config legacy tool fixtures

This commit is contained in:
Kit Langton
2026-05-18 21:27:43 -04:00
committed by GitHub
parent 996928b32a
commit 7e4b02f1bf
2 changed files with 103 additions and 192 deletions
+58 -148
View File
@@ -1295,34 +1295,18 @@ test("migrates legacy tools config to permissions - deny", async () => {
}) })
}) })
test("migrates legacy write tool to edit permission", async () => { it.instance("migrates legacy write tool to edit permission", () =>
await using tmp = await tmpdir({ Effect.gen(function* () {
init: async (dir) => { const test = yield* TestInstance
await Filesystem.write( yield* writeConfigEffect(test.directory, {
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json", $schema: "https://opencode.ai/config.json",
agent: { agent: { test: { tools: { write: true } } },
test: { })
tools: {
write: true, const config = yield* Config.Service.use((svc) => svc.get())
}, expect(config.agent?.["test"]?.permission).toEqual({ edit: "allow" })
},
},
}), }),
) )
},
})
await withTestInstance({
directory: tmp.path,
fn: async (ctx) => {
const config = await load(ctx)
expect(config.agent?.["test"]?.permission).toEqual({
edit: "allow",
})
},
})
})
// Managed settings tests // Managed settings tests
// Note: preload.ts sets OPENCODE_TEST_MANAGED_CONFIG which Global.Path.managedConfig uses // Note: preload.ts sets OPENCODE_TEST_MANAGED_CONFIG which Global.Path.managedConfig uses
@@ -1402,140 +1386,72 @@ test("missing managed settings file is not an error", async () => {
}) })
}) })
test("migrates legacy edit tool to edit permission", async () => { it.instance("migrates legacy edit tool to edit permission", () =>
await using tmp = await tmpdir({ Effect.gen(function* () {
init: async (dir) => { const test = yield* TestInstance
await Filesystem.write( yield* writeConfigEffect(test.directory, {
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json", $schema: "https://opencode.ai/config.json",
agent: { agent: { test: { tools: { edit: false } } },
test: {
tools: {
edit: false,
},
},
},
}),
)
},
}) })
await withTestInstance({
directory: tmp.path,
fn: async (ctx) => {
const config = await load(ctx)
expect(config.agent?.["test"]?.permission).toEqual({
edit: "deny",
})
},
})
})
test("migrates legacy patch tool to edit permission", async () => { const config = yield* Config.Service.use((svc) => svc.get())
await using tmp = await tmpdir({ expect(config.agent?.["test"]?.permission).toEqual({ edit: "deny" })
init: async (dir) => {
await Filesystem.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
agent: {
test: {
tools: {
patch: true,
},
},
},
}), }),
) )
},
})
await withTestInstance({
directory: tmp.path,
fn: async (ctx) => {
const config = await load(ctx)
expect(config.agent?.["test"]?.permission).toEqual({
edit: "allow",
})
},
})
})
test("migrates mixed legacy tools config", async () => { it.instance("migrates legacy patch tool to edit permission", () =>
await using tmp = await tmpdir({ Effect.gen(function* () {
init: async (dir) => { const test = yield* TestInstance
await Filesystem.write( yield* writeConfigEffect(test.directory, {
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json", $schema: "https://opencode.ai/config.json",
agent: { agent: { test: { tools: { patch: true } } },
test: {
tools: {
bash: true,
write: true,
read: false,
webfetch: true,
},
},
},
}),
)
},
}) })
await withTestInstance({
directory: tmp.path, const config = yield* Config.Service.use((svc) => svc.get())
fn: async (ctx) => { expect(config.agent?.["test"]?.permission).toEqual({ edit: "allow" })
const config = await load(ctx) }),
)
it.instance("migrates mixed legacy tools config", () =>
Effect.gen(function* () {
const test = yield* TestInstance
yield* writeConfigEffect(test.directory, {
$schema: "https://opencode.ai/config.json",
agent: { test: { tools: { bash: true, write: true, read: false, webfetch: true } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
expect(config.agent?.["test"]?.permission).toEqual({ expect(config.agent?.["test"]?.permission).toEqual({
bash: "allow", bash: "allow",
edit: "allow", edit: "allow",
read: "deny", read: "deny",
webfetch: "allow", webfetch: "allow",
}) })
},
})
})
test("merges legacy tools with existing permission config", 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",
agent: {
test: {
permission: {
glob: "allow",
},
tools: {
bash: true,
},
},
},
}), }),
) )
},
it.instance("merges legacy tools with existing permission config", () =>
Effect.gen(function* () {
const test = yield* TestInstance
yield* writeConfigEffect(test.directory, {
$schema: "https://opencode.ai/config.json",
agent: { test: { permission: { glob: "allow" }, tools: { bash: true } } },
}) })
await withTestInstance({
directory: tmp.path, const config = yield* Config.Service.use((svc) => svc.get())
fn: async (ctx) => {
const config = await load(ctx)
expect(config.agent?.["test"]?.permission).toEqual({ expect(config.agent?.["test"]?.permission).toEqual({
glob: "allow", glob: "allow",
bash: "allow", bash: "allow",
}) })
}, }),
}) )
})
test("permission config preserves user key order", async () => { it.instance("permission config preserves user key order", () =>
// Permission precedence follows the order users write in config, so parsing // Permission precedence follows the order users write in config, so parsing
// must not canonicalise known keys ahead of wildcard or custom keys. // must not canonicalise known keys ahead of wildcard or custom keys.
await using tmp = await tmpdir({ Effect.gen(function* () {
init: async (dir) => { const test = yield* TestInstance
await Filesystem.write( yield* writeConfigEffect(test.directory, {
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json", $schema: "https://opencode.ai/config.json",
permission: { permission: {
"*": "deny", "*": "deny",
@@ -1549,14 +1465,9 @@ test("permission config preserves user key order", async () => {
"tools_*": "allow", "tools_*": "allow",
"pr_comments_*": "allow", "pr_comments_*": "allow",
}, },
}),
)
},
}) })
await withTestInstance({
directory: tmp.path, const config = yield* Config.Service.use((svc) => svc.get())
fn: async (ctx) => {
const config = await load(ctx)
expect(Object.keys(config.permission!)).toEqual([ expect(Object.keys(config.permission!)).toEqual([
"*", "*",
"edit", "edit",
@@ -1569,9 +1480,8 @@ test("permission config preserves user key order", async () => {
"tools_*", "tools_*",
"pr_comments_*", "pr_comments_*",
]) ])
}, }),
}) )
})
test("config parser preserves permission order while rejecting unknown top-level keys", () => { test("config parser preserves permission order while rejecting unknown top-level keys", () => {
const config = ConfigParse.schema( const config = ConfigParse.schema(
+1
View File
@@ -76,6 +76,7 @@ Repeated setup work, long sleeps/timeouts, serial integration tests, filesystem/
| 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. | | 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. |
| Local config update and directory cases can use Effect-aware instance fixtures | Migrated local `update` and `directories` cases to `it.instance` | 1.77s | 1.71s | keep | Three-run medians; small positive/neutral timing, removes manual instance plumbing, and eliminates one existing unsafe cast. | | Local config update and directory cases can use Effect-aware instance fixtures | Migrated local `update` and `directories` cases to `it.instance` | 1.77s | 1.71s | keep | Three-run medians; small positive/neutral timing, removes manual instance plumbing, and eliminates one existing unsafe cast. |
| `.opencode` agent and command file-loading cases can use Effect-aware instance fixtures | Migrated singular/plural agent and command markdown fixture cases to `it.instance` | 7.21s | 1.87s | keep | Parent baseline was noisy (7.42, 7.21, 2.83); after runs were stable at 1.87, 1.98, 1.83. Keep as cleanup with no broad claim. | | `.opencode` agent and command file-loading cases can use Effect-aware instance fixtures | Migrated singular/plural agent and command markdown fixture cases to `it.instance` | 7.21s | 1.87s | keep | Parent baseline was noisy (7.42, 7.21, 2.83); after runs were stable at 1.87, 1.98, 1.83. Keep as cleanup with no broad claim. |
| 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. |
## Profiling Results ## Profiling Results