23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
432 lines
12 KiB
TypeScript
432 lines
12 KiB
TypeScript
/**
|
|
* Test Intelligence Plugin - Bridge Tests
|
|
*
|
|
* Tests for TestLearningBridge initialization, lifecycle, and methods
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
import { TestLearningBridge } from '../src/bridges/learning-bridge.js';
|
|
|
|
// Mock WASM module
|
|
vi.mock('../src/bridges/learning-wasm.js', () => ({
|
|
initWasm: vi.fn().mockResolvedValue(undefined),
|
|
wasmAvailable: vi.fn().mockReturnValue(false),
|
|
}));
|
|
|
|
describe('TestLearningBridge', () => {
|
|
let bridge: TestLearningBridge;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
bridge = new TestLearningBridge();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
if (bridge.isReady()) {
|
|
await bridge.destroy();
|
|
}
|
|
});
|
|
|
|
describe('Initialization', () => {
|
|
it('should create bridge instance', () => {
|
|
expect(bridge).toBeInstanceOf(TestLearningBridge);
|
|
});
|
|
|
|
it('should not be ready before init', () => {
|
|
expect(bridge.isReady()).toBe(false);
|
|
});
|
|
|
|
it('should initialize successfully', async () => {
|
|
await bridge.init();
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
|
|
it('should initialize with custom config', async () => {
|
|
await bridge.init({
|
|
algorithm: 'ppo',
|
|
learningRate: 0.001,
|
|
gamma: 0.95,
|
|
epsilon: 0.2,
|
|
});
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
|
|
it('should initialize with q-learning algorithm', async () => {
|
|
await bridge.init({
|
|
algorithm: 'q-learning',
|
|
learningRate: 0.1,
|
|
gamma: 0.99,
|
|
});
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
|
|
it('should initialize with decision-transformer algorithm', async () => {
|
|
await bridge.init({
|
|
algorithm: 'decision-transformer',
|
|
contextLength: 20,
|
|
embeddingDim: 128,
|
|
});
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
|
|
it('should handle double initialization gracefully', async () => {
|
|
await bridge.init();
|
|
await bridge.init(); // Should not throw
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Lifecycle', () => {
|
|
it('should destroy successfully', async () => {
|
|
await bridge.init();
|
|
await bridge.destroy();
|
|
expect(bridge.isReady()).toBe(false);
|
|
});
|
|
|
|
it('should handle destroy when not initialized', async () => {
|
|
await expect(bridge.destroy()).resolves.not.toThrow();
|
|
});
|
|
|
|
it('should reinitialize after destroy', async () => {
|
|
await bridge.init();
|
|
await bridge.destroy();
|
|
await bridge.init();
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('trainOnHistory', () => {
|
|
beforeEach(async () => {
|
|
await bridge.init();
|
|
});
|
|
|
|
it('should train on test history', async () => {
|
|
const history = [
|
|
{
|
|
testId: 'test-1',
|
|
testName: 'test_auth',
|
|
file: 'auth.test.ts',
|
|
failureRate: 0.1,
|
|
avgDuration: 150,
|
|
affectedFiles: ['src/auth.ts'],
|
|
results: [
|
|
{ status: 'passed', duration: 150 },
|
|
{ status: 'failed', duration: 200 },
|
|
],
|
|
},
|
|
{
|
|
testId: 'test-2',
|
|
testName: 'test_login',
|
|
file: 'login.test.ts',
|
|
failureRate: 0.3,
|
|
avgDuration: 200,
|
|
affectedFiles: ['src/auth.ts', 'src/login.ts'],
|
|
results: [
|
|
{ status: 'failed', duration: 200 },
|
|
{ status: 'passed', duration: 180 },
|
|
],
|
|
},
|
|
];
|
|
|
|
const result = await bridge.trainOnHistory(history);
|
|
|
|
// Returns the average loss
|
|
expect(typeof result).toBe('number');
|
|
});
|
|
|
|
it('should handle empty history', async () => {
|
|
const result = await bridge.trainOnHistory([]);
|
|
|
|
// Returns 0 for empty history
|
|
expect(result).toBe(0);
|
|
});
|
|
|
|
it('should handle large history batches', async () => {
|
|
const history = Array(100).fill(null).map((_, i) => ({
|
|
testId: `test-${i}`,
|
|
testName: `test_${i}`,
|
|
file: `test${i}.test.ts`,
|
|
failureRate: Math.random(),
|
|
avgDuration: Math.floor(Math.random() * 500),
|
|
affectedFiles: [`src/file${i % 10}.ts`],
|
|
results: [
|
|
{ status: Math.random() > 0.2 ? 'passed' : 'failed', duration: 100 },
|
|
{ status: Math.random() > 0.2 ? 'passed' : 'failed', duration: 150 },
|
|
],
|
|
}));
|
|
|
|
const result = await bridge.trainOnHistory(history);
|
|
|
|
expect(typeof result).toBe('number');
|
|
});
|
|
|
|
it('should throw when not initialized', async () => {
|
|
await bridge.destroy();
|
|
const history = [{
|
|
testId: 'test-1',
|
|
testName: 'test',
|
|
file: 'test.ts',
|
|
failureRate: 0,
|
|
avgDuration: 100,
|
|
affectedFiles: [],
|
|
results: [],
|
|
}];
|
|
|
|
await expect(bridge.trainOnHistory(history)).rejects.toThrow('Learning bridge not initialized');
|
|
});
|
|
});
|
|
|
|
describe('predictFailingTests', () => {
|
|
beforeEach(async () => {
|
|
await bridge.init();
|
|
// Train with some history first
|
|
await bridge.trainOnHistory([
|
|
{
|
|
testId: 'test-auth',
|
|
testName: 'test_auth',
|
|
file: 'auth.test.ts',
|
|
failureRate: 0.5,
|
|
avgDuration: 150,
|
|
affectedFiles: ['src/auth.ts'],
|
|
results: [
|
|
{ status: 'failed', duration: 150 },
|
|
{ status: 'passed', duration: 140 },
|
|
],
|
|
},
|
|
{
|
|
testId: 'test-user',
|
|
testName: 'test_user',
|
|
file: 'user.test.ts',
|
|
failureRate: 0.1,
|
|
avgDuration: 100,
|
|
affectedFiles: ['src/user.ts'],
|
|
results: [
|
|
{ status: 'passed', duration: 100 },
|
|
{ status: 'passed', duration: 95 },
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should predict failing tests for changed files', async () => {
|
|
const changes = [
|
|
{ file: 'src/auth.ts', type: 'modified' as const, linesAdded: 10, linesRemoved: 2 },
|
|
];
|
|
|
|
const predictions = await bridge.predictFailingTests(changes, 10);
|
|
|
|
expect(Array.isArray(predictions)).toBe(true);
|
|
// May or may not have predictions depending on training
|
|
});
|
|
|
|
it('should return empty array for unknown files', async () => {
|
|
const changes = [
|
|
{ file: 'src/completely-new-file.ts', type: 'added' as const, linesAdded: 50, linesRemoved: 0 },
|
|
];
|
|
|
|
const predictions = await bridge.predictFailingTests(changes, 10);
|
|
|
|
expect(Array.isArray(predictions)).toBe(true);
|
|
// Should return empty for files with no test mapping
|
|
expect(predictions.length).toBe(0);
|
|
});
|
|
|
|
it('should sort predictions by failure probability', async () => {
|
|
const changes = [
|
|
{ file: 'src/auth.ts', type: 'modified' as const, linesAdded: 5, linesRemoved: 2 },
|
|
{ file: 'src/user.ts', type: 'modified' as const, linesAdded: 3, linesRemoved: 1 },
|
|
];
|
|
|
|
const predictions = await bridge.predictFailingTests(changes, 10);
|
|
|
|
if (predictions.length >= 2) {
|
|
for (let i = 1; i < predictions.length; i++) {
|
|
expect(predictions[i - 1].failureProbability).toBeGreaterThanOrEqual(
|
|
predictions[i].failureProbability
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
it('should throw when not initialized', async () => {
|
|
await bridge.destroy();
|
|
const changes = [{ file: 'test.ts', type: 'modified' as const, linesAdded: 1, linesRemoved: 0 }];
|
|
|
|
await expect(bridge.predictFailingTests(changes, 10)).rejects.toThrow('Learning bridge not initialized');
|
|
});
|
|
});
|
|
|
|
describe('updatePolicyWithFeedback', () => {
|
|
beforeEach(async () => {
|
|
await bridge.init();
|
|
// First train with some history to have embeddings
|
|
await bridge.trainOnHistory([
|
|
{
|
|
testId: 'test-auth',
|
|
testName: 'test_auth',
|
|
file: 'auth.test.ts',
|
|
failureRate: 0.5,
|
|
avgDuration: 150,
|
|
affectedFiles: ['src/auth.ts'],
|
|
results: [
|
|
{ status: 'passed', duration: 150 },
|
|
{ status: 'failed', duration: 200 },
|
|
],
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('should update policy with feedback', async () => {
|
|
const feedback = {
|
|
predictions: [
|
|
{ testId: 'test-auth', failureProbability: 0.8, confidence: 0.7, reason: 'test' },
|
|
],
|
|
actualResults: [
|
|
{ testId: 'test-auth', status: 'failed' },
|
|
],
|
|
};
|
|
|
|
// Should not throw
|
|
await expect(bridge.updatePolicyWithFeedback(feedback)).resolves.not.toThrow();
|
|
});
|
|
|
|
it('should throw when not initialized', async () => {
|
|
await bridge.destroy();
|
|
|
|
await expect(
|
|
bridge.updatePolicyWithFeedback({
|
|
predictions: [],
|
|
actualResults: [],
|
|
})
|
|
).rejects.toThrow('Learning bridge not initialized');
|
|
});
|
|
});
|
|
|
|
describe('isReady', () => {
|
|
it('should return false before init', () => {
|
|
expect(bridge.isReady()).toBe(false);
|
|
});
|
|
|
|
it('should return true after init', async () => {
|
|
await bridge.init();
|
|
expect(bridge.isReady()).toBe(true);
|
|
});
|
|
|
|
it('should return false after destroy', async () => {
|
|
await bridge.init();
|
|
await bridge.destroy();
|
|
expect(bridge.isReady()).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('JavaScript Fallback', () => {
|
|
it('should work without WASM', async () => {
|
|
// WASM is mocked to be unavailable
|
|
const fallbackBridge = new TestLearningBridge();
|
|
await fallbackBridge.init();
|
|
|
|
expect(fallbackBridge.isReady()).toBe(true);
|
|
|
|
const changes = [{ file: 'test.ts', type: 'modified' as const, linesAdded: 1, linesRemoved: 0 }];
|
|
const predictions = await fallbackBridge.predictFailingTests(changes, 10);
|
|
expect(Array.isArray(predictions)).toBe(true);
|
|
|
|
await fallbackBridge.destroy();
|
|
});
|
|
|
|
it('should provide consistent results in fallback mode', async () => {
|
|
const bridge1 = new TestLearningBridge();
|
|
const bridge2 = new TestLearningBridge();
|
|
|
|
await bridge1.init();
|
|
await bridge2.init();
|
|
|
|
const history = [{
|
|
testId: 'test-1',
|
|
testName: 'test',
|
|
file: 'test.ts',
|
|
failureRate: 0.1,
|
|
avgDuration: 100,
|
|
affectedFiles: ['src/a.ts'],
|
|
results: [
|
|
{ status: 'passed', duration: 100 },
|
|
{ status: 'passed', duration: 95 },
|
|
],
|
|
}];
|
|
|
|
await bridge1.trainOnHistory(history);
|
|
await bridge2.trainOnHistory(history);
|
|
|
|
const changes = [{ file: 'src/a.ts', type: 'modified' as const, linesAdded: 5, linesRemoved: 2 }];
|
|
const pred1 = await bridge1.predictFailingTests(changes, 10);
|
|
const pred2 = await bridge2.predictFailingTests(changes, 10);
|
|
|
|
// Both should produce same number of predictions
|
|
expect(pred1.length).toBe(pred2.length);
|
|
|
|
await bridge1.destroy();
|
|
await bridge2.destroy();
|
|
});
|
|
});
|
|
|
|
describe('Error Handling', () => {
|
|
it('should handle concurrent operations', async () => {
|
|
await bridge.init();
|
|
|
|
const history = [{
|
|
testId: 't1',
|
|
testName: 't',
|
|
file: 't.ts',
|
|
failureRate: 0.1,
|
|
avgDuration: 1,
|
|
affectedFiles: ['a.ts'],
|
|
results: [{ status: 'passed', duration: 1 }],
|
|
}];
|
|
|
|
const changes = [{ file: 'a.ts', type: 'modified' as const, linesAdded: 1, linesRemoved: 0 }];
|
|
|
|
const operations = [
|
|
bridge.trainOnHistory(history),
|
|
bridge.predictFailingTests(changes, 10),
|
|
];
|
|
|
|
await expect(Promise.all(operations)).resolves.toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('Memory Management', () => {
|
|
it('should release resources on destroy', async () => {
|
|
await bridge.init();
|
|
|
|
// Train with substantial data
|
|
const largeHistory = Array(50).fill(null).map((_, i) => ({
|
|
testId: `test-${i}`,
|
|
testName: `test_${i}`,
|
|
file: `test${i}.test.ts`,
|
|
failureRate: Math.random(),
|
|
avgDuration: Math.floor(Math.random() * 1000),
|
|
affectedFiles: Array(5).fill(null).map((_, j) => `src/file${j}.ts`),
|
|
results: [
|
|
{ status: Math.random() > 0.3 ? 'passed' : 'failed', duration: 100 },
|
|
{ status: Math.random() > 0.3 ? 'passed' : 'failed', duration: 110 },
|
|
],
|
|
}));
|
|
|
|
await bridge.trainOnHistory(largeHistory);
|
|
await bridge.destroy();
|
|
|
|
// Bridge should be reset
|
|
expect(bridge.isReady()).toBe(false);
|
|
});
|
|
|
|
it('should handle multiple init/destroy cycles', async () => {
|
|
for (let i = 0; i < 5; i++) {
|
|
await bridge.init();
|
|
expect(bridge.isReady()).toBe(true);
|
|
await bridge.destroy();
|
|
expect(bridge.isReady()).toBe(false);
|
|
}
|
|
});
|
|
});
|
|
});
|