- Rename delegate_task tool to task across codebase (100 files) - Update model references: claude-opus-4-6 → 4-5, gpt-5.3-codex → 5.2-codex - Add tool-metadata-store to restore metadata overwritten by fromPlugin() - Add session ID polling for BackgroundManager task sessions - Await async ctx.metadata() calls in tool executors - Add ses_ prefix guard to getMessageDir for performance - Harden BackgroundManager with idle deferral and error handling - Fix duplicate task key in sisyphus-junior test object literals - Fix unawaited showOutputToUser in ast_grep_replace - Fix background=true → run_in_background=true in ultrawork prompt - Fix duplicate task/task references in docs and comments
179 lines
5.3 KiB
TypeScript
179 lines
5.3 KiB
TypeScript
import { describe, test, expect } from "bun:test"
|
|
import {
|
|
createAgentToolRestrictions,
|
|
createAgentToolAllowlist,
|
|
migrateToolsToPermission,
|
|
migrateAgentConfig,
|
|
} from "./permission-compat"
|
|
|
|
describe("permission-compat", () => {
|
|
describe("createAgentToolRestrictions", () => {
|
|
test("returns permission format with deny values", () => {
|
|
// given tools to restrict
|
|
// when creating restrictions
|
|
const result = createAgentToolRestrictions(["write", "edit"])
|
|
|
|
// then returns permission format
|
|
expect(result).toEqual({
|
|
permission: { write: "deny", edit: "deny" },
|
|
})
|
|
})
|
|
|
|
test("returns empty permission for empty array", () => {
|
|
// given empty tools array
|
|
// when creating restrictions
|
|
const result = createAgentToolRestrictions([])
|
|
|
|
// then returns empty permission
|
|
expect(result).toEqual({ permission: {} })
|
|
})
|
|
})
|
|
|
|
describe("createAgentToolAllowlist", () => {
|
|
test("returns wildcard deny with explicit allow", () => {
|
|
// given tools to allow
|
|
// when creating allowlist
|
|
const result = createAgentToolAllowlist(["read"])
|
|
|
|
// then returns wildcard deny with read allow
|
|
expect(result).toEqual({
|
|
permission: { "*": "deny", read: "allow" },
|
|
})
|
|
})
|
|
|
|
test("returns wildcard deny with multiple allows", () => {
|
|
// given multiple tools to allow
|
|
// when creating allowlist
|
|
const result = createAgentToolAllowlist(["read", "glob"])
|
|
|
|
// then returns wildcard deny with both allows
|
|
expect(result).toEqual({
|
|
permission: { "*": "deny", read: "allow", glob: "allow" },
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("migrateToolsToPermission", () => {
|
|
test("converts boolean tools to permission values", () => {
|
|
// given tools config
|
|
const tools = { write: false, edit: true, bash: false }
|
|
|
|
// when migrating
|
|
const result = migrateToolsToPermission(tools)
|
|
|
|
// then converts correctly
|
|
expect(result).toEqual({
|
|
write: "deny",
|
|
edit: "allow",
|
|
bash: "deny",
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("migrateAgentConfig", () => {
|
|
test("migrates tools to permission", () => {
|
|
// given config with tools
|
|
const config = {
|
|
model: "test",
|
|
tools: { write: false, edit: false },
|
|
}
|
|
|
|
// when migrating
|
|
const result = migrateAgentConfig(config)
|
|
|
|
// then converts to permission
|
|
expect(result.tools).toBeUndefined()
|
|
expect(result.permission).toEqual({ write: "deny", edit: "deny" })
|
|
expect(result.model).toBe("test")
|
|
})
|
|
|
|
test("preserves other config fields", () => {
|
|
// given config with other fields
|
|
const config = {
|
|
model: "test",
|
|
temperature: 0.5,
|
|
prompt: "hello",
|
|
tools: { write: false },
|
|
}
|
|
|
|
// when migrating
|
|
const result = migrateAgentConfig(config)
|
|
|
|
// then preserves other fields
|
|
expect(result.model).toBe("test")
|
|
expect(result.temperature).toBe(0.5)
|
|
expect(result.prompt).toBe("hello")
|
|
})
|
|
|
|
test("merges existing permission with migrated tools", () => {
|
|
// given config with both tools and permission
|
|
const config = {
|
|
tools: { write: false },
|
|
permission: { bash: "deny" as const },
|
|
}
|
|
|
|
// when migrating
|
|
const result = migrateAgentConfig(config)
|
|
|
|
// then merges permission (existing takes precedence)
|
|
expect(result.tools).toBeUndefined()
|
|
expect(result.permission).toEqual({ write: "deny", bash: "deny" })
|
|
})
|
|
|
|
test("returns unchanged config if no tools", () => {
|
|
// given config without tools
|
|
const config = { model: "test", permission: { edit: "deny" as const } }
|
|
|
|
// when migrating
|
|
const result = migrateAgentConfig(config)
|
|
|
|
// then returns unchanged
|
|
expect(result).toEqual(config)
|
|
})
|
|
|
|
test("migrates delegate_task permission to task", () => {
|
|
//#given config with delegate_task permission
|
|
const config = {
|
|
model: "test",
|
|
permission: { delegate_task: "allow" as const, write: "deny" as const },
|
|
}
|
|
|
|
//#when migrating
|
|
const result = migrateAgentConfig(config)
|
|
|
|
//#then delegate_task is renamed to task
|
|
const perm = result.permission as Record<string, string>
|
|
expect(perm["task"]).toBe("allow")
|
|
expect(perm["delegate_task"]).toBeUndefined()
|
|
expect(perm["write"]).toBe("deny")
|
|
})
|
|
|
|
test("does not overwrite existing task permission with delegate_task", () => {
|
|
//#given config with both task and delegate_task permissions
|
|
const config = {
|
|
permission: { delegate_task: "allow" as const, task: "deny" as const },
|
|
}
|
|
|
|
//#when migrating
|
|
const result = migrateAgentConfig(config)
|
|
|
|
//#then existing task permission is preserved
|
|
const perm = result.permission as Record<string, string>
|
|
expect(perm["task"]).toBe("deny")
|
|
expect(perm["delegate_task"]).toBe("allow")
|
|
})
|
|
|
|
test("does not mutate the original config permission object", () => {
|
|
//#given config with delegate_task permission
|
|
const originalPerm = { delegate_task: "allow" as const }
|
|
const config = { permission: originalPerm }
|
|
|
|
//#when migrating
|
|
migrateAgentConfig(config)
|
|
|
|
//#then original permission object is not mutated
|
|
expect(originalPerm).toEqual({ delegate_task: "allow" })
|
|
})
|
|
})
|
|
})
|