@@ -380,6 +380,90 @@ describe("embedded-agent active-run steering", () => {
380380 ) ;
381381 } ) ;
382382
383+ it ( "atomically claims pending plain-text input across an authority mismatch" , async ( ) => {
384+ const claimPendingUserInputAnswer = vi . fn ( async ( ) => true ) ;
385+ const queueMessage = vi . fn ( async ( ) => { } ) ;
386+ setActiveEmbeddedRun ( "session-pending-question" , {
387+ ...createEmbeddedRunHandle ( ) ,
388+ toolAuthorityFingerprint : "fallback-authority" ,
389+ claimPendingUserInputAnswer,
390+ queueMessage,
391+ } ) ;
392+
393+ const options = {
394+ isInboundUserMessage : true ,
395+ onQueueAccepted : vi . fn ( ) ,
396+ toolAuthorityFingerprint : "default-authority" ,
397+ } as const ;
398+ const outcome = await queueEmbeddedAgentMessageWithOutcomeAsync (
399+ "session-pending-question" ,
400+ "2" ,
401+ options ,
402+ ) ;
403+
404+ expect ( outcome ) . toMatchObject ( { queued : true , target : "embedded_run" } ) ;
405+ expect ( claimPendingUserInputAnswer ) . toHaveBeenCalledWith ( "2" , options ) ;
406+ expect ( options . onQueueAccepted ) . toHaveBeenCalledWith ( true ) ;
407+ expect ( queueMessage ) . not . toHaveBeenCalled ( ) ;
408+ } ) ;
409+
410+ it . each ( [
411+ { label : "no pending question" , claimed : false , images : undefined } ,
412+ {
413+ label : "image input" ,
414+ claimed : true ,
415+ images : [ { type : "image" as const , data : "png" , mimeType : "image/png" as const } ] ,
416+ } ,
417+ ] ) ( "preserves authority mismatch for $label" , async ( { claimed, images } ) => {
418+ const claimPendingUserInputAnswer = vi . fn ( async ( ) => claimed ) ;
419+ const cancelPendingUserInput = vi . fn ( async ( ) => true ) ;
420+ const queueMessage = vi . fn ( async ( ) => { } ) ;
421+ setActiveEmbeddedRun ( "session-pending-question-rejected" , {
422+ ...createEmbeddedRunHandle ( ) ,
423+ toolAuthorityFingerprint : "fallback-authority" ,
424+ claimPendingUserInputAnswer,
425+ cancelPendingUserInput,
426+ queueMessage,
427+ } ) ;
428+
429+ const outcome = await queueEmbeddedAgentMessageWithOutcomeAsync (
430+ "session-pending-question-rejected" ,
431+ "continue" ,
432+ {
433+ isInboundUserMessage : true ,
434+ toolAuthorityFingerprint : "default-authority" ,
435+ images,
436+ } ,
437+ ) ;
438+
439+ expect ( outcome ) . toMatchObject ( { queued : false , reason : "tool_authority_mismatch" } ) ;
440+ expect ( claimPendingUserInputAnswer ) . toHaveBeenCalledTimes ( images ? 0 : 1 ) ;
441+ expect ( cancelPendingUserInput ) . toHaveBeenCalledTimes ( images ? 1 : 0 ) ;
442+ expect ( queueMessage ) . not . toHaveBeenCalled ( ) ;
443+ } ) ;
444+
445+ it ( "cancels pending input before rejecting an unsupported queued image" , async ( ) => {
446+ const cancelPendingUserInput = vi . fn ( async ( ) => true ) ;
447+ setActiveEmbeddedRun ( "session-unsupported-question-image" , {
448+ ...createEmbeddedRunHandle ( ) ,
449+ toolAuthorityFingerprint : "same-authority" ,
450+ cancelPendingUserInput,
451+ } ) ;
452+
453+ const outcome = await queueEmbeddedAgentMessageWithOutcomeAsync (
454+ "session-unsupported-question-image" ,
455+ "inspect" ,
456+ {
457+ isInboundUserMessage : true ,
458+ toolAuthorityFingerprint : "same-authority" ,
459+ images : [ { type : "image" , data : "png" , mimeType : "image/png" } ] ,
460+ } ,
461+ ) ;
462+
463+ expect ( outcome ) . toMatchObject ( { queued : false , reason : "image_input_unsupported" } ) ;
464+ expect ( cancelPendingUserInput ) . toHaveBeenCalledWith ( "image-reply" ) ;
465+ } ) ;
466+
383467 it ( "reports accepted steering without transcript confirmation as non-replayable" , async ( ) => {
384468 setActiveEmbeddedRun ( "session-unconfirmed" , {
385469 ...createEmbeddedRunHandle ( ) ,
0 commit comments