diff --git a/backend/test/services/notification-format.test.ts b/backend/test/services/notification-format.test.ts index e7c72a45..17cfd95d 100644 --- a/backend/test/services/notification-format.test.ts +++ b/backend/test/services/notification-format.test.ts @@ -1,6 +1,7 @@ import { describe, it, expect } from 'vitest' import { getPermissionLabel, + getPermissionPhrase, getPermissionDetail, getPermissionAlwaysScope, getFormText, @@ -64,6 +65,22 @@ describe('getPermissionLabel', () => { }) }) +describe('getPermissionPhrase', () => { + it('lowercases every word of a multi-word label', () => { + expect(getPermissionPhrase('shell')).toBe('run command') + expect(getPermissionPhrase('external_directory')).toBe('external access') + }) + it('preserves acronym words', () => { + expect(getPermissionPhrase('webfetch')).toBe('fetch URL') + }) + it('falls back to the generic phrase when the action is missing', () => { + expect(getPermissionPhrase('')).toBe('approval') + }) + it('lowercases unknown actions', () => { + expect(getPermissionPhrase('frobnicate')).toBe('frobnicate') + }) +}) + describe('getPermissionDetail', () => { it('returns the shell command from resources', () => { expect(getPermissionDetail({ action: 'shell', resources: ['rm -rf node_modules'] }).primary).toBe('rm -rf node_modules') @@ -119,9 +136,13 @@ describe('getPermissionAlwaysScope', () => { expect(getPermissionAlwaysScope({ action: 'shell' })).toBeNull() expect(getPermissionAlwaysScope({ action: 'shell', save: [] })).toBeNull() }) - it('describes a wildcard scope', () => { + it('describes a wildcard scope with the human action phrase', () => { expect(getPermissionAlwaysScope({ action: 'shell', save: ['*'] })).toEqual({ - summary: 'This will always allow shell for this project.', + summary: 'This will always allow run command for this project.', + patterns: [], + }) + expect(getPermissionAlwaysScope({ action: 'webfetch', save: ['*'] })).toEqual({ + summary: 'This will always allow fetch URL for this project.', patterns: [], }) }) diff --git a/frontend/src/components/session/PermissionRequestDialog.test.tsx b/frontend/src/components/session/PermissionRequestDialog.test.tsx index 5ff7c446..d366b070 100644 --- a/frontend/src/components/session/PermissionRequestDialog.test.tsx +++ b/frontend/src/components/session/PermissionRequestDialog.test.tsx @@ -34,6 +34,23 @@ describe('PermissionRequestDialog', () => { expect(screen.getByText('rm -rf node_modules')).toBeInTheDocument() }) + it('phrases the allow question in lowercase while preserving acronyms', () => { + const { unmount } = render( + , + ) + expect(screen.getByText('Allow run command?')).toBeInTheDocument() + unmount() + + render( + , + ) + expect(screen.getByText('Allow fetch URL?')).toBeInTheDocument() + }) + it('labels multiple shell resources as commands', () => { render( { />, ) - expect(screen.getByText('This will always allow shell for this project.')).toBeInTheDocument() + expect(screen.getByText('This will always allow run command for this project.')).toBeInTheDocument() }) it('lists the patterns an always decision approves', () => { diff --git a/frontend/src/components/session/PermissionRequestDialog.tsx b/frontend/src/components/session/PermissionRequestDialog.tsx index f980fd6b..db48844c 100644 --- a/frontend/src/components/session/PermissionRequestDialog.tsx +++ b/frontend/src/components/session/PermissionRequestDialog.tsx @@ -13,6 +13,7 @@ import type { PermissionResponse } from '@/api/types' import type { PermissionRequest } from '@opencode-manager/shared/opencode' import { getPermissionLabel, + getPermissionPhrase, getPermissionDetail, getPermissionAlwaysScope, } from '@opencode-manager/shared/notifications' @@ -99,7 +100,7 @@ export function PermissionRequestDialog({ )} - {`Allow ${typeLabel.toLowerCase()}?`} + {`Allow ${getPermissionPhrase(permission.action)}?`} diff --git a/shared/src/notifications/format.ts b/shared/src/notifications/format.ts index 910c391f..243b0156 100644 --- a/shared/src/notifications/format.ts +++ b/shared/src/notifications/format.ts @@ -71,6 +71,19 @@ export function getPermissionLabel(permission: string): string { return PERMISSION_LABELS[permission] ?? permission.charAt(0).toUpperCase() + permission.slice(1) } +/** + * Renders a permission action as a lowercase mid-sentence phrase, preserving acronyms. + * + * Use inside sentences such as `Allow ${getPermissionPhrase(action)}?` so the human + * label reads naturally instead of lowercasing the whole label. + */ +export function getPermissionPhrase(action: string): string { + return getPermissionLabel(action) + .split(' ') + .map((word) => (word === word.toUpperCase() ? word : word.toLowerCase())) + .join(' ') +} + interface PermissionLike { action?: unknown metadata?: unknown @@ -141,7 +154,7 @@ export function getPermissionAlwaysScope(input: PermissionLike): PermissionAlway const save = Array.isArray(input.save) ? input.save.filter((item): item is string => typeof item === 'string') : [] if (save.length === 0) return null if (save.length === 1 && save[0] === '*') { - return { summary: `This will always allow ${action} for this project.`, patterns: [] } + return { summary: `This will always allow ${getPermissionPhrase(action)} for this project.`, patterns: [] } } return { summary: 'This will always allow the following patterns for this project.', patterns: save } }