@@ -414,24 +414,28 @@ const requireRunningSessionId = (result: { details: unknown }) => {
414414 return requireSessionId ( result . details as { sessionId ?: string } ) ;
415415} ;
416416
417- function hasNotifyEventForPrefix ( prefix : string , sessionKey = DEFAULT_NOTIFY_SESSION_KEY ) : boolean {
418- return peekSystemEvents ( sessionKey ) . some ( ( event ) => event . includes ( prefix ) ) ;
417+ function hasNotifyEventForSession (
418+ sessionId : string ,
419+ sessionKey = DEFAULT_NOTIFY_SESSION_KEY ,
420+ ) : boolean {
421+ return peekSystemEventEntries ( sessionKey ) . some (
422+ ( event ) => event . contextKey === `exec:${ sessionId } ` ,
423+ ) ;
419424}
420425
421426async function waitForNotifyEvent ( sessionId : string , sessionKey = DEFAULT_NOTIFY_SESSION_KEY ) {
422- const prefix = sessionId . slice ( 0 , 8 ) ;
423427 let finished = getFinishedSession ( sessionId ) ;
424- let hasEvent = hasNotifyEventForPrefix ( prefix , sessionKey ) ;
428+ let hasEvent = hasNotifyEventForSession ( sessionId , sessionKey ) ;
425429 await expect
426430 . poll ( ( ) => {
427431 finished = getFinishedSession ( sessionId ) ;
428- hasEvent = hasNotifyEventForPrefix ( prefix , sessionKey ) ;
432+ hasEvent = hasNotifyEventForSession ( sessionId , sessionKey ) ;
429433 return Boolean ( finished && hasEvent ) ;
430434 } , NOTIFY_POLL_OPTIONS )
431435 . toBe ( true ) ;
432436 return {
433437 finished : finished ?? getFinishedSession ( sessionId ) ,
434- hasEvent : hasEvent || hasNotifyEventForPrefix ( prefix ) ,
438+ hasEvent : hasEvent || hasNotifyEventForSession ( sessionId ) ,
435439 } ;
436440}
437441
@@ -826,8 +830,8 @@ describe("exec notifyOnExit", () => {
826830 const sessionId = await startBackgroundCommand ( tool , shellEcho ( "notify" ) ) ;
827831
828832 const { finished, hasEvent } = await waitForNotifyEvent ( sessionId ) ;
829- const queuedEvent = peekSystemEventEntries ( DEFAULT_NOTIFY_SESSION_KEY ) . find ( ( event ) =>
830- event . text . includes ( sessionId . slice ( 0 , 8 ) ) ,
833+ const queuedEvent = peekSystemEventEntries ( DEFAULT_NOTIFY_SESSION_KEY ) . find (
834+ ( event ) => event . contextKey === `exec: ${ sessionId } ` ,
831835 ) ;
832836 const formatted = await drainNotifyEvents ( ) ;
833837
@@ -848,8 +852,8 @@ describe("exec notifyOnExit", () => {
848852 const poll = await pollProcessSession ( { tool : processTool , sessionId } ) ;
849853
850854 expect ( poll . status ) . toBe ( PROCESS_STATUS_COMPLETED ) ;
851- expect ( hasNotifyEventForPrefix ( sessionId . slice ( 0 , 8 ) ) ) . toBe ( false ) ;
852- expect ( hasNotifyEventForPrefix ( unpolledSessionId . slice ( 0 , 8 ) ) ) . toBe ( true ) ;
855+ expect ( hasNotifyEventForSession ( sessionId ) ) . toBe ( false ) ;
856+ expect ( hasNotifyEventForSession ( unpolledSessionId ) ) . toBe ( true ) ;
853857 } ) ;
854858
855859 it ( "preserves the origin delivery context on background exec completion events" , async ( ) => {
@@ -864,8 +868,8 @@ describe("exec notifyOnExit", () => {
864868 const sessionId = await startBackgroundCommand ( tool , shellEcho ( "notify" ) ) ;
865869
866870 await waitForNotifyEvent ( sessionId , sessionKey ) ;
867- const queuedEvent = peekSystemEventEntries ( sessionKey ) . find ( ( event ) =>
868- event . text . includes ( sessionId . slice ( 0 , 8 ) ) ,
871+ const queuedEvent = peekSystemEventEntries ( sessionKey ) . find (
872+ ( event ) => event . contextKey === `exec: ${ sessionId } ` ,
869873 ) ;
870874
871875 expect ( queuedEvent ) . toBeDefined ( ) ;
0 commit comments