Files
proffesor-for-testing__agen…/scripts/test-agent-persistence.js
Profa b3d2018ee2 feat: v1.8.0 - Quality Hardening & Pattern Isolation
Critical bug fixes and code quality improvements from brutal-honest-review.

## Critical Fixes (9/10 completed, 1 deferred)

1. Fixed Agent Pattern Isolation (CRITICAL)
   - Added SwarmMemoryManager.queryPatternsByAgent()
   - SQL filtering by agent_id in metadata
   - Each agent now isolated

2. Fixed Async Method Cascade
   - Changed getPatterns() to async
   - Fixed 10 callers across 6 files
   - Build passes

3. Fixed Misleading Logging
   - Added isRealAgentDB() detection
   - Honest mock vs real reporting

4. Consolidated Embedding Generation
   - Created EmbeddingGenerator utility
   - Removed 50+ duplicate lines

5. Added AgentDB Initialization Checks
   - Empty DB detection
   - HNSW index verification

6. Integration Test Suite
   - 26 new test cases
   - Error path coverage

7. Repository Cleanup
   - Removed 19 temp test files

8. New QE Skill: sherlock-review
   - Evidence-based investigative review
   - 38 QE skills total

9. Deferred: Wire Up Real Test Execution
   - Deferred to v1.9.0 (documented)

## Statistics
- Fixes: 9/10 (90%, 1 deferred)
- Files Modified: 16
- Files Created: 3
- Files Deleted: 19
- Integration Tests: 26
- Build: PASSING

## Breaking Changes
- getPatterns() now async - add await

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-17 12:32:03 +00:00

124 lines
4.5 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const path = require('path');
const db = require('better-sqlite3');
async function testAgentPersistence() {
console.log('=== TESTING QE AGENT PERSISTENCE ===\n');
// Import modules
const { AgentRegistry } = require('../dist/mcp/services/AgentRegistry.js');
const dbPath = path.join(process.cwd(), '.agentic-qe/memory.db');
console.log('📁 Database path:', dbPath, '\n');
// Check initial state (skip if database doesn't exist yet)
let initialQValues = { count: 0 };
let initialExperiences = { count: 0 };
if (require('fs').existsSync(dbPath)) {
const checkDb = db(dbPath, { readonly: true });
initialQValues = checkDb.prepare('SELECT COUNT(*) as count FROM q_values').get();
initialExperiences = checkDb.prepare('SELECT COUNT(*) as count FROM learning_experiences').get();
checkDb.close();
}
console.log('📊 BEFORE Agent Execution:');
console.log(' Q-values:', initialQValues.count);
console.log(' Experiences:', initialExperiences.count);
console.log('\n🤖 Spawning QE Agent via AgentRegistry...\n');
try {
// Create registry
const registry = new AgentRegistry({
maxAgents: 10,
enableMetrics: true
});
// Wait for memory store initialization
console.log('⏳ Waiting for memory store initialization...');
await new Promise(resolve => setTimeout(resolve, 2000));
// Spawn test generator agent
console.log('🚀 Spawning test-generator agent...');
const { id, agent } = await registry.spawnAgent('test-generator', {
name: 'TestGen-Persistence-Test',
description: 'Agent for testing persistence',
capabilities: ['unit-test-generation']
});
console.log('✅ Agent spawned successfully!');
console.log(' Agent ID:', id);
console.log(' Has learningEngine:', !!agent.learningEngine);
if (agent.learningEngine) {
console.log(' Learning enabled:', agent.learningEngine.isEnabled());
}
console.log('\n📝 Executing test task...\n');
// Create a simple task
const task = {
id: 'task-' + Date.now(),
type: 'unit-test-generation',
targetFile: 'src/learning/LearningEngine.ts',
framework: 'jest'
};
// Execute task
const result = await registry.executeTask(id, task);
console.log('✅ Task completed!');
console.log(' Success:', result.success);
// Wait for async persistence
console.log('\n⏳ Waiting for data persistence...');
await new Promise(resolve => setTimeout(resolve, 1500));
console.log('\n📊 AFTER Agent Execution:\n');
// Check database again
const checkDbAfter = db(dbPath, { readonly: true });
const qValues = checkDbAfter.prepare('SELECT COUNT(*) as count FROM q_values').get();
const experiences = checkDbAfter.prepare('SELECT COUNT(*) as count FROM learning_experiences').get();
console.log('📈 Q-VALUES:', qValues.count, 'entries');
console.log('🧪 EXPERIENCES:', experiences.count, 'entries');
if (qValues.count > initialQValues.count || experiences.count > initialExperiences.count) {
console.log('\n✅ SUCCESS: Data WAS persisted!');
console.log(' Q-values: ' + initialQValues.count + ' → ' + qValues.count);
console.log(' Experiences: ' + initialExperiences.count + ' → ' + experiences.count);
if (qValues.count > 0) {
console.log('\n📋 Sample Q-value:');
const sample = checkDbAfter.prepare('SELECT agent_id, state_key, action_key, q_value FROM q_values LIMIT 1').get();
console.log(' Agent:', sample.agent_id);
console.log(' State:', sample.state_key.substring(0, 80));
console.log(' Action:', sample.action_key.substring(0, 80));
console.log(' Q-value:', sample.q_value);
}
if (experiences.count > 0) {
console.log('\n📋 Sample Experience:');
const sample = checkDbAfter.prepare('SELECT agent_id, task_type, reward FROM learning_experiences LIMIT 1').get();
console.log(' Agent:', sample.agent_id);
console.log(' Task:', sample.task_type);
console.log(' Reward:', sample.reward);
}
} else {
console.log('\n⚠️ NO NEW DATA persisted');
console.log(' This may indicate learning is not enabled or task did not trigger learning hooks');
}
checkDbAfter.close();
} catch (error) {
console.error('\n❌ ERROR:', error.message);
console.error(error.stack);
}
}
testAgentPersistence()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});