feat: OpenCode v1.1.1 permission system compatibility (#489)
* feat: add OpenCode v1.1.1 version detection and permission compatibility utilities - Add opencode-version.ts: Detect installed OpenCode version and support API - Add permission-compat.ts: Compatibility layer for permission system migration - Add comprehensive tests (418 lines total) - Export new utilities from shared/index.ts 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode) * fix: update agent permission configs for OpenCode v1.1.1 compatibility - Fix document-writer: change invalid 'permission: { background_task: deny }' to 'tools: { background_task: false }' - Fix explore: split 'permission' and 'tools' config, move tool-level denials to 'tools' key - Fix oracle: split 'permission' and 'tools' config, move tool-level denials to 'tools' key - Align all agents with v1.1.1 permission system structure 🤖 Generated with assistance of OhMyOpenCode (https://github.com/code-yeongyu/oh-my-opencode)
This commit is contained in:
161
src/shared/permission-compat.test.ts
Normal file
161
src/shared/permission-compat.test.ts
Normal file
@@ -0,0 +1,161 @@
|
||||
import { describe, test, expect } from "bun:test"
|
||||
import {
|
||||
createToolDenyList,
|
||||
permissionValueToBoolean,
|
||||
booleanToPermissionValue,
|
||||
convertToolsToPermission,
|
||||
convertPermissionToTools,
|
||||
createAgentRestrictions,
|
||||
} from "./permission-compat"
|
||||
|
||||
describe("permission-compat", () => {
|
||||
describe("createToolDenyList", () => {
|
||||
test("creates tools config with all values false", () => {
|
||||
// #given a list of tool names
|
||||
const tools = ["write", "edit", "task"]
|
||||
|
||||
// #when creating deny list
|
||||
const result = createToolDenyList(tools)
|
||||
|
||||
// #then all values are false
|
||||
expect(result).toEqual({ write: false, edit: false, task: false })
|
||||
})
|
||||
|
||||
test("returns empty object for empty array", () => {
|
||||
// #given empty array
|
||||
// #when creating deny list
|
||||
const result = createToolDenyList([])
|
||||
|
||||
// #then returns empty object
|
||||
expect(result).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
describe("permissionValueToBoolean", () => {
|
||||
test("converts allow to true", () => {
|
||||
expect(permissionValueToBoolean("allow")).toBe(true)
|
||||
})
|
||||
|
||||
test("converts deny to false", () => {
|
||||
expect(permissionValueToBoolean("deny")).toBe(false)
|
||||
})
|
||||
|
||||
test("converts ask to false", () => {
|
||||
expect(permissionValueToBoolean("ask")).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe("booleanToPermissionValue", () => {
|
||||
test("converts true to allow", () => {
|
||||
expect(booleanToPermissionValue(true)).toBe("allow")
|
||||
})
|
||||
|
||||
test("converts false to deny", () => {
|
||||
expect(booleanToPermissionValue(false)).toBe("deny")
|
||||
})
|
||||
})
|
||||
|
||||
describe("convertToolsToPermission", () => {
|
||||
test("converts boolean tools config to permission format", () => {
|
||||
// #given tools config with booleans
|
||||
const tools = { write: false, edit: true, bash: false }
|
||||
|
||||
// #when converting to permission
|
||||
const result = convertToolsToPermission(tools)
|
||||
|
||||
// #then converts to permission values
|
||||
expect(result).toEqual({ write: "deny", edit: "allow", bash: "deny" })
|
||||
})
|
||||
|
||||
test("handles empty tools config", () => {
|
||||
// #given empty config
|
||||
// #when converting
|
||||
const result = convertToolsToPermission({})
|
||||
|
||||
// #then returns empty object
|
||||
expect(result).toEqual({})
|
||||
})
|
||||
})
|
||||
|
||||
describe("convertPermissionToTools", () => {
|
||||
test("converts permission to boolean tools config", () => {
|
||||
// #given permission config
|
||||
const permission = { write: "deny" as const, edit: "allow" as const }
|
||||
|
||||
// #when converting to tools
|
||||
const result = convertPermissionToTools(permission)
|
||||
|
||||
// #then converts to boolean values
|
||||
expect(result).toEqual({ write: false, edit: true })
|
||||
})
|
||||
|
||||
test("excludes ask values", () => {
|
||||
// #given permission with ask value
|
||||
const permission = {
|
||||
write: "deny" as const,
|
||||
edit: "ask" as const,
|
||||
bash: "allow" as const,
|
||||
}
|
||||
|
||||
// #when converting
|
||||
const result = convertPermissionToTools(permission)
|
||||
|
||||
// #then ask is excluded
|
||||
expect(result).toEqual({ write: false, bash: true })
|
||||
})
|
||||
})
|
||||
|
||||
describe("createAgentRestrictions", () => {
|
||||
test("creates restrictions with denied tools", () => {
|
||||
// #given deny tools list
|
||||
const config = { denyTools: ["write", "task"] }
|
||||
|
||||
// #when creating restrictions
|
||||
const result = createAgentRestrictions(config)
|
||||
|
||||
// #then creates tools config
|
||||
expect(result).toEqual({ tools: { write: false, task: false } })
|
||||
})
|
||||
|
||||
test("creates restrictions with permission", () => {
|
||||
// #given permission config
|
||||
const config = {
|
||||
permission: { edit: "deny" as const, bash: "ask" as const },
|
||||
}
|
||||
|
||||
// #when creating restrictions
|
||||
const result = createAgentRestrictions(config)
|
||||
|
||||
// #then creates permission config
|
||||
expect(result).toEqual({
|
||||
permission: { edit: "deny", bash: "ask" },
|
||||
})
|
||||
})
|
||||
|
||||
test("combines tools and permission", () => {
|
||||
// #given both deny tools and permission
|
||||
const config = {
|
||||
denyTools: ["task"],
|
||||
permission: { edit: "deny" as const },
|
||||
}
|
||||
|
||||
// #when creating restrictions
|
||||
const result = createAgentRestrictions(config)
|
||||
|
||||
// #then includes both
|
||||
expect(result).toEqual({
|
||||
tools: { task: false },
|
||||
permission: { edit: "deny" },
|
||||
})
|
||||
})
|
||||
|
||||
test("returns empty object when no config provided", () => {
|
||||
// #given empty config
|
||||
// #when creating restrictions
|
||||
const result = createAgentRestrictions({})
|
||||
|
||||
// #then returns empty object
|
||||
expect(result).toEqual({})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user