mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 07:51:52 +00:00
test(memory): add tests for markMemoryMerged and enable dependency injection
- Update `markMemoryMerged` to accept `options.repository` for better testability. - Add unit tests in `test/memory-admin.test.mjs` to verify: - Delegation to repository. - Cache clearing side effect. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
4d11b2b710
commit
78c31e828d
2 files changed
+44
-2
No files matched your search
@@ -330,8 +330,9 @@ export async function unpinMemory(id, options = {}) {
|
||||
* @param {string} id
|
||||
* @param {string} mergedInto
|
||||
*/
|
||||
export async function markMemoryMerged(id, mergedInto) {
|
||||
const merged = await memoryRepository.markMerged(id, mergedInto);
|
||||
export async function markMemoryMerged(id, mergedInto, options = {}) {
|
||||
const repository = options.repository ?? memoryRepository;
|
||||
const merged = await repository.markMerged(id, mergedInto);
|
||||
cache.clear();
|
||||
return merged;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ingestEvents,
|
||||
inspectMemory,
|
||||
listMemories,
|
||||
markMemoryMerged,
|
||||
memoryStats,
|
||||
pinMemory,
|
||||
runPruneCycle,
|
||||
@@ -133,3 +134,43 @@ test('runPruneCycle respects prune feature-flag modes', async () => {
|
||||
assert.equal(offResult.mode, 'off');
|
||||
assert.equal(offResult.pruned.length, 0);
|
||||
});
|
||||
|
||||
test('markMemoryMerged delegates to repository and clears cache', async () => {
|
||||
let callCount = 0;
|
||||
const repository = {
|
||||
async markMerged(id, mergedInto) {
|
||||
callCount++;
|
||||
return id === 'exists';
|
||||
}
|
||||
};
|
||||
|
||||
const result1 = await markMemoryMerged('exists', 'target', { repository });
|
||||
assert.equal(result1, true);
|
||||
assert.equal(callCount, 1);
|
||||
|
||||
const result2 = await markMemoryMerged('missing', 'target', { repository });
|
||||
assert.equal(result2, false);
|
||||
assert.equal(callCount, 2);
|
||||
|
||||
// Verify cache clearing
|
||||
const telemetry = [];
|
||||
const emitTelemetry = (event, payload) => telemetry.push({ event, payload });
|
||||
|
||||
// 1. Populate cache
|
||||
await getRelevantMemories({ agent_id: 'cache-test', emitTelemetry });
|
||||
const hit1 = telemetry.findLast(t => t.event === 'memory:retrieved');
|
||||
assert.equal(hit1.payload.cache_hit, false);
|
||||
|
||||
// 2. Hit cache
|
||||
await getRelevantMemories({ agent_id: 'cache-test', emitTelemetry });
|
||||
const hit2 = telemetry.findLast(t => t.event === 'memory:retrieved');
|
||||
assert.equal(hit2.payload.cache_hit, true);
|
||||
|
||||
// 3. Clear cache via side-effect
|
||||
await markMemoryMerged('exists', 'target', { repository });
|
||||
|
||||
// 4. Miss cache
|
||||
await getRelevantMemories({ agent_id: 'cache-test', emitTelemetry });
|
||||
const hit3 = telemetry.findLast(t => t.event === 'memory:retrieved');
|
||||
assert.equal(hit3.payload.cache_hit, false);
|
||||
});
|
||||
Reference in new issue
Block a user