@@ -219,6 +219,38 @@ describe('agent() PromptEngine/Memory/Skills integration', () => {
219219 const combined = systemMsgs . map ( ( m : any ) => m . content ) . join ( '\n' ) ;
220220 expect ( combined ) . toContain ( 'Memory: user likes hiking' ) ;
221221 } ) ;
222+
223+ it ( 'calls getContext before direct agent.stream() (new in 0.2.0)' , async ( ) => {
224+ const memory = createMockMemory ( ) ;
225+ const a = agent ( { instructions : 'test' , memoryProvider : memory } ) ;
226+
227+ const streamResult = a . stream ( 'hello from stream' ) ;
228+ // Drain the stream to ensure generation completes
229+ for await ( const _chunk of streamResult . textStream ) {
230+ // consume
231+ }
232+ await streamResult . text ;
233+
234+ expect ( memory . getContext ) . toHaveBeenCalledWith (
235+ 'hello from stream' ,
236+ expect . objectContaining ( { tokenBudget : expect . any ( Number ) } ) ,
237+ ) ;
238+ } ) ;
239+
240+ it ( 'calls observe after direct agent.stream() completes (new in 0.2.0)' , async ( ) => {
241+ const memory = createMockMemory ( ) ;
242+ const a = agent ( { instructions : 'test' , memoryProvider : memory } ) ;
243+
244+ const streamResult = a . stream ( 'hello from stream' ) ;
245+ for await ( const _chunk of streamResult . textStream ) {
246+ // consume
247+ }
248+ await streamResult . text ;
249+ await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ;
250+
251+ expect ( memory . observe ) . toHaveBeenCalledWith ( 'user' , 'hello from stream' ) ;
252+ expect ( memory . observe ) . toHaveBeenCalledWith ( 'assistant' , 'streamed' ) ;
253+ } ) ;
222254 } ) ;
223255
224256 describe ( 'all three compose together' , ( ) => {
0 commit comments