Files
Profa b3d2018ee2 feat: v1.8.0 - Quality Hardening & Pattern Isolation
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>
2025-11-17 12:32:03 +00:00

4.1 KiB

Quick Fix Guide - FleetManager Test Failures

Target: Fix TypeError: Cannot read properties of undefined (reading 'info') in FleetManager tests Estimated Time: 30 minutes Difficulty: Low


TL;DR

The issue is Logger mock not being hoisted properly, not Database mocking. Fix by moving mocks to __mocks__ directory.


Step-by-Step Fix

Step 1: Create Logger Mock File

Create: /workspaces/agentic-qe-cf/tests/__mocks__/src/utils/Logger.ts

const mockLoggerInstance = {
  info: jest.fn(),
  warn: jest.fn(),
  error: jest.fn(),
  debug: jest.fn(),
  log: jest.fn(),
  child: jest.fn(function() { return this; }),
  setLevel: jest.fn(),
  getLevel: jest.fn(() => 'info')
};

export const Logger = {
  getInstance: jest.fn(() => mockLoggerInstance)
};

export const LogLevel = {
  ERROR: 'error',
  WARN: 'warn',
  INFO: 'info',
  DEBUG: 'debug'
};

Step 2: Create Database Mock File

Create: /workspaces/agentic-qe-cf/tests/__mocks__/src/utils/Database.ts

export class Database {
  initialize = jest.fn().mockResolvedValue(undefined);
  close = jest.fn().mockResolvedValue(undefined);
  run = jest.fn().mockResolvedValue({ lastID: 1, changes: 1 });
  get = jest.fn().mockResolvedValue(undefined);
  all = jest.fn().mockResolvedValue([]);
}

Step 3: Update FleetManager Test File

Edit: /workspaces/agentic-qe-cf/tests/core/FleetManager.test.ts

Remove lines 6-51 (the inline mock blocks) and replace with:

// Mock Logger and Database using __mocks__ directory
jest.mock('../../src/utils/Logger');
jest.mock('../../src/utils/Database');

import { FleetManager } from '../../src/core/FleetManager';
import { Config } from '../../src/utils/Config';
import { createResourceCleanup } from '../helpers/cleanup';

Step 4: Run Tests

npm test -- tests/core/FleetManager.test.ts

Expected Result: All tests should pass ✅


Why This Works

Issue Root Cause Solution
Logger returns undefined Inline jest.mock() not hoisted properly Use __mocks__/ directory for guaranteed hoisting
EventBus crashes on init Logger.getInstance() called in constructor Mock is now available before any imports
Database mock overcomplicated 12 methods when only 5 needed Simplified to essential methods only

Verification Checklist

  • Logger mock file created at correct path
  • Database mock file created at correct path
  • Inline mocks removed from test file
  • jest.mock() calls added at top of test
  • Tests run and pass
  • No console errors during test execution

If Tests Still Fail

Check 1: Verify Mock Directory Structure

tree tests/__mocks__/
# Should show:
# tests/__mocks__/
# └── src/
#     └── utils/
#         ├── Logger.ts
#         └── Database.ts

Check 2: Clear Jest Cache

npm test -- --clearCache
npm test -- tests/core/FleetManager.test.ts

Check 3: Verify Mock Is Being Used

Add console.log to mock:

export const Logger = {
  getInstance: jest.fn(() => {
    console.log('✅ Mock Logger.getInstance() called');
    return mockLoggerInstance;
  })
};

Next Steps After Fix

  1. Run full test suite: npm test
  2. Check coverage: npm run test:coverage
  3. Update other tests: Apply same pattern to other failing tests
  4. Document pattern: Add to testing guidelines

Alternative: Manual Mock Reset (If mocks Doesn't Work)

If the __mocks__ directory approach doesn't work (rare, but possible with Jest config issues):

Add to beforeEach() in test:

beforeEach(() => {
  // Manually mock Logger before FleetManager creation
  const { Logger } = require('../../src/utils/Logger');
  Logger.getInstance = jest.fn(() => ({
    info: jest.fn(),
    warn: jest.fn(),
    error: jest.fn(),
    debug: jest.fn(),
    log: jest.fn()
  }));

  // Then create FleetManager
  fleetManager = new FleetManager(mockConfig);
});

For detailed analysis, see: /workspaces/agentic-qe-cf/docs/fixes/database-mocking-analysis.md