core: preserve permission config key order to maintain user-defined permission precedence

This commit is contained in:
Dax Raad
2026-01-05 14:06:38 -05:00
parent 5a38a6f248
commit 0276885181
2 changed files with 90 additions and 20 deletions

View File

@@ -868,3 +868,48 @@ test("merges legacy tools with existing permission config", async () => {
},
})
})
test("permission config preserves key order", async () => {
await using tmp = await tmpdir({
init: async (dir) => {
await Bun.write(
path.join(dir, "opencode.json"),
JSON.stringify({
$schema: "https://opencode.ai/config.json",
permission: {
"*": "deny",
edit: "ask",
write: "ask",
external_directory: "ask",
read: "allow",
todowrite: "allow",
todoread: "allow",
"thoughts_*": "allow",
"reasoning_model_*": "allow",
"tools_*": "allow",
"pr_comments_*": "allow",
},
}),
)
},
})
await Instance.provide({
directory: tmp.path,
fn: async () => {
const config = await Config.get()
expect(Object.keys(config.permission!)).toEqual([
"*",
"edit",
"write",
"external_directory",
"read",
"todowrite",
"todoread",
"thoughts_*",
"reasoning_model_*",
"tools_*",
"pr_comments_*",
])
},
})
})