mirror of
https://github.com/proffesor-for-testing/agentic-qe.git
synced 2026-09-19 08:45:47 +08:00
346438f0de
* SwarmMemoryManager Refactoring Plan * fix: add missing directories to npm package (v1.9.3) Added templates/, .claude/helpers/, and docs/reference/ to package.json files array. These were missing from the npm distribution, causing `aqe init` to fail with "Template file not found" errors. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * checkpoint improvements * fix: critical memory/learning system fixes for v1.9.4 ## Critical Fixes - Vector embeddings now stored correctly (was storing NULL) - SQL parameter style fixed for agentdb's SqlJsDatabase wrapper - HNSW index schema mismatch resolved with pattern_id column - Hooks now save to correct database (.agentic-qe/agentdb.db) ## New Features - Added 5 SwarmMemoryManager methods for learning data retrieval: - getBestAction() - Q-learning best action selection - getRecentLearningExperiences() - Recent experience retrieval - getLearningExperiencesByTaskType() - Task-filtered experiences - getHighRewardExperiences() - Successful experience extraction - getLearningStats() - Aggregate learning statistics - Added comprehensive integration test for memory/learning loop - Added RuVector pattern store integration (experimental) ## Technical Details - Vector embeddings: 384 dimensions × 4 bytes = 1,536 bytes per pattern - All 12 integration tests pass - HNSW index: 150x faster vector search enabled 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: move ARM64-only ruvector packages to optionalDependencies Fixes CI failures caused by platform-specific dependencies: - @ruvector/node-linux-arm64-gnu (ARM64 only) - ruvector-core-linux-arm64-gnu (ARM64 only) These packages caused npm ci to fail on x64 CI runners with: "EBADPLATFORM - wanted linux/arm64, current linux/x64" Solution: Move ARM64 packages to optionalDependencies and add x64 variants for cross-platform compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * chore: regenerate package-lock.json with x64 ruvector packages Updates lockfile to include optional x64 platform packages for CI compatibility: - @ruvector/node-linux-x64-gnu@0.1.17 - ruvector-core-linux-x64-gnu@0.1.15 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: replace fake QUIC with proper implementation and clean up skills manifest QUIC Transport: - Remove fake HTTP/2-based QUICTransport.ts that pretended to be QUIC - Add proper QUIC implementation via Rust/WASM (@agentic-flow/quic-wasm) - Add WebSocket fallback transport for when WASM unavailable - Add dedicated type declarations for optional WASM module - Features: 0-RTT connection, stream multiplexing, TLS 1.3 built-in Skills Manifest: - Rewrite skills-manifest.json with only QE skills (41 skills) - Remove Claude Flow platform skills (agentdb-*, flow-nexus-*, github-*, etc.) - Organize into proper categories: qe-core, testing-methodologies, etc. Bug Fixes: - Fix UnifiedMemoryCoordinator.ts TypeScript errors - Use Logger.getInstance() instead of private constructor - Use swarmMemory.query() instead of non-existent list() method - Use correct close() method signatures for backends 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add QX Partner agent, compact subagents, fix CLAUDE.md dynamic counts - Add QX Partner agent for Quality Experience analysis combining QA + UX perspectives - Compact 9 subagent definitions to ~80 lines each (88% reduction) - Fix CLAUDE.md template to dynamically count agents (including subagents) and skills - Move CLAUDE.md creation after parallel phases for accurate counts - Remove 'Production-Ready' claim from README and CHANGELOG - Clean up backup files and move docs to proper directory Initialization now correctly reports: - 31 QE Agents (20 main + 11 subagents) - 53 QE Skills - 8 Slash Commands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
611 lines
17 KiB
TypeScript
611 lines
17 KiB
TypeScript
/**
|
|
* Integration Test: Learning Engine Backward Compatibility
|
|
*
|
|
* Verifies that the refactored LearningEngine maintains backward compatibility:
|
|
* 1. Old recordExperience() API still works (with deprecation warning)
|
|
* 2. BaseAgent integration remains unchanged
|
|
* 3. Existing test suites pass without modification
|
|
* 4. Migration path is smooth
|
|
*/
|
|
|
|
// CRITICAL: Unmock Database to use real implementation
|
|
jest.unmock('../../src/utils/Database');
|
|
|
|
import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
|
|
import { LearningEngine } from '../../src/learning/LearningEngine';
|
|
import { SwarmMemoryManager } from '../../src/core/memory/SwarmMemoryManager';
|
|
import { Database } from '../../src/utils/Database';
|
|
import { TaskResult } from '../../src/learning/RewardCalculator';
|
|
import { LearningFeedback } from '../../src/learning/types';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
describe('LearningEngine Backward Compatibility', () => {
|
|
// Use tests/.tmp directory for test databases (not project root)
|
|
const tmpDir = path.join(__dirname, '../.tmp');
|
|
const testDbPath = path.join(tmpDir, '.test-learning-compat.db');
|
|
const memoryDbPath = path.join(tmpDir, '.test-memory-compat.db');
|
|
let database: Database;
|
|
let memoryManager: SwarmMemoryManager;
|
|
let learningEngine: LearningEngine | null = null;
|
|
|
|
beforeEach(async () => {
|
|
// Ensure tmp directory exists
|
|
if (!fs.existsSync(tmpDir)) {
|
|
fs.mkdirSync(tmpDir, { recursive: true });
|
|
}
|
|
|
|
// Clean up test databases
|
|
[testDbPath, memoryDbPath].forEach(dbPath => {
|
|
if (fs.existsSync(dbPath)) {
|
|
fs.unlinkSync(dbPath);
|
|
}
|
|
});
|
|
|
|
// Create fresh database and memory manager
|
|
database = new Database(testDbPath);
|
|
await database.initialize();
|
|
|
|
memoryManager = new SwarmMemoryManager(memoryDbPath);
|
|
await memoryManager.initialize();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
// Dispose learning engine to prevent open handles
|
|
if (learningEngine) {
|
|
learningEngine.dispose();
|
|
learningEngine = null;
|
|
}
|
|
|
|
// Close database connections
|
|
try {
|
|
if (database) await database.close();
|
|
} catch (error) {
|
|
// Ignore close errors
|
|
}
|
|
|
|
try {
|
|
if (memoryManager && (memoryManager as any).db) {
|
|
(memoryManager as any).db.close();
|
|
}
|
|
} catch (error) {
|
|
// Ignore close errors
|
|
}
|
|
|
|
// Clean up test databases
|
|
[testDbPath, memoryDbPath].forEach(dbPath => {
|
|
if (fs.existsSync(dbPath)) {
|
|
fs.unlinkSync(dbPath);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('recordExperience() Compatibility', () => {
|
|
it('should work with old recordExperience() API', async () => {
|
|
const agentId = 'compat-agent-old-api';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
// Use OLD API (recordExperience instead of learnFromExecution)
|
|
const task = {
|
|
type: 'unit-test-generation',
|
|
context: {},
|
|
requirements: {
|
|
capabilities: ['code-analysis', 'test-generation']
|
|
}
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: true,
|
|
executionTime: 1500,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template-based',
|
|
toolsUsed: ['ast-parser', 'jest-generator'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.6
|
|
}
|
|
};
|
|
|
|
// OLD API - should still work
|
|
await learningEngine.recordExperience(task, result);
|
|
|
|
// Verify data was persisted
|
|
const stats = await database.getLearningStatistics(agentId);
|
|
expect(stats.totalExperiences).toBeGreaterThan(0);
|
|
expect(stats.qTableSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should work with old recordExperience() API with feedback', async () => {
|
|
const agentId = 'compat-agent-feedback';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
const task = {
|
|
type: 'security-test-generation',
|
|
context: {},
|
|
requirements: {
|
|
capabilities: ['security-testing', 'owasp']
|
|
}
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: true,
|
|
executionTime: 3000,
|
|
errors: [],
|
|
coverage: 0.95,
|
|
metadata: {
|
|
strategy: 'threat-modeling',
|
|
toolsUsed: ['semgrep', 'bandit'],
|
|
parallelization: 0.8,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.9
|
|
}
|
|
};
|
|
|
|
const feedback: LearningFeedback = {
|
|
rating: 0.9,
|
|
issues: [],
|
|
suggestions: ['Excellent coverage of OWASP Top 10']
|
|
};
|
|
|
|
// OLD API with feedback
|
|
await learningEngine.recordExperience(task, result, feedback);
|
|
|
|
// Verify feedback influenced learning
|
|
const stats = await database.getLearningStatistics(agentId);
|
|
expect(stats.avgReward).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('should handle multiple calls to old API', async () => {
|
|
const agentId = 'compat-agent-multiple';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
// Multiple calls using OLD API
|
|
for (let i = 0; i < 10; i++) {
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: i % 2 === 0,
|
|
executionTime: 1000 + i * 100,
|
|
errors: [],
|
|
coverage: 0.7 + i * 0.02,
|
|
metadata: {
|
|
strategy: i % 2 === 0 ? 'template' : 'property',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
await learningEngine.recordExperience(task, result);
|
|
}
|
|
|
|
// Verify all experiences were recorded
|
|
const stats = await database.getLearningStatistics(agentId);
|
|
expect(stats.totalExperiences).toBe(10);
|
|
});
|
|
});
|
|
|
|
describe('learnFromExecution() New API', () => {
|
|
it('should work with new learnFromExecution() API', async () => {
|
|
const agentId = 'compat-agent-new-api';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
// Use NEW API
|
|
const task = {
|
|
type: 'integration-test-generation',
|
|
context: {},
|
|
requirements: {
|
|
capabilities: ['api-testing']
|
|
}
|
|
};
|
|
|
|
const result = {
|
|
success: true,
|
|
executionTime: 2000,
|
|
errors: [],
|
|
coverage: 0.90
|
|
};
|
|
|
|
// NEW API - returns LearningOutcome
|
|
const outcome = await learningEngine.learnFromExecution(task, result);
|
|
|
|
expect(outcome).toBeDefined();
|
|
expect(outcome.newPerformance).toBeDefined();
|
|
expect(outcome.confidence).toBeGreaterThanOrEqual(0);
|
|
expect(outcome.patterns).toBeDefined();
|
|
|
|
// Verify learning occurred (but no database persistence in learnFromExecution)
|
|
expect(learningEngine.getTotalExperiences()).toBe(1);
|
|
});
|
|
|
|
it('should support both APIs in same session', async () => {
|
|
const agentId = 'compat-agent-mixed';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
const task1 = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result1: TaskResult = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
// OLD API (with database persistence)
|
|
await learningEngine.recordExperience(task1, result1);
|
|
|
|
const task2 = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result2 = {
|
|
success: true,
|
|
executionTime: 1200,
|
|
errors: [],
|
|
coverage: 0.88
|
|
};
|
|
|
|
// NEW API (in-memory only)
|
|
await learningEngine.learnFromExecution(task2, result2);
|
|
|
|
// Verify both APIs worked
|
|
expect(learningEngine.getTotalExperiences()).toBe(2);
|
|
|
|
// OLD API should have persisted to database
|
|
const stats = await database.getLearningStatistics(agentId);
|
|
expect(stats.totalExperiences).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Migration Scenarios', () => {
|
|
it('should migrate from old to new API smoothly', async () => {
|
|
const agentId = 'compat-agent-migration';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
// Phase 1: Using OLD API (existing codebase)
|
|
for (let i = 0; i < 5; i++) {
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
await learningEngine.recordExperience(task, result);
|
|
}
|
|
|
|
// Verify OLD API worked
|
|
let stats = await database.getLearningStatistics(agentId);
|
|
expect(stats.totalExperiences).toBe(5);
|
|
|
|
// Phase 2: Gradual migration to NEW API
|
|
for (let i = 0; i < 5; i++) {
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85
|
|
};
|
|
|
|
// NEW API
|
|
await learningEngine.learnFromExecution(task, result);
|
|
}
|
|
|
|
// Verify total experiences (5 old + 5 new)
|
|
expect(learningEngine.getTotalExperiences()).toBe(10);
|
|
|
|
// OLD API calls should still be in database
|
|
stats = await database.getLearningStatistics(agentId);
|
|
expect(stats.totalExperiences).toBe(5); // Only OLD API persists
|
|
});
|
|
|
|
it('should handle disabled learning gracefully', async () => {
|
|
const agentId = 'compat-agent-disabled';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: false }, // Learning disabled
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
// Should not throw even when disabled
|
|
await expect(learningEngine.recordExperience(task, result)).resolves.not.toThrow();
|
|
|
|
const result2 = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85
|
|
};
|
|
|
|
await expect(learningEngine.learnFromExecution(task, result2)).resolves.not.toThrow();
|
|
|
|
// No learning should have occurred
|
|
expect(learningEngine.getTotalExperiences()).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('Error Recovery', () => {
|
|
it('should handle persistence errors gracefully in old API', async () => {
|
|
const agentId = 'compat-agent-error';
|
|
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
database
|
|
);
|
|
await learningEngine.initialize();
|
|
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
// Record first experience
|
|
await learningEngine.recordExperience(task, result);
|
|
|
|
// Close database to trigger error
|
|
await database.close();
|
|
|
|
// Should not throw - error should be caught internally
|
|
await expect(learningEngine.recordExperience(task, result)).resolves.not.toThrow();
|
|
|
|
// Learning should continue (in-memory)
|
|
expect(learningEngine.getTotalExperiences()).toBe(2);
|
|
});
|
|
|
|
it('should recover from database errors and continue learning', async () => {
|
|
const agentId = 'compat-agent-recovery';
|
|
|
|
// Temporarily set invalid database path
|
|
const badDbPath = '/invalid/path/db.sqlite';
|
|
const badDatabase = new Database(badDbPath);
|
|
|
|
// This should fail to initialize, but engine should handle it
|
|
try {
|
|
await badDatabase.initialize();
|
|
} catch (error) {
|
|
// Expected - database initialization failed
|
|
}
|
|
|
|
// Create engine with bad database
|
|
learningEngine = new LearningEngine(
|
|
agentId,
|
|
memoryManager,
|
|
{ enabled: true },
|
|
badDatabase
|
|
);
|
|
|
|
// Initialize should not throw
|
|
await expect(learningEngine.initialize()).resolves.not.toThrow();
|
|
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result: TaskResult = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
// Should not throw - error should be caught internally
|
|
await expect(learningEngine.recordExperience(task, result)).resolves.not.toThrow();
|
|
|
|
// Learning should continue (in-memory)
|
|
expect(learningEngine.getTotalExperiences()).toBeGreaterThan(0);
|
|
});
|
|
});
|
|
|
|
describe('Feature Parity', () => {
|
|
let engine1: LearningEngine | null = null;
|
|
let engine2: LearningEngine | null = null;
|
|
|
|
afterEach(() => {
|
|
if (engine1) {
|
|
engine1.dispose();
|
|
engine1 = null;
|
|
}
|
|
if (engine2) {
|
|
engine2.dispose();
|
|
engine2 = null;
|
|
}
|
|
});
|
|
|
|
it('should provide same learning capabilities in both APIs', async () => {
|
|
const agentId1 = 'compat-agent-old-features';
|
|
const agentId2 = 'compat-agent-new-features';
|
|
|
|
engine1 = new LearningEngine(agentId1, memoryManager, { enabled: true }, database);
|
|
await engine1.initialize();
|
|
|
|
engine2 = new LearningEngine(agentId2, memoryManager, { enabled: true }, database);
|
|
await engine2.initialize();
|
|
|
|
const task = {
|
|
type: 'test-generation',
|
|
context: {},
|
|
requirements: { capabilities: ['testing'] }
|
|
};
|
|
|
|
const result1: TaskResult = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85,
|
|
metadata: {
|
|
strategy: 'template',
|
|
toolsUsed: ['jest'],
|
|
parallelization: 0.5,
|
|
retryPolicy: 'exponential',
|
|
resourceAllocation: 0.5
|
|
}
|
|
};
|
|
|
|
const result2 = {
|
|
success: true,
|
|
executionTime: 1000,
|
|
errors: [],
|
|
coverage: 0.85
|
|
};
|
|
|
|
// OLD API
|
|
await engine1.recordExperience(task, result1);
|
|
|
|
// NEW API
|
|
await engine2.learnFromExecution(task, result2);
|
|
|
|
// Both should have learned
|
|
expect(engine1.getTotalExperiences()).toBe(1);
|
|
expect(engine2.getTotalExperiences()).toBe(1);
|
|
|
|
// Both should support strategy recommendations
|
|
const state = {
|
|
taskComplexity: 0.5,
|
|
requiredCapabilities: ['testing'],
|
|
contextFeatures: {},
|
|
previousAttempts: 0,
|
|
availableResources: 0.8,
|
|
timeConstraint: 30000
|
|
};
|
|
|
|
const rec1 = await engine1.recommendStrategy(state);
|
|
const rec2 = await engine2.recommendStrategy(state);
|
|
|
|
expect(rec1).toBeDefined();
|
|
expect(rec2).toBeDefined();
|
|
expect(rec1.strategy).toBeDefined();
|
|
expect(rec2.strategy).toBeDefined();
|
|
});
|
|
});
|
|
});
|