@@ -3,6 +3,8 @@ import type { ConfigEntry, OpenCodeEvent, SessionMessageInfo, WorktreeDirectory
33import { NO_PROVIDER , REMOTE_SERVER , SERVER , holdRoute , project , seed , session } from "../utils/app"
44import { mockMissingLocation , mockOpenCodeServer } from "../utils/mock-server"
55import { mockRemoteServer , mockWorkspace , openSession , openSettings , type WorkspaceInput } from "../utils/workspace"
6+ import { recordNotifications } from "../utils/notifications"
7+ import { installSseTransport } from "../utils/sse-transport"
68
79const directory = "C:/Projects/settings-demo"
810
@@ -94,6 +96,146 @@ test("a settings page survives refresh", async ({ page }) => {
9496 await expect ( page ) . toHaveURL ( "/settings?tab=appearance" )
9597} )
9698
99+ test ( "Questions settings default independently of old Permissions settings and survive reload" , async ( { page } ) => {
100+ const { settings } = await open ( page , {
101+ seed : {
102+ settings : {
103+ notifications : { agent : false , permissions : false , errors : true } ,
104+ sounds : { permissionsEnabled : false , permissions : "alert-05" } ,
105+ } ,
106+ } ,
107+ } )
108+
109+ await settings . getByRole ( "tab" , { name : "Notifications" , exact : true } ) . click ( )
110+ await expect ( settings . locator ( '[data-slot="settings-row-title"]' ) ) . toHaveText ( [
111+ "Agent" ,
112+ "Permissions" ,
113+ "Questions" ,
114+ "Errors" ,
115+ "Agent" ,
116+ "Permissions" ,
117+ "Questions" ,
118+ "Errors" ,
119+ "Interface" ,
120+ ] )
121+ const questions = settings . getByRole ( "switch" , { name : "Questions" , exact : true } )
122+
123+ const permissions = settings . locator ( '[data-action="settings-notifications-permissions"]' ) . getByRole ( "switch" )
124+
125+ const questionSound = settings . locator ( '[data-action="settings-sounds-questions"]' )
126+
127+ const permissionSound = settings . locator ( '[data-action="settings-sounds-permissions"]' )
128+
129+ await expect ( questions ) . toBeChecked ( )
130+ await expect ( permissions ) . not . toBeChecked ( )
131+ await expect ( questionSound ) . toHaveText ( "Staplebops 02" )
132+ await expect ( permissionSound ) . toHaveText ( "None" )
133+ await questions . locator ( ".." ) . locator ( '[data-slot="switch-control"]' ) . click ( )
134+ await expect ( questions ) . not . toBeChecked ( )
135+ await questionSound . click ( )
136+ await page . getByRole ( "option" , { name : "Alert 02" , exact : true } ) . click ( )
137+ await expect ( questionSound ) . toHaveText ( "Alert 02" )
138+
139+ await page . reload ( )
140+ await expect ( questions ) . not . toBeChecked ( )
141+ await expect ( questionSound ) . toHaveText ( "Alert 02" )
142+ await expect ( permissions ) . not . toBeChecked ( )
143+ await expect ( permissionSound ) . toHaveText ( "None" )
144+ await questions . locator ( ".." ) . locator ( '[data-slot="switch-control"]' ) . click ( )
145+ await questionSound . click ( )
146+ await page . getByRole ( "option" , { name : "None" , exact : true } ) . click ( )
147+ await expect ( questions ) . toBeChecked ( )
148+ await expect ( questionSound ) . toHaveText ( "None" )
149+ await settings . getByRole ( "combobox" , { name : "Search" , exact : true } ) . fill ( "Questions" )
150+ await expect ( settings . locator ( '[data-setting-target="settings-notifications-questions"]' ) ) . toBeVisible ( )
151+ await expect ( settings . locator ( '[data-setting-target="settings-sounds-questions"]' ) ) . toBeVisible ( )
152+ } )
153+
154+ test ( "request events use real Questions settings without disabling Permissions alerts" , async ( { page } ) => {
155+ const recorded = await recordNotifications ( page )
156+
157+ const transport = await installSseTransport ( page , { server : SERVER } )
158+
159+ const workspace = await openSession ( page , {
160+ name : "Request notifications" ,
161+ seed : { settings : { sounds : { agentEnabled : false , permissions : "alert-01" , questions : "alert-02" } } } ,
162+ } )
163+
164+ await transport . waitForConnection ( )
165+ await page . getByRole ( "button" , { name : "Home" , exact : true } ) . click ( )
166+ await page . getByRole ( "button" , { name : "Settings" , exact : true } ) . click ( )
167+ const settings = page . getByTestId ( "settings-screen" )
168+
169+ await settings . getByRole ( "tab" , { name : "Notifications" , exact : true } ) . click ( )
170+ const questions = settings . getByRole ( "switch" , { name : "Questions" , exact : true } )
171+
172+ await expect ( questions ) . toBeChecked ( )
173+
174+ const event = (
175+ kind : "question" | "mcp-elicitation" | "websearch.provider" | "permission" ,
176+ index : number ,
177+ ) : OpenCodeEvent => ( {
178+ id : `evt_request_${ index } ` ,
179+ created : 1700000001000 + index ,
180+ location : { directory : workspace . directory } ,
181+ ...( kind === "permission"
182+ ? {
183+ type : "permission.asked" as const ,
184+ data : {
185+ id : `per_request_${ index } ` ,
186+ sessionID : workspace . session . id ,
187+ action : "shell" ,
188+ resources : [ "echo hello" ] ,
189+ metadata : { } ,
190+ } ,
191+ }
192+ : {
193+ type : "form.created" as const ,
194+ data : {
195+ form : {
196+ id : `frm_request_${ index } ` ,
197+ sessionID : workspace . session . id ,
198+ title : "Input" ,
199+ metadata : { kind } ,
200+ fields : [ { key : "answer" , type : "string" as const , title : "Continue?" } ] ,
201+ } ,
202+ } ,
203+ } ) ,
204+ } )
205+
206+ await transport . send ( event ( "question" , 1 ) )
207+ await expect
208+ . poll ( ( ) => recorded . notifications )
209+ . toEqual ( [ { title : "Question requires an answer" , body : "Request notifications" } ] )
210+ await expect . poll ( ( ) => recorded . sounds ) . toEqual ( [ expect . stringContaining ( "alert-02" ) ] )
211+
212+ // Choosing None leaves system notifications enabled; the next input request proves the settings reach delivery.
213+ await settings . locator ( '[data-action="settings-sounds-questions"]' ) . click ( )
214+ await page . getByRole ( "option" , { name : "None" , exact : true } ) . click ( )
215+ await expect ( settings . locator ( '[data-action="settings-sounds-questions"]' ) ) . toHaveText ( "None" )
216+ const previews = recorded . sounds . slice ( )
217+
218+ await transport . send ( event ( "mcp-elicitation" , 2 ) )
219+ await expect
220+ . poll ( ( ) => recorded . notifications . map ( ( item ) => item . title ) )
221+ . toEqual ( [ "Question requires an answer" , "Input requested" ] )
222+
223+ await questions . locator ( ".." ) . locator ( '[data-slot="switch-control"]' ) . click ( )
224+ await expect ( questions ) . not . toBeChecked ( )
225+ await transport . send ( event ( "question" , 3 ) )
226+ await transport . send ( event ( "permission" , 4 ) )
227+ await expect
228+ . poll ( ( ) => recorded . notifications . map ( ( item ) => item . title ) )
229+ . toEqual ( [ "Question requires an answer" , "Input requested" , "Permission required" ] )
230+ await transport . send ( event ( "websearch.provider" , 5 ) )
231+ await expect
232+ . poll ( ( ) => recorded . notifications . map ( ( item ) => item . title ) )
233+ . toEqual ( [ "Question requires an answer" , "Input requested" , "Permission required" , "Permission required" ] )
234+ await expect
235+ . poll ( ( ) => recorded . sounds )
236+ . toEqual ( [ ...previews , expect . stringContaining ( "alert-01" ) , expect . stringContaining ( "alert-01" ) ] )
237+ } )
238+
97239for ( const locale of [ "en" , "ar" ] ) {
98240 test ( `background activity alignment stays physical and persists (${ locale } )` , async ( { page } ) => {
99241 const id = "ses_activity_settings"
0 commit comments