Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:02:19 +08:00

683 lines
21 KiB
TypeScript

import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { WorkflowEngine } from '../../src/task-execution/application/WorkflowEngine';
import { SwarmCoordinator } from '../../src/coordination/application/SwarmCoordinator';
import { HybridBackend } from '../../src/memory/infrastructure/HybridBackend';
import { PluginManager } from '../../src/infrastructure/plugins/PluginManager';
import { Task } from '../../src/task-execution/domain/Task';
import { Agent } from '../../src/agent-lifecycle/domain/Agent';
import { EventEmitter } from 'events';
import * as path from 'path';
import * as fs from 'fs/promises';
describe('Full Workflow Integration Tests', () => {
let workflowEngine: WorkflowEngine;
let coordinator: SwarmCoordinator;
let memoryBackend: HybridBackend;
let pluginManager: PluginManager;
let eventBus: EventEmitter;
let testDbPath: string;
beforeEach(async () => {
testDbPath = path.join(__dirname, `workflow-test-${Date.now()}.db`);
eventBus = new EventEmitter();
// Initialize memory backend
memoryBackend = {
store: vi.fn().mockResolvedValue(undefined),
retrieve: vi.fn().mockResolvedValue(null),
query: vi.fn().mockResolvedValue([]),
update: vi.fn().mockResolvedValue(undefined),
delete: vi.fn().mockResolvedValue(undefined),
vectorSearch: vi.fn().mockResolvedValue([]),
initialize: vi.fn().mockResolvedValue(undefined),
close: vi.fn().mockResolvedValue(undefined)
} as any;
// Initialize plugin manager
pluginManager = new PluginManager({ eventBus });
await pluginManager.initialize();
// Initialize coordinator
coordinator = new SwarmCoordinator({
topology: 'hierarchical',
memoryBackend,
eventBus,
pluginManager
});
await coordinator.initialize();
// Initialize workflow engine
workflowEngine = new WorkflowEngine({
coordinator,
memoryBackend,
eventBus,
pluginManager
});
await workflowEngine.initialize();
});
afterEach(async () => {
await workflowEngine.shutdown();
await coordinator.shutdown();
await pluginManager.shutdown();
try {
await fs.unlink(testDbPath);
} catch (error) {
// Ignore cleanup errors
}
});
it('should execute end-to-end agent workflow', async () => {
// 1. Spawn agents
const coder = await coordinator.spawnAgent({
id: 'coder-1',
type: 'coder',
capabilities: ['code', 'refactor']
});
const tester = await coordinator.spawnAgent({
id: 'tester-1',
type: 'tester',
capabilities: ['test', 'validate']
});
// 2. Create workflow
const workflow = {
id: 'feature-workflow',
name: 'Implement Feature',
tasks: [
{
id: 'code-task',
type: 'code',
description: 'Implement login feature',
assignedTo: 'coder-1',
priority: 'high'
},
{
id: 'test-task',
type: 'test',
description: 'Test login feature',
assignedTo: 'tester-1',
priority: 'high',
dependencies: ['code-task']
}
]
};
// 3. Execute workflow
const result = await workflowEngine.executeWorkflow(workflow);
// 4. Verify execution
expect(result.status).toBe('completed');
expect(result.tasksCompleted).toBe(2);
expect(result.errors).toHaveLength(0);
// 5. Verify memory persistence
expect(memoryBackend.store).toHaveBeenCalled();
});
it('should persist task execution pipeline to memory', async () => {
const storedMemories: any[] = [];
(memoryBackend.store as any).mockImplementation(async (memory) => {
storedMemories.push(memory);
return memory;
});
await coordinator.spawnAgent({
id: 'worker',
type: 'coder',
capabilities: ['code']
});
const task: Task = {
id: 'persist-task',
type: 'code',
description: 'Persistence test',
priority: 'medium'
};
await workflowEngine.executeTask(task, 'worker');
// Verify task lifecycle was persisted
expect(storedMemories.length).toBeGreaterThan(0);
const taskStartMemory = storedMemories.find(m =>
m.type === 'task-start' && m.metadata?.taskId === 'persist-task'
);
const taskCompleteMemory = storedMemories.find(m =>
m.type === 'task-complete' && m.metadata?.taskId === 'persist-task'
);
expect(taskStartMemory).toBeDefined();
expect(taskCompleteMemory).toBeDefined();
});
it('should handle memory persistence across multiple operations', async () => {
const memories = new Map<string, any>();
(memoryBackend.store as any).mockImplementation(async (memory) => {
memories.set(memory.id, memory);
return memory;
});
(memoryBackend.retrieve as any).mockImplementation(async (id) => {
return memories.get(id) || null;
});
(memoryBackend.query as any).mockImplementation(async (query) => {
return Array.from(memories.values()).filter(m => {
if (query.agentId && m.agentId !== query.agentId) return false;
if (query.type && m.type !== query.type) return false;
return true;
});
});
// Create agent
const agent = await coordinator.spawnAgent({
id: 'persistent-agent',
type: 'coder',
capabilities: ['code']
});
// Execute multiple tasks
const tasks = [
{ id: 'task-1', type: 'code', description: 'Task 1', priority: 'high' as const },
{ id: 'task-2', type: 'code', description: 'Task 2', priority: 'medium' as const },
{ id: 'task-3', type: 'code', description: 'Task 3', priority: 'low' as const }
];
for (const task of tasks) {
await workflowEngine.executeTask(task, 'persistent-agent');
}
// Query memories
const agentMemories = await memoryBackend.query({ agentId: 'persistent-agent' });
expect(agentMemories.length).toBeGreaterThan(0);
expect(memories.size).toBeGreaterThan(0);
});
it('should coordinate multi-agent parallel execution', async () => {
const agents = await Promise.all([
coordinator.spawnAgent({ id: 'parallel-1', type: 'coder', capabilities: ['code'] }),
coordinator.spawnAgent({ id: 'parallel-2', type: 'coder', capabilities: ['code'] }),
coordinator.spawnAgent({ id: 'parallel-3', type: 'coder', capabilities: ['code'] })
]);
const tasks: Task[] = [
{ id: 'p-task-1', type: 'code', description: 'Parallel 1', priority: 'high' },
{ id: 'p-task-2', type: 'code', description: 'Parallel 2', priority: 'high' },
{ id: 'p-task-3', type: 'code', description: 'Parallel 3', priority: 'high' }
];
const startTime = Date.now();
const results = await workflowEngine.executeParallel(tasks);
const duration = Date.now() - startTime;
expect(results).toHaveLength(3);
expect(results.every(r => r.status === 'completed' || r.status === 'failed')).toBe(true);
// Parallel execution should be faster than sequential
expect(duration).toBeLessThan(500);
});
it('should handle complex workflow with dependencies', async () => {
await coordinator.spawnAgent({ id: 'designer', type: 'designer', capabilities: ['design'] });
await coordinator.spawnAgent({ id: 'coder', type: 'coder', capabilities: ['code'] });
await coordinator.spawnAgent({ id: 'tester', type: 'tester', capabilities: ['test'] });
await coordinator.spawnAgent({ id: 'deployer', type: 'deployer', capabilities: ['deploy'] });
const workflow = {
id: 'complex-workflow',
name: 'Full Stack Feature',
tasks: [
{
id: 'design',
type: 'design',
description: 'Design UI',
assignedTo: 'designer',
priority: 'high' as const,
dependencies: []
},
{
id: 'implement',
type: 'code',
description: 'Implement feature',
assignedTo: 'coder',
priority: 'high' as const,
dependencies: ['design']
},
{
id: 'test',
type: 'test',
description: 'Test implementation',
assignedTo: 'tester',
priority: 'high' as const,
dependencies: ['implement']
},
{
id: 'deploy',
type: 'deploy',
description: 'Deploy to production',
assignedTo: 'deployer',
priority: 'high' as const,
dependencies: ['test']
}
]
};
const result = await workflowEngine.executeWorkflow(workflow);
expect(result.status).toBe('completed');
expect(result.executionOrder).toEqual(['design', 'implement', 'test', 'deploy']);
});
it('should integrate plugins into workflow execution', async () => {
const pluginCalls: string[] = [];
const validatorPlugin = {
id: 'workflow-validator',
name: 'Workflow Validator',
version: '1.0.0',
initialize: vi.fn().mockResolvedValue(undefined),
shutdown: vi.fn().mockResolvedValue(undefined),
getExtensionPoints: vi.fn().mockReturnValue([
{
name: 'workflow.beforeExecute',
handler: async (workflow) => {
pluginCalls.push('validate');
return { validated: true, workflow };
}
},
{
name: 'workflow.afterExecute',
handler: async (result) => {
pluginCalls.push('complete');
return { logged: true, result };
}
}
])
};
await pluginManager.loadPlugin(validatorPlugin);
await coordinator.spawnAgent({ id: 'plugin-agent', type: 'coder', capabilities: ['code'] });
const workflow = {
id: 'plugin-workflow',
name: 'Plugin Test',
tasks: [
{
id: 'task-1',
type: 'code',
description: 'Test task',
assignedTo: 'plugin-agent',
priority: 'high' as const
}
]
};
await workflowEngine.executeWorkflow(workflow);
expect(pluginCalls).toContain('validate');
expect(pluginCalls).toContain('complete');
});
it('should handle workflow failures and rollback', async () => {
const executedTasks: string[] = [];
const rolledBackTasks: string[] = [];
await coordinator.spawnAgent({
id: 'failing-agent',
type: 'coder',
capabilities: ['code']
});
const workflow = {
id: 'rollback-workflow',
name: 'Rollback Test',
tasks: [
{
id: 'success-1',
type: 'code',
description: 'Success task 1',
assignedTo: 'failing-agent',
priority: 'high' as const,
onExecute: () => executedTasks.push('success-1'),
onRollback: () => rolledBackTasks.push('success-1')
},
{
id: 'success-2',
type: 'code',
description: 'Success task 2',
assignedTo: 'failing-agent',
priority: 'high' as const,
dependencies: ['success-1'],
onExecute: () => executedTasks.push('success-2'),
onRollback: () => rolledBackTasks.push('success-2')
},
{
id: 'failure',
type: 'code',
description: 'Failing task',
assignedTo: 'failing-agent',
priority: 'high' as const,
dependencies: ['success-2'],
onExecute: () => {
executedTasks.push('failure');
throw new Error('Intentional failure');
},
onRollback: () => rolledBackTasks.push('failure')
}
],
rollbackOnFailure: true
};
const result = await workflowEngine.executeWorkflow(workflow);
expect(result.status).toBe('failed');
expect(executedTasks).toContain('success-1');
expect(executedTasks).toContain('success-2');
expect(rolledBackTasks.length).toBeGreaterThan(0);
});
// SKIP #1872 — real bug: workflowEngine.pauseWorkflow() returns but
// doesn't actually pause; workflow continues to 'completed' instead
// of holding at 'paused'.
it.skip('should support workflow resume after interruption', async () => {
await coordinator.spawnAgent({ id: 'resume-agent', type: 'coder', capabilities: ['code'] });
const workflow = {
id: 'resume-workflow',
name: 'Resume Test',
tasks: [
{ id: 'task-1', type: 'code', description: 'Task 1', assignedTo: 'resume-agent', priority: 'high' as const },
{ id: 'task-2', type: 'code', description: 'Task 2', assignedTo: 'resume-agent', priority: 'high' as const },
{ id: 'task-3', type: 'code', description: 'Task 3', assignedTo: 'resume-agent', priority: 'high' as const }
]
};
// Start workflow
const execution = workflowEngine.startWorkflow(workflow);
// Simulate interruption after first task
await new Promise(resolve => setTimeout(resolve, 100));
await workflowEngine.pauseWorkflow('resume-workflow');
const checkpointState = await workflowEngine.getWorkflowState('resume-workflow');
expect(checkpointState.status).toBe('paused');
// Resume workflow
await workflowEngine.resumeWorkflow('resume-workflow');
const result = await execution;
expect(result.status).toBe('completed');
});
it('should monitor and report workflow metrics', async () => {
await coordinator.spawnAgent({ id: 'metrics-agent', type: 'coder', capabilities: ['code'] });
const workflow = {
id: 'metrics-workflow',
name: 'Metrics Test',
tasks: Array.from({ length: 5 }, (_, i) => ({
id: `metric-task-${i}`,
type: 'code',
description: `Metric task ${i}`,
assignedTo: 'metrics-agent',
priority: 'medium' as const
}))
};
await workflowEngine.executeWorkflow(workflow);
const metrics = await workflowEngine.getWorkflowMetrics('metrics-workflow');
expect(metrics.tasksTotal).toBe(5);
expect(metrics.tasksCompleted).toBe(5);
expect(metrics.totalDuration).toBeGreaterThan(0);
expect(metrics.averageTaskDuration).toBeGreaterThan(0);
expect(metrics.successRate).toBe(1.0);
});
it('should integrate event-driven architecture', async () => {
const events: any[] = [];
eventBus.on('workflow:started', (e) => events.push({ type: 'started', ...e }));
eventBus.on('workflow:taskComplete', (e) => events.push({ type: 'taskComplete', ...e }));
eventBus.on('workflow:completed', (e) => events.push({ type: 'completed', ...e }));
await coordinator.spawnAgent({ id: 'event-agent', type: 'coder', capabilities: ['code'] });
const workflow = {
id: 'event-workflow',
name: 'Event Test',
tasks: [
{
id: 'event-task',
type: 'code',
description: 'Event task',
assignedTo: 'event-agent',
priority: 'high' as const
}
]
};
await workflowEngine.executeWorkflow(workflow);
// Allow async event processing
await new Promise(resolve => setTimeout(resolve, 100));
expect(events.find(e => e.type === 'started')).toBeDefined();
expect(events.find(e => e.type === 'taskComplete')).toBeDefined();
expect(events.find(e => e.type === 'completed')).toBeDefined();
});
it('should support distributed workflow execution', async () => {
// Create multiple coordinators (simulating distributed nodes)
const node1Coordinator = coordinator;
const node2Coordinator = new SwarmCoordinator({
topology: 'mesh',
memoryBackend,
eventBus
});
await node2Coordinator.initialize();
await node1Coordinator.spawnAgent({ id: 'node1-agent', type: 'coder', capabilities: ['code'] });
await node2Coordinator.spawnAgent({ id: 'node2-agent', type: 'coder', capabilities: ['code'] });
const distributedWorkflow = {
id: 'distributed-workflow',
name: 'Distributed Test',
tasks: [
{
id: 'node1-task',
type: 'code',
description: 'Node 1 task',
assignedTo: 'node1-agent',
priority: 'high' as const
},
{
id: 'node2-task',
type: 'code',
description: 'Node 2 task',
assignedTo: 'node2-agent',
priority: 'high' as const
}
]
};
const result = await workflowEngine.executeDistributedWorkflow(
distributedWorkflow,
[node1Coordinator, node2Coordinator]
);
expect(result.status).toBe('completed');
expect(result.tasksCompleted).toBe(2);
await node2Coordinator.shutdown();
});
it('should persist complete workflow state across restarts', async () => {
const workflowState = {
id: 'persistent-workflow',
name: 'Persistence Test',
tasks: [
{ id: 'task-1', type: 'code', description: 'Task 1', priority: 'high' as const }
],
status: 'in-progress',
completedTasks: [],
currentTask: 'task-1'
};
await memoryBackend.store({
id: 'workflow-state',
agentId: 'system',
content: JSON.stringify(workflowState),
type: 'workflow-state',
timestamp: Date.now()
});
// Simulate restart
await workflowEngine.shutdown();
workflowEngine = new WorkflowEngine({
coordinator,
memoryBackend,
eventBus,
pluginManager
});
await workflowEngine.initialize();
(memoryBackend.retrieve as any).mockResolvedValue({
id: 'workflow-state',
agentId: 'system',
content: JSON.stringify(workflowState),
type: 'workflow-state',
timestamp: Date.now()
});
const restored = await workflowEngine.restoreWorkflow('persistent-workflow');
expect(restored).toBeDefined();
expect(restored.id).toBe('persistent-workflow');
expect(restored.status).toBe('in-progress');
});
it('should handle concurrent workflow executions', async () => {
await coordinator.spawnAgent({ id: 'concurrent-worker', type: 'coder', capabilities: ['code'] });
const workflows = Array.from({ length: 5 }, (_, i) => ({
id: `concurrent-workflow-${i}`,
name: `Concurrent ${i}`,
tasks: [
{
id: `task-${i}`,
type: 'code',
description: `Task ${i}`,
assignedTo: 'concurrent-worker',
priority: 'medium' as const
}
]
}));
const results = await Promise.all(
workflows.map(w => workflowEngine.executeWorkflow(w))
);
expect(results).toHaveLength(5);
expect(results.every(r => r.status === 'completed' || r.status === 'failed')).toBe(true);
});
// SKIP #1872 — real bug: nested sub-workflow execution doesn't resolve
// sub-workflow results into the parent's state correctly.
it.skip('should support workflow composition and nesting', async () => {
await coordinator.spawnAgent({ id: 'composer', type: 'coder', capabilities: ['code'] });
const subWorkflow = {
id: 'sub-workflow',
name: 'Sub Workflow',
tasks: [
{
id: 'sub-task-1',
type: 'code',
description: 'Sub task 1',
assignedTo: 'composer',
priority: 'high' as const
},
{
id: 'sub-task-2',
type: 'code',
description: 'Sub task 2',
assignedTo: 'composer',
priority: 'high' as const
}
]
};
const mainWorkflow = {
id: 'main-workflow',
name: 'Main Workflow',
tasks: [
{
id: 'main-task-1',
type: 'code',
description: 'Main task 1',
assignedTo: 'composer',
priority: 'high' as const
},
{
id: 'nested-workflow',
type: 'workflow',
description: 'Execute sub-workflow',
workflow: subWorkflow,
priority: 'high' as const,
dependencies: ['main-task-1']
},
{
id: 'main-task-2',
type: 'code',
description: 'Main task 2',
assignedTo: 'composer',
priority: 'high' as const,
dependencies: ['nested-workflow']
}
]
};
const result = await workflowEngine.executeWorkflow(mainWorkflow);
expect(result.status).toBe('completed');
expect(result.tasksCompleted).toBeGreaterThanOrEqual(4); // 2 main + 2 sub
});
it('should provide comprehensive workflow debugging', async () => {
await coordinator.spawnAgent({ id: 'debug-agent', type: 'coder', capabilities: ['code'] });
const workflow = {
id: 'debug-workflow',
name: 'Debug Test',
debug: true,
tasks: [
{
id: 'debug-task',
type: 'code',
description: 'Debug task',
assignedTo: 'debug-agent',
priority: 'high' as const
}
]
};
const result = await workflowEngine.executeWorkflow(workflow);
const debugInfo = await workflowEngine.getWorkflowDebugInfo('debug-workflow');
expect(debugInfo.executionTrace).toBeDefined();
expect(debugInfo.taskTimings).toBeDefined();
expect(debugInfo.memorySnapshots).toBeDefined();
expect(debugInfo.eventLog).toBeDefined();
});
});