sf-agent-framework
Version:
AI Agent Orchestration Framework for Salesforce Development - Two-phase architecture with 70% context reduction
191 lines (158 loc) • 5.48 kB
JavaScript
/**
* Test Example for Simulation Engine
* Demonstrates how simulation runs parallel to actual work
*/
const { OrchestratorSimulation, SimulationCommands } = require('./index');
const yaml = require('js-yaml');
const fs = require('fs').promises;
async function testSimulation() {
console.log('=== SF-Agent Framework Simulation Test ===\n');
// Initialize simulation for sf-orchestrator
const orchestratorSim = new OrchestratorSimulation('sf-orchestrator', {
enabled: true,
visualizationType: 'ascii',
realTimeSync: true,
});
// Load a sample workflow
const workflowData = {
id: 'security-audit-workflow',
name: 'Security Audit Workflow',
sequence: [
{
phase: 'audit_preparation',
duration: '2 days',
steps: [
{ step: 'scope_definition', agent: 'sf-security' },
{ step: 'information_gathering', agent: 'sf-security' },
],
},
{
phase: 'security_assessment',
duration: '5 days',
steps: [
{ step: 'vulnerability_scan', agent: 'sf-security' },
{ step: 'code_review', agent: 'sf-developer' },
{ step: 'permission_audit', agent: 'sf-admin' },
],
},
{
phase: 'remediation',
duration: '3 days',
steps: [
{ step: 'fix_critical_issues', agent: 'sf-developer' },
{ step: 'update_permissions', agent: 'sf-admin' },
{ step: 'validate_fixes', agent: 'sf-qa' },
],
},
],
};
// Load team definition
const teamData = {
name: 'salesforce-core-team',
agents: ['sf-security', 'sf-developer', 'sf-admin', 'sf-qa'],
};
// Start workflow with simulation
console.log('Starting Security Audit Workflow with Simulation...\n');
const workflow = await orchestratorSim.startWorkflow(workflowData, teamData);
// Simulate actual work progress
await simulateActualWork(workflow);
}
async function simulateActualWork(workflow) {
// This simulates how the actual agents would report progress
console.log('\n--- Simulating Actual Agent Work ---\n');
// Phase 1: Audit Preparation
await delay(2000);
workflow.updateProgress({
phase: 'audit_preparation',
task: { name: 'scope_definition', agent: 'sf-security', progress: 25 },
});
await delay(2000);
workflow.updateProgress({
task: { name: 'scope_definition', agent: 'sf-security', progress: 100 },
completedTask: { name: 'scope_definition', agent: 'sf-security' },
});
await delay(2000);
workflow.updateProgress({
task: { name: 'information_gathering', agent: 'sf-security', progress: 50 },
});
await delay(2000);
workflow.updateProgress({
completedTask: { name: 'information_gathering', agent: 'sf-security' },
phase: 'security_assessment',
});
// Phase 2: Security Assessment
await delay(2000);
workflow.updateProgress({
task: { name: 'vulnerability_scan', agent: 'sf-security', progress: 30 },
});
await delay(2000);
workflow.updateProgress({
task: { name: 'code_review', agent: 'sf-developer', progress: 20 },
});
await delay(2000);
workflow.updateProgress({
task: { name: 'permission_audit', agent: 'sf-admin', progress: 40 },
});
// Simulate finding critical issues
await delay(3000);
workflow.updateProgress({
result: 'Found 3 critical vulnerabilities',
completedTask: { name: 'vulnerability_scan', agent: 'sf-security' },
});
await delay(2000);
workflow.updateProgress({
completedTask: { name: 'code_review', agent: 'sf-developer' },
completedTask: { name: 'permission_audit', agent: 'sf-admin' },
phase: 'remediation',
});
// Phase 3: Remediation
await delay(2000);
workflow.updateProgress({
task: { name: 'fix_critical_issues', agent: 'sf-developer', progress: 50 },
});
// Simulate an error (uncomment to test error handling)
// workflow.error(new Error('Failed to apply security patch'));
await delay(3000);
workflow.updateProgress({
completedTask: { name: 'fix_critical_issues', agent: 'sf-developer' },
task: { name: 'update_permissions', agent: 'sf-admin', progress: 100 },
});
await delay(2000);
workflow.updateProgress({
completedTask: { name: 'update_permissions', agent: 'sf-admin' },
task: { name: 'validate_fixes', agent: 'sf-qa', progress: 100 },
});
await delay(2000);
workflow.updateProgress({
completedTask: { name: 'validate_fixes', agent: 'sf-qa' },
progress: 100,
status: 'complete',
result: 'Security audit completed successfully. All critical issues resolved.',
});
// Complete the workflow
workflow.complete();
}
function delay(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
// Test simulation commands
async function testCommands() {
console.log('\n=== Testing Simulation Commands ===\n');
const commands = new SimulationCommands();
// Test status command
const status = await commands.handleCommand('simulation-status');
console.log('Status:', status);
// Test visual command
const visual = await commands.handleCommand('simulation-visual', ['ascii']);
console.log('Visual:', visual);
// Test toggle command
const toggle = await commands.handleCommand('simulation-off');
console.log('Toggle:', toggle);
}
// Run the test
if (require.main === module) {
testSimulation()
.then(() => testCommands())
.catch(console.error);
}
module.exports = { testSimulation, testCommands };