Skip to content

Commit 984ddfc

Browse files
committed
test(webview): visual snapshot for blanket auto-deny checkbox
The blanket auto-deny setting makes command execution fail closed when command auto-approval is on: explicitly approved commands run, anything else is denied without prompting, and the denial reason goes back to the model. The settings row that controls it had no visual regression coverage. Add a Story Gallery snapshot test for the Auto-approve settings panel with the blanket auto-deny checkbox visible and checked, plus its story registration and baselines for the four supported themes (dark, light, high-contrast, high-contrast-light). The baselines were generated in the Playwright container image pinned by docker-compose.visual.yml and are committed so the surface is protected against future drift. The setting behavior itself landed in earlier commits of this branch; this commit only adds the visual coverage.
1 parent 4576e51 commit 984ddfc

7 files changed

Lines changed: 106 additions & 0 deletions

File tree

‎webview-ui/playwright/gallery/stories.tsx‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export const stories: Record<string, Story> = {
5656
</AppProviders>
5757
)
5858
},
59+
"auto-approve-settings": async () => {
60+
const { AutoApproveSettingsStory } =
61+
await import("@/components/settings/__tests__/AutoApproveSettings.visual.fixture")
62+
return <AutoApproveSettingsStory />
63+
},
5964
"chat-text-area": async () => {
6065
const { ChatTextAreaStory } = await import("@/components/chat/__tests__/ChatTextArea.visual.fixture")
6166
return <ChatTextAreaStory />
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React, { useState } from "react"
2+
3+
import type { ExtensionStateContextType } from "@/context/ExtensionStateContext"
4+
import type { SetCachedStateField } from "../types"
5+
import { AutoApproveSettings } from "../AutoApproveSettings"
6+
import { AppProviders } from "../../../../playwright/AppProviders"
7+
8+
interface AutoApproveState {
9+
alwaysAllowReadOnly: boolean
10+
alwaysAllowWrite: boolean
11+
alwaysAllowMcp: boolean
12+
alwaysAllowModeSwitch: boolean
13+
alwaysAllowSubtasks: boolean
14+
alwaysAllowExecute: boolean
15+
alwaysAllowFollowupQuestions: boolean
16+
destructiveCommandGuardEnabled: boolean
17+
alwaysDenyUnapprovedCommands: boolean
18+
allowedCommands: string[]
19+
deniedCommands: string[]
20+
allowedReadFiles: string[]
21+
allowedWriteFiles: string[]
22+
allowedMaxRequests?: number
23+
allowedMaxCost?: number
24+
}
25+
26+
export function AutoApproveSettingsStory() {
27+
// The blanket auto-deny checkbox is pinned here in its operative mode: with
28+
// the destructive command guard on it is the fail-closed policy, and the
29+
// guard's hidden command-list editors would otherwise vary the snapshot.
30+
const [state, setState] = useState<AutoApproveState>({
31+
alwaysAllowReadOnly: false,
32+
alwaysAllowWrite: false,
33+
alwaysAllowMcp: false,
34+
alwaysAllowModeSwitch: false,
35+
alwaysAllowSubtasks: false,
36+
alwaysAllowExecute: true,
37+
alwaysAllowFollowupQuestions: false,
38+
destructiveCommandGuardEnabled: true,
39+
alwaysDenyUnapprovedCommands: true,
40+
allowedCommands: [],
41+
deniedCommands: [],
42+
allowedReadFiles: [],
43+
allowedWriteFiles: [],
44+
})
45+
const setCachedStateField: SetCachedStateField<keyof ExtensionStateContextType> = (field, value) => {
46+
setState((current) => {
47+
switch (field) {
48+
case "alwaysAllowReadOnly":
49+
case "alwaysAllowWrite":
50+
case "alwaysAllowMcp":
51+
case "alwaysAllowModeSwitch":
52+
case "alwaysAllowSubtasks":
53+
case "alwaysAllowExecute":
54+
case "alwaysAllowFollowupQuestions":
55+
case "destructiveCommandGuardEnabled":
56+
case "alwaysDenyUnapprovedCommands":
57+
return { ...current, [field]: Boolean(value) }
58+
case "allowedCommands":
59+
case "deniedCommands":
60+
case "allowedReadFiles":
61+
case "allowedWriteFiles":
62+
return { ...current, [field]: Array.isArray(value) ? [...value] : [] }
63+
case "allowedMaxRequests":
64+
case "allowedMaxCost":
65+
return { ...current, [field]: typeof value === "number" ? value : undefined }
66+
default:
67+
return current
68+
}
69+
})
70+
}
71+
72+
return (
73+
<AppProviders initialState={{ autoApprovalEnabled: true }}>
74+
<div
75+
data-testid="auto-approve-settings-story"
76+
className="w-[488px] max-w-full rounded-lg border border-vscode-panel-border bg-vscode-editor-background p-4 text-vscode-editor-foreground">
77+
<AutoApproveSettings {...state} setCachedStateField={setCachedStateField} />
78+
</div>
79+
</AppProviders>
80+
)
81+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect, test } from "../../../../playwright/coverage-fixture"
2+
import { mountedStory } from "../../../../playwright/mounted-story"
3+
import { applyVisualTheme, visualThemes } from "../../../../playwright/themes"
4+
5+
// Declared in webview-ui/src/i18n/locales/en/settings.json under
6+
// settings:autoApprove.execute.autoDeny.label; the checkbox takes its accessible
7+
// name from that label text, so the two must stay in sync.
8+
const autoDenyLabel = "Auto-deny unapproved commands (never ask)"
9+
10+
for (const theme of visualThemes) {
11+
test(`renders the blanket auto-deny checkbox in the VS Code ${theme.name} theme`, async ({ mount, page }) => {
12+
const component = mountedStory(await mount("auto-approve-settings"))
13+
await applyVisualTheme(page, theme)
14+
const story = component.getByTestId("auto-approve-settings-story")
15+
const checkbox = story.getByRole("checkbox", { name: autoDenyLabel })
16+
await expect(checkbox).toBeVisible()
17+
await expect(checkbox).toBeChecked()
18+
await expect(story).toHaveScreenshot(`auto-approve-settings-${theme.name}.png`)
19+
})
20+
}
109 KB
Loading
109 KB
Loading
112 KB
Loading
111 KB
Loading

0 commit comments

Comments
 (0)