fix(notifications): phrase permission labels without losing acronyms

The always-allow summary interpolated the raw action id ("always allow
shell") while every other surface shows the label ("Run Command"), and
the permission dialog lowercased the whole label, turning "Fetch URL"
into "fetch url". getPermissionPhrase lowercases each word of the label
unless it is all caps, and both the scope summary and the dialog
question use it.
This commit is contained in:
Chris Scott committed 2026-10-25 11:20:21 -04:00
1 parent 11a2661cc6
commit 8747cfece9
4 files changed
+57 -5

No files matched your search

@@ -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: [],
})
})
@@ -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(
<PermissionRequestDialog permission={permission} pendingCount={1} onRespond={vi.fn()} />,
)
expect(screen.getByText('Allow run command?')).toBeInTheDocument()
unmount()
render(
<PermissionRequestDialog
permission={{ ...permission, action: 'webfetch', resources: [], metadata: { url: 'https://example.com' } }}
pendingCount={1}
onRespond={vi.fn()}
/>,
)
expect(screen.getByText('Allow fetch URL?')).toBeInTheDocument()
})
it('labels multiple shell resources as commands', () => {
render(
<PermissionRequestDialog
@@ -69,7 +86,7 @@ describe('PermissionRequestDialog', () => {
/>,
)
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', () => {
@@ -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({
)}
</DialogTitle>
<DialogDescription className="break-all">
{`Allow ${typeLabel.toLowerCase()}?`}
{`Allow ${getPermissionPhrase(permission.action)}?`}
</DialogDescription>
</DialogHeader>
+14 -1
View File
@@ -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 }
}