Merge pull request #234 from PR0M3TH3AN/test-memory-formatter-circular-context-16916269218151396900

🧪 Add test for circular agentContext in renderPromptWithMemoryContext
This commit is contained in:
thePR0M3TH3AN authored and GitHub committed 2026-02-17 13:37:29 -05:00
commit d3926f8a36
1 file changed
+31
+31
View File
@@ -193,3 +193,34 @@ test('renderPromptWithMemoryContext handles missing query or service', async ()
const output = await renderPromptWithMemoryContext(params);
assert.equal(output, 'Base prompt');
});
test('renderPromptWithMemoryContext handles circular agentContext gracefully', async () => {
const circular = {};
circular.self = circular;
let capturedQuery = '';
const memoryService = {
async getRelevantMemories({ query }) {
capturedQuery = query;
return [];
},
async updateMemoryUsage() {}
};
const params = {
basePrompt: 'Base prompt',
userRequest: 'Hello',
agentContext: circular,
agent_id: 'agent-1',
memoryService,
env: { TORCH_MEMORY_RETRIEVAL_ENABLED: 'true' }
};
const output = await renderPromptWithMemoryContext(params);
// It should not throw.
// The query should contain the string representation of the circular object.
// String(circular) is "[object Object]"
assert.ok(capturedQuery.includes('[object Object]'), 'Query should contain the stringified circular object fallback');
assert.ok(output.includes('Base prompt'), 'Output should contain the base prompt');
});