@@ -3373,5 +3373,104 @@ describe('LocalAgentExecutor', () => {
33733373 const uniqueNames = new Set ( names ) ;
33743374 expect ( uniqueNames . size ) . toBe ( names . length ) ;
33753375 } ) ;
3376+
3377+ describe ( 'Memory Injection' , ( ) => {
3378+ it ( 'should inject system instruction memory into system prompt' , async ( ) => {
3379+ const definition = createTestDefinition ( ) ;
3380+ const executor = await LocalAgentExecutor . create (
3381+ definition ,
3382+ mockConfig ,
3383+ onActivity ,
3384+ ) ;
3385+
3386+ const mockMemory = 'Global memory constraint' ;
3387+ vi . spyOn ( mockConfig , 'getSystemInstructionMemory' ) . mockReturnValue (
3388+ mockMemory ,
3389+ ) ;
3390+
3391+ mockModelResponse ( [
3392+ {
3393+ name : TASK_COMPLETE_TOOL_NAME ,
3394+ args : { finalResult : 'done' } ,
3395+ id : 'call1' ,
3396+ } ,
3397+ ] ) ;
3398+
3399+ await executor . run ( { goal : 'test' } , signal ) ;
3400+
3401+ const chatConstructorArgs = MockedGeminiChat . mock . calls [ 0 ] ;
3402+ const systemInstruction = chatConstructorArgs [ 1 ] as string ;
3403+
3404+ expect ( systemInstruction ) . toContain ( mockMemory ) ;
3405+ expect ( systemInstruction ) . toContain ( '<loaded_context>' ) ;
3406+ } ) ;
3407+
3408+ it ( 'should inject environment memory into the first message when JIT is disabled' , async ( ) => {
3409+ const definition = createTestDefinition ( ) ;
3410+ const executor = await LocalAgentExecutor . create (
3411+ definition ,
3412+ mockConfig ,
3413+ onActivity ,
3414+ ) ;
3415+
3416+ const mockMemory = 'Project memory rule' ;
3417+ vi . spyOn ( mockConfig , 'getEnvironmentMemory' ) . mockReturnValue (
3418+ mockMemory ,
3419+ ) ;
3420+ vi . spyOn ( mockConfig , 'isJitContextEnabled' ) . mockReturnValue ( false ) ;
3421+
3422+ mockModelResponse ( [
3423+ {
3424+ name : TASK_COMPLETE_TOOL_NAME ,
3425+ args : { finalResult : 'done' } ,
3426+ id : 'call1' ,
3427+ } ,
3428+ ] ) ;
3429+
3430+ await executor . run ( { goal : 'test' } , signal ) ;
3431+
3432+ const { message } = getMockMessageParams ( 0 ) ;
3433+ const parts = message as Part [ ] ;
3434+
3435+ expect ( parts ) . toBeDefined ( ) ;
3436+ const memoryPart = parts . find ( ( p ) => p . text ?. includes ( mockMemory ) ) ;
3437+ expect ( memoryPart ) . toBeDefined ( ) ;
3438+ expect ( memoryPart ?. text ) . toBe ( mockMemory ) ;
3439+ } ) ;
3440+
3441+ it ( 'should inject session memory into the first message when JIT is enabled' , async ( ) => {
3442+ const definition = createTestDefinition ( ) ;
3443+ const executor = await LocalAgentExecutor . create (
3444+ definition ,
3445+ mockConfig ,
3446+ onActivity ,
3447+ ) ;
3448+
3449+ const mockMemory =
3450+ '<loaded_context>\nExtension memory rule\n</loaded_context>' ;
3451+ vi . spyOn ( mockConfig , 'getSessionMemory' ) . mockReturnValue ( mockMemory ) ;
3452+ vi . spyOn ( mockConfig , 'isJitContextEnabled' ) . mockReturnValue ( true ) ;
3453+
3454+ mockModelResponse ( [
3455+ {
3456+ name : TASK_COMPLETE_TOOL_NAME ,
3457+ args : { finalResult : 'done' } ,
3458+ id : 'call1' ,
3459+ } ,
3460+ ] ) ;
3461+
3462+ await executor . run ( { goal : 'test' } , signal ) ;
3463+
3464+ const { message } = getMockMessageParams ( 0 ) ;
3465+ const parts = message as Part [ ] ;
3466+
3467+ expect ( parts ) . toBeDefined ( ) ;
3468+ const memoryPart = parts . find ( ( p ) =>
3469+ p . text ?. includes ( 'Extension memory rule' ) ,
3470+ ) ;
3471+ expect ( memoryPart ) . toBeDefined ( ) ;
3472+ expect ( memoryPart ?. text ) . toContain ( mockMemory ) ;
3473+ } ) ;
3474+ } ) ;
33763475 } ) ;
33773476} ) ;
0 commit comments