mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
Refactor SchedulePermissionRuleset from object-based to array-based format. Updates schema, builder, and tests to match OpenCode v1.16+ expectations.
31 lines
1.4 KiB
TypeScript
31 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { DEFAULT_DESTRUCTIVE_BASH_PATTERNS, buildSchedulePermissionRuleset } from '@opencode-manager/shared/schemas'
|
|
|
|
describe('buildSchedulePermissionRuleset', () => {
|
|
it('returns the allow-all baseline with default deny rules when given null', () => {
|
|
const result = buildSchedulePermissionRuleset(null)
|
|
|
|
expect(result[0]).toEqual({ permission: '*', pattern: '*', action: 'allow' })
|
|
expect(result).toContainEqual({ permission: 'external_directory', pattern: '*', action: 'deny' })
|
|
for (const pattern of DEFAULT_DESTRUCTIVE_BASH_PATTERNS) {
|
|
expect(result).toContainEqual({ permission: 'bash', pattern, action: 'deny' })
|
|
}
|
|
})
|
|
|
|
it('returns only the allow-all baseline when all permissions are granted', () => {
|
|
const result = buildSchedulePermissionRuleset({ allowExternalDirectory: true, bashDenyPatterns: [] })
|
|
|
|
expect(result).toEqual([{ permission: '*', pattern: '*', action: 'allow' }])
|
|
})
|
|
|
|
it('includes a single custom bash deny pattern alongside external_directory deny', () => {
|
|
const result = buildSchedulePermissionRuleset({ allowExternalDirectory: false, bashDenyPatterns: ['rm -rf *'] })
|
|
|
|
expect(result).toEqual([
|
|
{ permission: '*', pattern: '*', action: 'allow' },
|
|
{ permission: 'external_directory', pattern: '*', action: 'deny' },
|
|
{ permission: 'bash', pattern: 'rm -rf *', action: 'deny' },
|
|
])
|
|
})
|
|
})
|