@@ -180,6 +180,85 @@ describe("chat pane header state", () => {
180180 expect ( patch ) . not . toHaveBeenCalled ( ) ;
181181 } ) ;
182182
183+ it ( "refuses header rename when sessions.patch is unavailable or lacks write scope" , ( ) => {
184+ for ( const hello of [
185+ {
186+ auth : { role : "operator" , scopes : [ "operator.write" ] } ,
187+ features : { methods : [ "sessions.create" ] } ,
188+ } ,
189+ {
190+ auth : { role : "operator" , scopes : [ "operator.read" ] } ,
191+ features : { methods : [ "sessions.patch" ] } ,
192+ } ,
193+ ] ) {
194+ const patch = vi . fn ( async ( ) => ( { } ) ) ;
195+ const sessions = { patch } as unknown as SessionCapability ;
196+ const { pane, state, requestUpdate } = createTestChatPane ( {
197+ client : { } as GatewayBrowserClient ,
198+ sessions,
199+ } ) ;
200+ pane . context . gateway . snapshot . hello =
201+ hello as ApplicationContext [ "gateway" ] [ "snapshot" ] [ "hello" ] ;
202+ const session = {
203+ key : "agent:main:current" ,
204+ kind : "direct" ,
205+ updatedAt : 0 ,
206+ } satisfies GatewaySessionRow ;
207+
208+ pane . beginHeaderRename ( session ) ;
209+
210+ expect ( pane . headerEditing ) . toBe ( false ) ;
211+ expect ( state . chatError ) . toBeTruthy ( ) ;
212+ expect ( requestUpdate ) . toHaveBeenCalledOnce ( ) ;
213+ expect ( patch ) . not . toHaveBeenCalled ( ) ;
214+ }
215+ } ) ;
216+
217+ it ( "rechecks header rename access before committing" , ( ) => {
218+ const patch = vi . fn ( async ( ) => ( { } ) ) ;
219+ const sessions = { patch } as unknown as SessionCapability ;
220+ const { pane, state } = createTestChatPane ( {
221+ client : { } as GatewayBrowserClient ,
222+ sessions,
223+ } ) ;
224+ const session = {
225+ key : "agent:main:current" ,
226+ kind : "direct" ,
227+ updatedAt : 0 ,
228+ } satisfies GatewaySessionRow ;
229+
230+ pane . beginHeaderRename ( session ) ;
231+ pane . headerRenameValue = "Blocked rename" ;
232+ pane . context . gateway . snapshot . hello = {
233+ auth : { role : "operator" , scopes : [ "operator.read" ] } ,
234+ features : { methods : [ "sessions.patch" ] } ,
235+ } as ApplicationContext [ "gateway" ] [ "snapshot" ] [ "hello" ] ;
236+ pane . commitHeaderRename ( ) ;
237+
238+ expect ( state . chatError ) . toBeTruthy ( ) ;
239+ expect ( patch ) . not . toHaveBeenCalled ( ) ;
240+ } ) ;
241+
242+ it ( "refuses archived-session restore without exact sessions.patch access" , async ( ) => {
243+ const patch = vi . fn ( async ( ) => ( { } ) ) ;
244+ const sessions = { patch } as unknown as SessionCapability ;
245+ const { pane, state, requestUpdate } = createTestChatPane ( {
246+ client : { } as GatewayBrowserClient ,
247+ sessions,
248+ } ) ;
249+ pane . context . gateway . snapshot . hello = {
250+ auth : { role : "operator" , scopes : [ "operator.read" ] } ,
251+ features : { methods : [ "sessions.patch" ] } ,
252+ } as ApplicationContext [ "gateway" ] [ "snapshot" ] [ "hello" ] ;
253+
254+ await pane . restoreArchivedSession ( state . sessionKey ) ;
255+
256+ expect ( state . chatError ) . toBeTruthy ( ) ;
257+ expect ( state . lastError ) . toBe ( state . chatError ) ;
258+ expect ( requestUpdate ) . toHaveBeenCalledOnce ( ) ;
259+ expect ( patch ) . not . toHaveBeenCalled ( ) ;
260+ } ) ;
261+
183262 it ( "copies the resolved workspace path and branch" , async ( ) => {
184263 const { pane } = createTestChatPane ( {
185264 client : { } as GatewayBrowserClient ,
0 commit comments