Files
proffesor-for-testing__agen…/reports/verification/next-steps-action-plan.md
Profa 505bbe9ecc fix: restore build success by reverting Date serialization changes
- Reverted src/ to v1.0.0 baseline (0 TypeScript errors)
- Root cause: Date → string type changes created cascade of 54 errors
- Kept improvements: tsconfig downlevelIteration, ESLint underscore pattern
- Kept stub cleanup: removed 4 redundant test files
- Build status: PASSING (typecheck + build both succeed)

Fixes #build-broken
Related: docs/FORENSIC-ANALYSIS-SESSION-BREAKDOWN.md
2025-10-01 11:53:31 +00:00

10 KiB

Critical Fixes - Next Steps Action Plan

🎯 Mission: Build Success in 4-6 Hours


Phase 1: MemoryValue Type System Fix (2 hours) 🔥

Impact: Resolves 28/54 errors (52%)

Step 1.1: Expand MemoryValue Type Definition (30 min)

File: /workspaces/agentic-qe-cf/src/types/index.ts

// Current (too restrictive):
export type MemoryValue =
  | string
  | number
  | boolean
  | Date
  | null
  | { [key: string]: MemoryValue | undefined }
  | MemoryValue[];

// Proposed (flexible):
export type MemoryValue =
  | string
  | number
  | boolean
  | Date
  | null
  | MemoryValue[]
  | { [key: string]: MemoryValue | undefined }
  | Record<string, unknown> // Allow any object structure
  | unknown; // Escape hatch for complex types

// Add serialization helpers:
export function toMemoryValue(value: any): MemoryValue {
  if (value === null || value === undefined) return null;
  if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') return value;
  if (value instanceof Date) return value;
  if (Array.isArray(value)) return value.map(toMemoryValue);
  if (typeof value === 'object') return JSON.parse(JSON.stringify(value)); // Deep clone
  return value;
}

export function fromMemoryValue<T>(value: MemoryValue): T {
  return value as T;
}

Step 1.2: Update Affected Agents (1.5 hours)

FlakyTestHunterAgent.ts (9 errors)

// Line 240: Use toMemoryValue helper
await this.storeMemory('flaky-scan-results', toMemoryValue({
  timestamp: new Date(),
  count: flakyTests.length,
  tests: flakyTests
}));

// Line 287: Use toMemoryValue helper
await this.storeMemory(`quarantine/${testName}`, toMemoryValue(quarantineRecord));

// Lines 1062-1064: Use toMemoryValue helper
await this.storeMemory('flaky-tests', toMemoryValue(Array.from(this.flakyTests.values())));
await this.storeMemory('quarantine', toMemoryValue(Array.from(this.quarantine.values())));
await this.storeMemory('reliability-scores', toMemoryValue(Array.from(this.reliabilityScores.values())));

RegressionRiskAnalyzerAgent.ts (11 errors)

// Line 404: Use toMemoryValue helper
await this.storeMemory('risk-heatmap', toMemoryValue(heatMap));

// Line 408: Use toMemoryValue helper
await this.storeMemory('dependency-graph', toMemoryValue(this.dependencyGraph));

// Lines 476-477: Use toMemoryValue helper
await this.storeMemory(`analysis/${analysis.commitSha}`, toMemoryValue(analysis));
await this.storeMemory('latest-analysis', toMemoryValue(analysis));

// Lines 556-557: Use toMemoryValue helper
await this.storeMemory('test-selection', toMemoryValue(selection));
await this.storeMemory(`selection/${analysis.commitSha}`, toMemoryValue(selection));

// Line 609: Use toMemoryValue helper
await this.storeMemory('risk-heatmap', toMemoryValue(heatMap));

// Line 773: Use toMemoryValue helper
await this.storeMemory('ml-model-metrics', toMemoryValue(metrics));

// Lines 1150, 1164: Initialize with proper Maps
const dependencyMap = new Map<string, string[]>(
  Object.entries(stored || {}).map(([k, v]) => [k, Array.isArray(v) ? v : []])
);

const testImpactMap = new Map<string, any>(
  Object.entries(stored || {}).map(([k, v]) => [k, v])
);

PerformanceTesterAgent.ts (2 errors)

// Line 360: Use toMemoryValue helper (already fixed with timestamp serialization)
await this.storeMemory('performance-state', toMemoryValue({
  activeTests: Array.from(this.activeTests.entries()),
  baselines: Array.from(this.baselines.entries()),
  timestamp: new Date().toISOString()
}));

// Line 1203: Use toMemoryValue helper
await this.storeSharedMemory('latest-test', toMemoryValue({
  testId,
  timestamp: new Date().toISOString(),
  passed: result.slaViolations.length === 0,
  metrics: result.metrics
}));

FleetCommanderAgent.ts (1 error)

// Line 278: Use toMemoryValue helper
await this.storeMemory('topology-state', toMemoryValue(topologyState));

ApiContractValidatorAgent.ts (1 error)

// Line 208: Replace {} with proper value
await this.storeMemory('contract-state', toMemoryValue({
  contracts: Array.from(this.contracts.entries()),
  validationHistory: Array.from(this.validationHistory.entries())
}));

Phase 2: Date Type Handling Fix (1 hour) 📅

Impact: Resolves 4/54 errors (7%)

Step 2.1: Create Type Guard Utilities (15 min)

File: /workspaces/agentic-qe-cf/src/utils/type-guards.ts (create new)

export function ensureDate(value: string | Date): Date {
  return typeof value === 'string' ? new Date(value) : value;
}

export function toISOString(value: string | Date): string {
  return typeof value === 'string' ? value : value.toISOString();
}

export function parseDateSafe(value: string | Date | null | undefined): Date | null {
  if (!value) return null;
  if (value instanceof Date) return value;
  const parsed = new Date(value);
  return isNaN(parsed.getTime()) ? null : parsed;
}

Step 2.2: Fix BaseAgent.ts (30 min)

// Line 370: Use ensureDate
import { ensureDate, toISOString } from '../utils/type-guards';

// Line 370:
this.agentId.lastActive = ensureDate(lastActive);

// Line 385:
this.agentId.created = ensureDate(created);

// Line 388:
this.agentId.lastActive = ensureDate(lastActive);

Step 2.3: Fix CoverageAnalyzerAgent.ts (15 min)

// Line 607: Use ensureDate
import { ensureDate } from '../utils/type-guards';

// Line 607:
state.lastAnalysis = ensureDate(state.lastAnalysis);

Phase 3: Object Initialization Fix (2 hours) 📦

Impact: Resolves 22/54 errors (41%)

Step 3.1: Create Factory Functions (30 min)

File: /workspaces/agentic-qe-cf/src/utils/factory-functions.ts (create new)

export function createEmptyQualityMetrics() {
  return {
    status: 'warning' as const,
    score: 0,
    violations: []
  };
}

export function createEmptyPerformanceMetrics() {
  return {
    p50: 0,
    p95: 0,
    p99: 0,
    throughput: 0,
    errorRate: 0,
    status: 'warning' as const
  };
}

export function createEmptySecurityMetrics() {
  return {
    vulnerabilities: {
      critical: 0,
      high: 0,
      medium: 0,
      low: 0
    },
    status: 'warning' as const
  };
}

export function createEmptyCoverageMetrics() {
  return {
    line: 0,
    branch: 0,
    function: 0,
    statement: 0
  };
}

export function createEmptyTestMetrics() {
  return {
    total: 0,
    passed: 0,
    failed: 0,
    skipped: 0,
    flakyCount: 0
  };
}

export function createEmptyChangeAnalysis(): ChangeAnalysis {
  return {
    commitSha: '',
    author: '',
    timestamp: new Date(),
    changedFiles: [],
    riskScore: 0,
    affectedTests: [],
    testCoverage: 0,
    complexityChange: 0,
    dependencyImpact: [],
    mlPrediction: 0,
    confidence: 0
  };
}

Step 3.2: Fix DeploymentReadinessAgent.ts (1 hour)

import {
  createEmptyQualityMetrics,
  createEmptyPerformanceMetrics,
  createEmptySecurityMetrics,
  createEmptyCoverageMetrics,
  createEmptyTestMetrics
} from '../utils/factory-functions';

// Line 496: Replace {}
const qualityMetrics = stored?.quality || createEmptyQualityMetrics();

// Line 507: Replace {}
const performanceMetrics = stored?.performance || createEmptyPerformanceMetrics();

// Line 518: Replace {}
const securityMetrics = stored?.security || createEmptySecurityMetrics();

// Line 528: Replace {}
const coverageMetrics = stored?.coverage || createEmptyCoverageMetrics();

// Line 537: Replace {}
const testMetrics = stored?.tests || createEmptyTestMetrics();

Step 3.3: Fix RegressionRiskAnalyzerAgent.ts (30 min)

import { createEmptyChangeAnalysis } from '../utils/factory-functions';

// Line 517: Replace {}
const latestAnalysis = fromMemoryValue<ChangeAnalysis>(
  await this.retrieveMemory('latest-analysis') || createEmptyChangeAnalysis()
);

// Line 520: Replace {}
const latestAnalysis = fromMemoryValue<ChangeAnalysis>(
  await this.retrieveMemory('latest-analysis') || createEmptyChangeAnalysis()
);

Phase 4: Verification & Build (1 hour) ✅

Step 4.1: Run TypeScript Check (10 min)

npm run typecheck
# Expected: 0 errors (down from 54)

Step 4.2: Run Build (10 min)

npm run build
# Expected: SUCCESS

Step 4.3: Run ESLint (10 min)

npm run lint
# Expected: Fewer errors (target: <100)

Step 4.4: Run Tests (30 min)

npm test
# Document results

Phase 5: ESLint Cleanup (Optional, 4-6 hours) 🧹

Priority ESLint Fixes:

  1. Unused Variables (81 instances)

    • Remove or prefix with underscore
    • Use // eslint-disable-next-line if intentional
  2. @typescript-eslint/no-explicit-any (65 instances)

    • Add proper type definitions
    • Use unknown when type is truly unknown
  3. Auto-fixable Issues

    npx eslint --fix src/**/*.ts
    

Success Criteria Checklist

  • Phase 1 Complete: MemoryValue type system expanded
  • Phase 2 Complete: Date type handling fixed
  • Phase 3 Complete: Object initialization patterns applied
  • TypeScript Errors: 0 (down from 54)
  • Build Status: SUCCESS
  • ESLint Errors: <100 (stretch: <10)
  • Test Suite: Running and documented

Execution Timeline

Hour 1-2:   Phase 1 - MemoryValue Type System Fix
Hour 2-3:   Phase 2 - Date Type Handling Fix
Hour 3-5:   Phase 3 - Object Initialization Fix
Hour 5-6:   Phase 4 - Verification & Build

Optional:
Hour 6-12:  Phase 5 - ESLint Cleanup

Risk Mitigation

High Risk:

  • MemoryValue changes break existing functionality
    • Mitigation: Keep original type as fallback, add tests

Medium Risk:

  • Date conversion introduces timezone issues
    • Mitigation: Always use UTC/ISO strings

Low Risk:

  • Factory functions miss edge cases
    • Mitigation: Add validation in factories

Commands Quick Reference

# Verify TypeScript
npm run typecheck

# Verify Build
npm run build

# Verify ESLint
npm run lint

# Run Tests
npm test

# Auto-fix ESLint (safe)
npx eslint --fix src/**/*.ts

# Check specific file
npx eslint src/agents/FlakyTestHunterAgent.ts

Next Action: Execute Phase 1 - MemoryValue Type System Fix

Estimated Completion: 4-6 hours to build success