@@ -15,6 +15,59 @@ import { chatHistoryHandlers } from "./chat-history-handler.js";
1515import type { GatewayRequestContext , RespondFn } from "./types.js" ;
1616
1717describe ( "chat history consumption receipts" , ( ) => {
18+ it ( "projects pending input at its acceptance time" , async ( ) => {
19+ await withOpenClawTestState ( { scenario : "minimal" } , async ( ) => {
20+ const now = vi . spyOn ( Date , "now" ) . mockReturnValue ( 2_000 ) ;
21+ const scope = {
22+ agentId : "main" ,
23+ sessionKey : "agent:main:pending-display-time" ,
24+ sessionId : "pending-display-time" ,
25+ } ;
26+ await upsertSessionEntryCore ( scope , { sessionId : scope . sessionId , updatedAt : 1 } ) ;
27+ const receipt = expectDefined (
28+ await stageSessionPendingInput ( scope , {
29+ runId : "pending-display-run" ,
30+ assertCurrent : ( ) => { } ,
31+ message : {
32+ role : "user" ,
33+ content : "Display me where I was accepted" ,
34+ timestamp : 1_000 ,
35+ idempotencyKey : "pending-display-run:user" ,
36+ } ,
37+ } ) ,
38+ "pending input receipt" ,
39+ ) ;
40+ try {
41+ let result : unknown ;
42+ await expectDefined (
43+ chatHistoryHandlers [ "chat.history" ] ,
44+ "history handler" ,
45+ ) ( {
46+ params : { sessionKey : scope . sessionKey } ,
47+ context : createDirectChatContext ( ) ,
48+ req : { type : "req" , id : "history" , method : "chat.history" } ,
49+ client : null ,
50+ isWebchatConnect : ( ) => false ,
51+ respond : ( ok , payload , error ) => {
52+ expect ( error ) . toBeUndefined ( ) ;
53+ expect ( ok ) . toBe ( true ) ;
54+ result = payload ;
55+ } ,
56+ } ) ;
57+ const page = expectDefined ( asOptionalRecord ( result ) , "history response" ) ;
58+ const pendingInputs = expectDefined ( asOptionalRecord ( page . pendingInputs ) , "pending inputs" ) ;
59+ const [ pending ] = pendingInputs . items as Array < Record < string , unknown > > ;
60+ expect ( pending ) . toMatchObject ( {
61+ acceptedAt : 2_000 ,
62+ message : { content : "Display me where I was accepted" , timestamp : 2_000 } ,
63+ } ) ;
64+ } finally {
65+ receipt . finish ( "interrupted" ) ;
66+ now . mockRestore ( ) ;
67+ }
68+ } ) ;
69+ } ) ;
70+
1871 it . each ( [ "chat.history" , "chat.startup" ] as const ) (
1972 "%s returns only requested current-session receipts in pages and empty deltas" ,
2073 async ( method ) => {
0 commit comments