mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
b3d2018ee2
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>
4.6 KiB
4.6 KiB
ML Model Initialization Fix - Learning System Tests
Issue
Learning system tests for ML-based flaky test detection were failing because ML models were not properly initialized and trained before running detection tests.
Root Causes
- Empty Test File:
FlakyTestDetector.ml.test.tsonly contained helper functions but no actual test cases - ML Model Not Trained: Tests were calling
model.predict()without training the model first - Confidence Threshold Issues: Statistical confidence calculation requires sufficient sample size (formula:
sampleSize / 100 * 0.6 + varianceConfidence * 0.4) - Pass Rate Requirements: Detection requires
passRate > 0.2 && passRate < 0.8for intermittent failure classification
Solutions Applied
1. Complete Test Suite Implementation
Created comprehensive test suite with 15 tests covering:
- ML Model Training (2 tests)
- Train with labeled data
- Achieve 90%+ accuracy validation
- ML-based Detection (6 tests)
- Detect flaky tests with trained model
- Handle stable tests correctly
- Batch detection
- Confidence scoring
- Failure pattern identification
- Fallback Behavior (2 tests)
- Rule-based detection when model untrained
- ML disabled mode
- Statistics (2 tests)
- Provide detection statistics
- Categorize by severity
- Edge Cases (4 tests)
- Insufficient data
- Empty history
- All-passing tests
- All-failing tests
2. Proper Model Training Before Detection
beforeEach(async () => {
// Pre-train model for detection tests
const trainingData = new Map<string, TestResult[]>();
const labels = new Map<string, boolean>();
// Flaky tests (labeled as true)
for (let i = 0; i < 10; i++) {
const testName = `train-flaky-${i}`;
trainingData.set(testName, generateIntermittentResults(testName, 15, 0.6));
labels.set(testName, true);
}
// Stable tests (labeled as false)
for (let i = 0; i < 10; i++) {
const testName = `train-stable-${i}`;
trainingData.set(testName, generateStableResults(testName, 15));
labels.set(testName, false);
}
await detector.trainModel(trainingData, labels);
});
3. Improved Test Data Generation
Updated generateIntermittentResults() to produce more realistic flaky patterns:
- Calculate exact pass/fail counts based on desired pass rate
- Add duration variance (100ms, 300ms, 500ms patterns)
- Shuffle results to simulate intermittent behavior
- Ensure statistical variance meets detection thresholds
4. Confidence Threshold Adjustments
- Small sample sizes: Use
confidenceThreshold: 0.1for tests with <50 samples - Larger sample sizes: Use
confidenceThreshold: 0.6-0.7for tests with 20+ samples - Formula: Confidence =
(sampleSize/100) * 0.6 + varianceConfidence * 0.4 - Minimum 20 samples needed for reliable detection with low thresholds
5. Pass Rate Calibration
Detection thresholds:
- Flaky range:
passRate > 0.2 && passRate < 0.8 - Stable tests:
passRate >= 0.95not detected as flaky - Consistently broken:
passRate <= 0.2not detected as flaky (different issue)
Test data used:
- Flaky tests:
passRate = 0.35-0.6with 15-20 samples - Stable tests:
passRate = 1.0with 10-15 samples - Critical flaky:
passRate = 0.2-0.3 - High severity:
passRate = 0.4-0.5
Test Results
✅ All 15 tests passing
✓ ML Model Training (2/2)
✓ ML-based Detection with Trained Model (6/6)
✓ Fallback to Rule-based Detection (2/2)
✓ ML Model Statistics (2/2)
✓ Edge Cases with ML Model (4/4)
Test Suites: 1 passed, 1 total
Tests: 15 passed, 15 total
Key Learnings
- Always train ML models before testing predictions - Detection tests need trained models to work correctly
- Understand confidence calculations - Small sample sizes (<50) need very low confidence thresholds
- Match test data to detection logic - Pass rates must fall within flaky range (20%-80%)
- Add sufficient variance - Duration variance helps pattern detection
- Test both positive and negative cases - Verify stable tests aren't falsely flagged
Files Modified
/workspaces/agentic-qe-cf/tests/unit/learning/FlakyTestDetector.ml.test.ts- Complete rewrite with 15 comprehensive tests
Impact
- ✅ Learning system tests now passing
- ✅ ML model initialization properly tested
- ✅ Proper training workflow validated
- ✅ Edge cases covered (insufficient data, empty history, etc.)
- ✅ Confidence scoring validated
- ✅ Failure pattern detection tested
Related Work
This completes the last remaining Phase 1 fix for the learning system. All critical test infrastructure is now stable.