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
+102 -192
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"), $schema: "https://opencode.ai/config.json",
JSON.stringify({ agent: { test: { tools: { write: true } } },
$schema: "https://opencode.ai/config.json", })
agent: {
test: { const config = yield* Config.Service.use((svc) => svc.get())
tools: { expect(config.agent?.["test"]?.permission).toEqual({ edit: "allow" })
write: true, }),
}, )
},
},
}),
)
},
})
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,176 +1386,102 @@ 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"), $schema: "https://opencode.ai/config.json",
JSON.stringify({ agent: { test: { tools: { edit: false } } },
$schema: "https://opencode.ai/config.json", })
agent: {
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"), $schema: "https://opencode.ai/config.json",
JSON.stringify({ agent: { test: { tools: { patch: true } } },
$schema: "https://opencode.ai/config.json", })
agent: {
test: {
tools: {
bash: true,
write: true,
read: false,
webfetch: true,
},
},
},
}),
)
},
})
await withTestInstance({
directory: tmp.path,
fn: async (ctx) => {
const config = await load(ctx)
expect(config.agent?.["test"]?.permission).toEqual({
bash: "allow",
edit: "allow",
read: "deny",
webfetch: "allow",
})
},
})
})
test("merges legacy tools with existing permission config", async () => { const config = yield* Config.Service.use((svc) => svc.get())
await using tmp = await tmpdir({ expect(config.agent?.["test"]?.permission).toEqual({ edit: "allow" })
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,
},
},
},
}),
)
},
})
await withTestInstance({
directory: tmp.path,
fn: async (ctx) => {
const config = await load(ctx)
expect(config.agent?.["test"]?.permission).toEqual({
glob: "allow",
bash: "allow",
})
},
})
})
test("permission config preserves user key order", async () => { 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({
bash: "allow",
edit: "allow",
read: "deny",
webfetch: "allow",
})
}),
)
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 } } },
})
const config = yield* Config.Service.use((svc) => svc.get())
expect(config.agent?.["test"]?.permission).toEqual({
glob: "allow",
bash: "allow",
})
}),
)
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"), $schema: "https://opencode.ai/config.json",
JSON.stringify({ permission: {
$schema: "https://opencode.ai/config.json", "*": "deny",
permission: { edit: "ask",
"*": "deny", write: "ask",
edit: "ask", external_directory: "ask",
write: "ask", read: "allow",
external_directory: "ask", todowrite: "allow",
read: "allow", "thoughts_*": "allow",
todowrite: "allow", "reasoning_model_*": "allow",
"thoughts_*": "allow", "tools_*": "allow",
"reasoning_model_*": "allow", "pr_comments_*": "allow",
"tools_*": "allow", },
"pr_comments_*": "allow", })
},
}), const config = yield* Config.Service.use((svc) => svc.get())
) expect(Object.keys(config.permission!)).toEqual([
}, "*",
}) "edit",
await withTestInstance({ "write",
directory: tmp.path, "external_directory",
fn: async (ctx) => { "read",
const config = await load(ctx) "todowrite",
expect(Object.keys(config.permission!)).toEqual([ "thoughts_*",
"*", "reasoning_model_*",
"edit", "tools_*",
"write", "pr_comments_*",
"external_directory", ])
"read", }),
"todowrite", )
"thoughts_*",
"reasoning_model_*",
"tools_*",
"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