@@ -44,6 +44,13 @@ function createOps(params: {
4444 broadcast : ReturnType < typeof vi . fn > ;
4545 nodeSendToSession : ReturnType < typeof vi . fn > ;
4646 removeChatRun : ReturnType < typeof vi . fn > ;
47+ clearedState : {
48+ chatDeltaSentAt : Map < string , number > ;
49+ chatDeltaLastBroadcastLen : Map < string , number > ;
50+ chatDeltaLastBroadcastText : Map < string , string > ;
51+ agentDeltaSentAt : Map < string , number > ;
52+ bufferedAgentEvents : Map < string , unknown > ;
53+ } ;
4754} {
4855 const { runId, entry, buffer } = params ;
4956 const broadcast = vi . fn ( ) ;
@@ -54,7 +61,7 @@ function createOps(params: {
5461 const chatDeltaLastBroadcastLen = new Map ( [ [ runId , buffer ?. length ?? 0 ] ] ) ;
5562 const chatDeltaLastBroadcastText = new Map ( buffer !== undefined ? [ [ runId , buffer ] ] : [ ] ) ;
5663 const agentDeltaSentAt = new Map ( [ [ `${ runId } :assistant` , Date . now ( ) ] ] ) ;
57- const bufferedAgentEvents : ChatAbortOps [ "bufferedAgentEvents" ] = new Map ( [
64+ const bufferedAgentEvents = new Map < string , unknown > ( [
5865 [
5966 `${ runId } :assistant` ,
6067 {
@@ -72,11 +79,6 @@ function createOps(params: {
7279 return {
7380 chatAbortControllers : new Map ( [ [ runId , entry ] ] ) ,
7481 chatRunBuffers,
75- chatDeltaSentAt,
76- chatDeltaLastBroadcastLen,
77- chatDeltaLastBroadcastText,
78- agentDeltaSentAt,
79- bufferedAgentEvents,
8082 chatAbortedRuns : new Map ( ) ,
8183 clearChatRunState : ( id : string ) => {
8284 chatRunBuffers . delete ( id ) ;
@@ -92,6 +94,13 @@ function createOps(params: {
9294 agentRunSeq : new Map ( ) ,
9395 broadcast,
9496 nodeSendToSession,
97+ clearedState : {
98+ chatDeltaSentAt,
99+ chatDeltaLastBroadcastLen,
100+ chatDeltaLastBroadcastText,
101+ agentDeltaSentAt,
102+ bufferedAgentEvents,
103+ } ,
95104 } ;
96105}
97106
@@ -142,11 +151,11 @@ describe("abortChatRunById", () => {
142151 expect ( entry . controller . signal . aborted ) . toBe ( true ) ;
143152 expect ( ops . chatAbortControllers . has ( runId ) ) . toBe ( false ) ;
144153 expect ( ops . chatRunBuffers . has ( runId ) ) . toBe ( false ) ;
145- expect ( ops . chatDeltaSentAt . has ( runId ) ) . toBe ( false ) ;
146- expect ( ops . chatDeltaLastBroadcastLen . has ( runId ) ) . toBe ( false ) ;
147- expect ( ops . chatDeltaLastBroadcastText . has ( runId ) ) . toBe ( false ) ;
148- expect ( ops . agentDeltaSentAt ? .has ( `${ runId } :assistant` ) ) . toBe ( false ) ;
149- expect ( ops . bufferedAgentEvents ? .has ( `${ runId } :assistant` ) ) . toBe ( false ) ;
154+ expect ( ops . clearedState . chatDeltaSentAt . has ( runId ) ) . toBe ( false ) ;
155+ expect ( ops . clearedState . chatDeltaLastBroadcastLen . has ( runId ) ) . toBe ( false ) ;
156+ expect ( ops . clearedState . chatDeltaLastBroadcastText . has ( runId ) ) . toBe ( false ) ;
157+ expect ( ops . clearedState . agentDeltaSentAt . has ( `${ runId } :assistant` ) ) . toBe ( false ) ;
158+ expect ( ops . clearedState . bufferedAgentEvents . has ( `${ runId } :assistant` ) ) . toBe ( false ) ;
150159 expect ( ops . removeChatRun ) . toHaveBeenCalledWith ( runId , runId , sessionKey ) ;
151160 expect ( ops . agentRunSeq . has ( runId ) ) . toBe ( false ) ;
152161 expect ( ops . agentRunSeq . has ( "client-run-1" ) ) . toBe ( false ) ;
0 commit comments