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>
159 lines
5.4 KiB
JavaScript
159 lines
5.4 KiB
JavaScript
const path = require('path');
|
|
const db = require('better-sqlite3');
|
|
|
|
async function testRealQLearning() {
|
|
console.log('=== TESTING REAL Q-LEARNING PERSISTENCE ===\n');
|
|
|
|
const { AgentRegistry } = require('./dist/mcp/services/AgentRegistry.js');
|
|
const { TaskAssignment, TaskPriority } = require('./dist/types');
|
|
|
|
const dbPath = path.join(process.cwd(), '.agentic-qe/memory.db');
|
|
console.log('📁 Database path:', dbPath, '\n');
|
|
|
|
// Check initial state
|
|
const checkDb = db(dbPath, { readonly: true });
|
|
const initialQValues = checkDb.prepare('SELECT COUNT(*) as count FROM q_values').get();
|
|
const initialExperiences = checkDb.prepare('SELECT COUNT(*) as count FROM learning_experiences').get();
|
|
checkDb.close();
|
|
|
|
console.log('📊 BEFORE Task Execution:');
|
|
console.log(' Q-values:', initialQValues.count);
|
|
console.log(' Experiences:', initialExperiences.count);
|
|
console.log('');
|
|
|
|
try {
|
|
// Create registry
|
|
const registry = new AgentRegistry({
|
|
maxAgents: 10,
|
|
enableMetrics: true
|
|
});
|
|
|
|
// Wait for initialization
|
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
|
|
// Spawn test generator agent
|
|
console.log('🚀 Spawning test-generator agent...\n');
|
|
const { id, agent } = await registry.spawnAgent('test-generator', {
|
|
name: 'TestGen-QLearning',
|
|
capabilities: ['unit-test-generation']
|
|
});
|
|
|
|
console.log('✅ Agent spawned:');
|
|
console.log(' ID:', id);
|
|
console.log(' Has learningEngine:', !!agent.learningEngine);
|
|
console.log(' Learning enabled:', agent.learningEngine?.isEnabled());
|
|
console.log('');
|
|
|
|
// Create proper TaskAssignment
|
|
const taskAssignment = {
|
|
id: `task-${Date.now()}`,
|
|
agentId: id,
|
|
task: {
|
|
type: 'unit-test-generation',
|
|
description: 'Generate unit tests for a simple utility function',
|
|
targetFile: 'src/utils/Logger.ts',
|
|
framework: 'jest',
|
|
coverage: true
|
|
},
|
|
priority: 'medium',
|
|
assignedAt: new Date(),
|
|
status: 'pending'
|
|
};
|
|
|
|
console.log('📝 Executing task with proper TaskAssignment...\n');
|
|
|
|
// Execute via agent's executeTask method (which triggers onPostTask hook)
|
|
const result = await agent.executeTask(taskAssignment.task);
|
|
|
|
console.log('✅ Task execution completed:');
|
|
console.log(' Status:', result.status || 'completed');
|
|
console.log(' Success:', result.success !== false);
|
|
console.log('');
|
|
|
|
// Wait for async persistence
|
|
console.log('⏳ Waiting for Q-learning persistence (2 seconds)...\n');
|
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
|
|
// Check database after execution
|
|
const checkDbAfter = db(dbPath, { readonly: true });
|
|
const finalQValues = checkDbAfter.prepare('SELECT COUNT(*) as count FROM q_values').get();
|
|
const finalExperiences = checkDbAfter.prepare('SELECT COUNT(*) as count FROM learning_experiences').get();
|
|
|
|
console.log('📊 AFTER Task Execution:');
|
|
console.log(' Q-values:', finalQValues.count);
|
|
console.log(' Experiences:', finalExperiences.count);
|
|
console.log('');
|
|
|
|
// Show the difference
|
|
const qValuesDelta = finalQValues.count - initialQValues.count;
|
|
const experiencesDelta = finalExperiences.count - initialExperiences.count;
|
|
|
|
if (qValuesDelta > 0 || experiencesDelta > 0) {
|
|
console.log('🎉 SUCCESS! Q-Learning data WAS persisted:');
|
|
console.log(' Q-values: +' + qValuesDelta + ' entries');
|
|
console.log(' Experiences: +' + experiencesDelta + ' entries');
|
|
console.log('');
|
|
|
|
// Show sample Q-value
|
|
if (finalQValues.count > 0) {
|
|
const qvalue = checkDbAfter.prepare(`
|
|
SELECT agent_id, state_key, action_key, q_value, visit_count
|
|
FROM q_values
|
|
ORDER BY updated_at DESC
|
|
LIMIT 1
|
|
`).get();
|
|
|
|
console.log('📈 Sample Q-Value (most recent):');
|
|
console.log(' Agent:', qvalue.agent_id);
|
|
console.log(' State:', qvalue.state_key.substring(0, 60) + '...');
|
|
console.log(' Action:', qvalue.action_key.substring(0, 60) + '...');
|
|
console.log(' Q-value:', qvalue.q_value.toFixed(4));
|
|
console.log(' Visits:', qvalue.visit_count);
|
|
console.log('');
|
|
}
|
|
|
|
// Show sample experience
|
|
if (finalExperiences.count > 0) {
|
|
const exp = checkDbAfter.prepare(`
|
|
SELECT agent_id, task_type, reward, outcome
|
|
FROM learning_experiences
|
|
ORDER BY timestamp DESC
|
|
LIMIT 1
|
|
`).get();
|
|
|
|
console.log('🧪 Sample Experience (most recent):');
|
|
console.log(' Agent:', exp.agent_id);
|
|
console.log(' Task Type:', exp.task_type);
|
|
console.log(' Reward:', exp.reward.toFixed(4));
|
|
console.log(' Outcome:', exp.outcome);
|
|
console.log('');
|
|
}
|
|
} else {
|
|
console.log('⚠️ NO Q-learning data persisted');
|
|
console.log(' This indicates the onPostTask hook may not have triggered');
|
|
console.log('');
|
|
}
|
|
|
|
checkDbAfter.close();
|
|
|
|
// Clean up
|
|
await registry.terminateAgent(id);
|
|
console.log('✅ Agent terminated successfully');
|
|
|
|
} catch (error) {
|
|
console.error('\n❌ ERROR:', error.message);
|
|
console.error(error.stack);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
testRealQLearning()
|
|
.then(() => {
|
|
console.log('\n✅ Test completed successfully');
|
|
process.exit(0);
|
|
})
|
|
.catch(error => {
|
|
console.error('\n❌ Test failed:', error);
|
|
process.exit(1);
|
|
});
|