Files
proffesor-for-testing__agen…/docs/migration/issue-103-implementation-plan.md
Profa 08568286ef refactor(tests): aggressive test suite consolidation (-60% lines, -54% files)
Major test suite migration and cleanup completing Issue #103:

## Metrics
- Files: 426 → 197 (-229 files, -53.8%)
- Lines: 208,253 → 82,698 (-125,555 lines, -60.3%)
- Large files (>600 lines): 149 → 25 (-83.2%)
- Skipped tests: 7 → 0 (-100%)

## Categories Deleted
- Phase 1/2/3 milestone tests (superseded by journey tests)
- MCP handler implementation tests (covered by contract tests)
- Comprehensive/exhaustive internal tests
- Duplicate algorithm tests (Q-learning, SARSA, Actor-Critic)
- Internal utility tests (Logger, migration tools)
- Mock-based tests with no real integration value

## High-Value Tests Preserved
- 7 journey tests (user workflows)
- CLI tests (user-facing commands)
- E2E tests (end-to-end workflows)
- Core infrastructure tests (memory, hooks, privacy)
- MCP contract tests (API stability)
- Unique integration tests (neural, multi-agent)

## New CI/CD Infrastructure
- .github/workflows/optimized-ci.yml (parallel jobs)
- scripts/test-dashboard.js (metrics visualization)
- scripts/test-ci-optimized.sh (batched execution)
- New test scripts: test:journeys, test:contracts, test:fast

## Coverage Thresholds
- Global: 80% lines, 75% branches
- Critical paths (core/, agents/): 85% coverage

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-08 07:22:53 +00:00

229 lines
7.1 KiB
Markdown

# Issue #103: Test Suite Migration Implementation Plan
**Analysis Date**: 2025-12-07
**Issue**: https://github.com/proffesor-for-testing/agentic-qe/issues/103
---
## Current State Analysis
### Key Finding: Test Suite Has GROWN (Not Shrunk)
| Metric | Baseline (Issue) | Current | Change |
|--------|-----------------|---------|--------|
| **Test Files** | 402 | 426 | +24 (+6%) |
| **Total Lines** | 195,527 | 208,253 | +12,726 (+6.5%) |
| **Files > 600 Lines** | ~67 | 149 | +82 (122% increase) |
| **Files > 1000 Lines** | 18 | 20+ | +2 |
| **Skipped Tests** | 7 | 7 | No change |
**Critical**: The problem is getting WORSE, not better. Migration has not started.
### Largest Test Files (>1000 lines)
| File | Lines | Issue |
|------|-------|-------|
| `TestGeneratorAgent.null-safety.test.ts` | 1,539 | Tests TypeScript semantics (DELETE) |
| `TestGeneratorAgent.comprehensive.test.ts` | 1,476 | Duplicate coverage (CONSOLIDATE) |
| `RequirementsValidatorAgent.test.ts` | 1,375 | Monolithic (SPLIT) |
| `TestDataArchitectAgent.test.ts` | 1,303 | Monolithic (SPLIT) |
| `BaseAgent.test.ts` | 1,275 | Duplicate coverage (CONSOLIDATE) |
| `DeploymentReadinessAgent.test.ts` | 1,217 | Monolithic (SPLIT) |
| `api-contract-validator-integration.test.ts` | 1,170 | OK for integration |
| `LearningEngine.test.ts` | 1,151 | Duplicate coverage (CONSOLIDATE) |
### What Exists (Setup Work Done)
- ✅ `docs/migration/test-suite-restructuring-plan.md` - Full 5-phase plan
- ✅ `docs/migration/progress-tracking.md` - Tracking document (shows 0%)
- ✅ `.github/workflows/migration-validation.yml` - CI workflow ready
- ✅ `scripts/analyze-test-duplicates.ts` - Duplicate analysis script
### What's Missing (Phase 1 Not Started)
- ❌ No `tests/journeys/` directory
- ❌ No `tests/contracts/` directory
- ❌ No `tests/infrastructure/` directory
- ❌ No baseline coverage report saved
- ❌ No test mapping document
- ❌ 0% progress on all 5 phases
---
## Implementation Plan
### Phase 1: Setup & Directory Structure (2-3 hours)
**Priority: Immediate**
#### 1.1 Create Directory Structure
```bash
mkdir -p tests/{journeys,contracts,infrastructure,regression/fixed-bugs}
touch tests/journeys/.gitkeep
touch tests/contracts/.gitkeep
touch tests/infrastructure/.gitkeep
touch tests/regression/fixed-bugs/.gitkeep
```
#### 1.2 Run Baseline Analysis
```bash
# Run duplicate analysis script
npx tsx scripts/analyze-test-duplicates.ts
# Save baseline coverage
npm run test:unit -- --coverage --coverageDirectory=docs/migration/baseline-coverage
```
#### 1.3 Create Test Mapping
Generate `docs/migration/test-mapping.md` mapping each of 426 files to:
- JOURNEY → `tests/journeys/`
- CONTRACT → `tests/contracts/`
- INFRASTRUCTURE → `tests/infrastructure/`
- DELETE → Remove entirely
#### 1.4 Update Progress Tracking
Update `docs/migration/progress-tracking.md` with current (worse) metrics.
---
### Phase 2: Quick Wins - Delete High-Value Targets (2-3 hours)
**Priority: High - Immediate LOC reduction**
#### 2.1 Delete "Null Safety" Test (~1,539 lines)
```bash
git rm tests/unit/agents/TestGeneratorAgent.null-safety.test.ts
```
**Reason**: Tests TypeScript compiler behavior, not business logic.
#### 2.2 Delete Skipped Tests in `disabled/` (~9 files)
```bash
rm -rf tests/disabled/until-implementations/
```
**Reason**: Already skipped, blocking CI, no user value.
#### 2.3 Verify No Coverage Drop
```bash
npm run test:unit -- --coverage
# Compare with baseline
```
**Expected Reduction**: ~3,000+ lines immediately
---
### Phase 3: Create 7 Journey Tests (8-12 hours)
**Priority: Critical - These replace 70% of current tests**
| Journey | File | Focus |
|---------|------|-------|
| 1. Init & Bootstrap | `tests/journeys/init-bootstrap.test.ts` | `aqe init` workflow |
| 2. Test Generation | `tests/journeys/test-generation.test.ts` | End-to-end generation |
| 3. Test Execution | `tests/journeys/test-execution.test.ts` | Parallel execution |
| 4. Coverage Analysis | `tests/journeys/coverage-analysis.test.ts` | O(log n) gap detection |
| 5. Quality Gate | `tests/journeys/quality-gate.test.ts` | GO/NO-GO decisions |
| 6. Flaky Detection | `tests/journeys/flaky-detection.test.ts` | Statistical detection |
| 7. Learning | `tests/journeys/learning.test.ts` | Q-learning patterns |
**Each journey test**: 300-500 lines, tests REAL user flows with REAL database.
---
### Phase 4: Consolidate Duplicate Files (12-16 hours)
**Priority: High - Largest reduction**
#### BaseAgent Tests (6 → 2 files, 73% reduction)
- Current: 6 files, ~4,500 lines
- Target: 2 files, ~1,200 lines
- Files to consolidate:
- `tests/unit/agents/BaseAgent.test.ts`
- `tests/unit/agents/BaseAgent.enhanced.test.ts`
- `tests/agents/BaseAgent.test.ts`
- `tests/agents/BaseAgent.lifecycle.test.ts`
- `tests/agents/BaseAgent.edge-cases.test.ts`
#### TestGeneratorAgent Tests (3 → 1 file, 73% reduction)
- Current: 3 files, ~3,000 lines
- Target: 1 file, ~800 lines
#### LearningEngine Tests (2 → 1 file, 70% reduction)
- Current: 2 files, ~2,000 lines
- Target: 1 file, ~600 lines
---
### Phase 5: CI/CD Optimization (4-6 hours)
**Priority: Medium - Final polish**
1. Update `package.json` with new test scripts
2. Parallel CI jobs for journeys/contracts/infrastructure
3. Coverage gates (≥85% minimum)
4. Execution time < 2 minutes
---
## Recommended Execution Order
### Week 1: Foundation
1. Phase 1 (Setup) - 2 hours
2. Phase 2.1-2.2 (Quick deletes) - 2 hours
3. Journey 1: Init & Bootstrap - 2 hours
### Week 2: Journey Tests
4. Journey 2-4: Generation, Execution, Coverage - 6 hours
5. Journey 5-7: Quality Gate, Flaky, Learning - 4 hours
### Week 3: Consolidation
6. Consolidate BaseAgent tests - 3 hours
7. Consolidate TestGeneratorAgent tests - 3 hours
8. Consolidate LearningEngine tests - 2 hours
### Week 4: Cleanup & CI
9. Delete redundant files after consolidation - 4 hours
10. CI/CD optimization - 4 hours
11. Documentation update - 2 hours
---
## Success Criteria
| Metric | Current | Target | Verification |
|--------|---------|--------|--------------|
| Test Files | 426 | 50 | `find tests -name "*.test.ts" \| wc -l` |
| Total Lines | 208,253 | 40,000 | `find tests -name "*.test.ts" -exec wc -l {} + \| tail -1` |
| Files > 600 lines | 149 | 0 | `find tests -name "*.test.ts" -exec wc -l {} \; \| awk '$1>600'` |
| Skipped Tests | 7 | 0 | `grep -r "describe.skip\|it.skip" tests \| wc -l` |
| Execution Time | ~5 min | < 2 min | CI workflow timing |
| Coverage | 85% | ≥85% | `npm run test:coverage` |
---
## CI Running
The migration validation CI (`migration-validation.yml`) is already configured and runs:
- Journey test detection
- Contract test detection
- Large file checking (>600 lines)
- Skipped test counting
- Migration metrics generation
It runs on:
- Push to `migration/**` branches
- PRs to `main` that touch `tests/**`
---
## Next Steps
1. **Start Phase 1 now** - Create directories and baseline
2. **Quick wins first** - Delete null-safety tests immediately
3. **One journey at a time** - Get Init & Bootstrap working first
4. **Track daily** - Update progress-tracking.md after each session
---
*Analysis by Claude Code • 2025-12-07*