Files
doormilxpress_astryx/tests/lib/AgentFactory.test.js

67 lines
2.2 KiB
JavaScript

import { AgentFactory } from '@/lib/assistant/agent/AgentFactory';
import { SkillRegistry } from '@/lib/assistant/skills/SkillRegistry';
describe('AgentFactory', () => {
beforeEach(() => {
SkillRegistry.clearRegistryConfig();
});
it('synthesizes an agent from active skills with instructions and tools', () => {
const agent = AgentFactory.synthesizeDefaultAgent();
expect(agent.name).toBe('Doormile Fleet Orchestrator');
expect(agent.activeSkillCount).toBeGreaterThanOrEqual(5);
expect(agent.systemPrompt).toContain('Doormile Autonomous Logistics Fleet Orchestrator');
expect(agent.tools.length).toBeGreaterThan(0);
});
it('evaluates telemetry findings across active skills', () => {
const agent = AgentFactory.synthesizeDefaultAgent();
const sampleRows = [
{
bookingid: 501,
bookingno: 'BK-501',
orderstatus: 'pending',
expecteddeliverytime: '2026-08-31 10:00:00', // overdue compared to 12:00:00
orderdate: '2026-08-31 09:00:00'
}
];
const findings = agent.evaluateTelemetry(sampleRows, '2026-08-31 12:00:00');
expect(findings.length).toBeGreaterThan(0);
expect(findings.some((f) => f.id === 'sla_breached')).toBe(true);
});
it('omits disabled skills from telemetry evaluation', () => {
SkillRegistry.applyRegistryConfig([{ skillid: 'skill_sla_guardian', enabled: false, thresholds: {} }]);
const agent = AgentFactory.synthesizeDefaultAgent();
const sampleRows = [
{
bookingid: 501,
bookingno: 'BK-501',
orderstatus: 'pending',
expecteddeliverytime: '2026-08-31 10:00:00',
orderdate: '2026-08-31 09:00:00'
}
];
const findings = agent.evaluateTelemetry(sampleRows, '2026-08-31 12:00:00');
expect(findings.some((f) => f.id === 'sla_breached')).toBe(false);
});
it('executes active skill tools', async () => {
const agent = AgentFactory.synthesizeDefaultAgent();
const result = await agent.executeSkillTool('reassign_sla_critical_order', {
bookingId: 999,
targetMilerId: 42,
reason: 'Urgent priority'
});
expect(result.success).toBe(true);
expect(result.proposal.action).toBe('reassign_miler');
expect(result.proposal.bookingId).toBe(999);
});
});