mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
86ccaa6ee4
CRITICAL LEARNING SYSTEM FIXES (4 issues):
- Fixed Q-learning persistence: Database auto-initialization when not provided
- Fixed Database.initialize() call for auto-created instances
- Removed FK constraint on learning_experiences.task_id (architectural fix)
- Fixed SQL syntax: datetime('now', '-7 days') quotes
NEW FEATURES:
- LearningPersistenceAdapter pattern for flexible storage backends
- Auto-initialize Database in LearningEngine when learning enabled
COMPREHENSIVE TEST EXPANSION (44 MCP handler test files):
- Analysis handlers: +1,637 lines across 5 files
- Chaos handlers: +2,094 lines across 3 files
- Coordination handlers: +5,225 lines across 7 files
- Memory handlers: +6,415 lines across 10 files
- Prediction handlers: +3,440 lines across 5 files
- Test handlers: +1,628 lines across 4 files
NEW TEST SUITES (9 total):
- tests/integration/learning-persistence.test.ts (468 lines, 7 tests)
- tests/integration/learning-backward-compat.test.ts
- tests/unit/learning/LearningEngine.database.test.ts
- tests/unit/learning/LearningPersistenceAdapter.test.ts
- tests/core/memory/SwarmMemoryManager.test.ts
- tests/performance/learning-engine-refactor.perf.test.ts
- 3 test helper scripts for Q-learning verification
DOCUMENTATION:
- Updated CHANGELOG.md with learning fixes + test stats
- Added 16 comprehensive reports in docs/ (learning analysis, Q-learning evidence, fixes)
- Cleaned up 6 obsolete release files from root directory
FILES CHANGED:
- Modified: 48 source/test files
- Added: 25 new files (tests + docs)
- Deleted: 6 obsolete release files
- Total: ~22,000 lines added
IMPACT:
✅ Learning system now persists Q-values correctly
✅ Comprehensive MCP handler test coverage
✅ Zero breaking changes (backward compatible)
✅ Documentation verified: 18 QE agents, 34 QE skills, 8 commands
🤖 Generated with Claude Code
https://claude.com/claude-code
Co-Authored-By: Claude <noreply@anthropic.com>
124 lines
4.5 KiB
JavaScript
124 lines
4.5 KiB
JavaScript
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);
|
||
});
|