fix(review): address review findings with proper type guards and clean formatting

This commit is contained in:
Spencer
2026-03-04 04:36:54 +00:00
parent cf08dcf6ac
commit 9888f8afa7
18 changed files with 199 additions and 333 deletions
@@ -411,7 +411,7 @@ describe('ToolConfirmationMessage', () => {
unmount();
});
it('should show "Allow for all future sessions" when setting is true', async () => {
it('should show "Allow for all future sessions" when trusted', async () => {
const mockConfig = {
isTrustedFolder: () => true,
getIdeMode: () => false,
@@ -434,41 +434,9 @@ describe('ToolConfirmationMessage', () => {
);
await waitUntilReady();
expect(lastFrame()).toContain('Allow for all future sessions');
unmount();
});
it('should default to "Allow for all future sessions" when autoAddToPolicyByDefault is true', async () => {
const mockConfig = {
isTrustedFolder: () => true,
getIdeMode: () => false,
} as unknown as Config;
const { lastFrame, waitUntilReady, unmount } = renderWithProviders(
<ToolConfirmationMessage
callId="test-call-id"
confirmationDetails={editConfirmationDetails}
config={mockConfig}
getPreferredEditor={vi.fn()}
availableTerminalHeight={30}
terminalWidth={80}
/>,
{
settings: createMockSettings({
security: {
enablePermanentToolApproval: true,
autoAddToPolicyByDefault: true,
},
}),
},
);
await waitUntilReady();
const output = lastFrame();
// In Ink, the selected item is usually highlighted with a cursor or different color.
// We can't easily check colors in text output, but we can verify it's NOT the first option
// if we could see the selection indicator.
// Instead, we'll verify the snapshot which should show the selection.
expect(output).toContain('future sessions');
// Verify it is the default selection (matching the indicator in the snapshot)
expect(output).toMatchSnapshot();
unmount();
});
@@ -245,7 +245,7 @@ export const ToolConfirmationMessage: React.FC<
});
if (allowPermanentApproval) {
options.push({
label: 'Allow for all future sessions',
label: `Allow for this file in all future sessions`,
value: ToolConfirmationOutcome.ProceedAlwaysAndSave,
key: 'Allow for all future sessions',
});
@@ -281,7 +281,7 @@ export const ToolConfirmationMessage: React.FC<
});
if (allowPermanentApproval) {
options.push({
label: `Allow for all future sessions`,
label: `Allow this command for all future sessions`,
value: ToolConfirmationOutcome.ProceedAlwaysAndSave,
key: `Allow for all future sessions`,
});
@@ -401,19 +401,16 @@ export const ToolConfirmationMessage: React.FC<
const options = getOptions();
let initialIndex = 0;
if (
settings.merged.security.autoAddToPolicyByDefault &&
isTrustedFolder &&
allowPermanentApproval
) {
if (isTrustedFolder && allowPermanentApproval) {
const isSafeToPersist =
confirmationDetails.type === 'info' ||
confirmationDetails.type === 'edit' ||
(confirmationDetails.type === 'exec' &&
confirmationDetails.rootCommand) ||
confirmationDetails.type === 'mcp';
if (isSafeToPersist) {
if (
isSafeToPersist &&
settings.merged.security.autoAddToPolicyByDefault
) {
const alwaysAndSaveIndex = options.findIndex(
(o) => o.value === ToolConfirmationOutcome.ProceedAlwaysAndSave,
);
@@ -671,9 +668,9 @@ export const ToolConfirmationMessage: React.FC<
mcpToolDetailsText,
expandDetailsHintKey,
getPreferredEditor,
settings.merged.security.autoAddToPolicyByDefault,
isTrustedFolder,
allowPermanentApproval,
settings.merged.security.autoAddToPolicyByDefault,
]);
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`ToolConfirmationMessage > enablePermanentToolApproval setting > should default to "Allow for all future sessions" when autoAddToPolicyByDefault is true 1`] = `
exports[`ToolConfirmationMessage > enablePermanentToolApproval setting > should show "Allow for all future sessions" when trusted 1`] = `
"╭──────────────────────────────────────────────────────────────────────────────╮
│ │
│ No changes detected. │
@@ -10,7 +10,7 @@ Apply this change?
1. Allow once
2. Allow for this session
● 3. Allow for all future sessions
● 3. Allow for this file in all future sessions
4. Modify with external editor
5. No, suggest changes (esc)
"