update on the agents and registry side
This commit is contained in:
78
tests/lib/skills/SlaGuardianSkill.test.js
Normal file
78
tests/lib/skills/SlaGuardianSkill.test.js
Normal file
@@ -0,0 +1,78 @@
|
||||
import { SlaGuardianSkill } from '@/lib/assistant/skills/definitions/SlaGuardianSkill';
|
||||
|
||||
describe('SlaGuardianSkill', () => {
|
||||
const fixedNow = '2026-08-31 12:00:00';
|
||||
|
||||
it('detects breached SLA orders', () => {
|
||||
const rows = [
|
||||
{
|
||||
bookingid: 1,
|
||||
bookingno: 'BK-1',
|
||||
orderstatus: 'pending',
|
||||
expecteddeliverytime: '2026-08-31 11:30:00', // 30 min overdue
|
||||
},
|
||||
{
|
||||
bookingid: 2,
|
||||
bookingno: 'BK-2',
|
||||
orderstatus: 'delivered', // terminal, should be ignored
|
||||
expecteddeliverytime: '2026-08-31 11:30:00',
|
||||
},
|
||||
];
|
||||
|
||||
const findings = SlaGuardianSkill.evaluate(rows, fixedNow);
|
||||
const breach = findings.find((f) => f.id === 'sla_breached');
|
||||
|
||||
expect(breach).toBeDefined();
|
||||
expect(breach.count).toBe(1);
|
||||
expect(breach.rows[0].bookingid).toBe(1);
|
||||
});
|
||||
|
||||
it('detects at-risk SLA orders within custom threshold window', () => {
|
||||
const rows = [
|
||||
{
|
||||
bookingid: 10,
|
||||
bookingno: 'BK-10',
|
||||
orderstatus: 'accepted',
|
||||
expecteddeliverytime: '2026-08-31 12:20:00', // due in 20 min
|
||||
},
|
||||
];
|
||||
|
||||
// Default window is 45 min -> should match
|
||||
const findings = SlaGuardianSkill.evaluate(rows, fixedNow, { slaRiskWindowMin: 45 });
|
||||
expect(findings.some((f) => f.id === 'sla_at_risk')).toBe(true);
|
||||
|
||||
// If threshold overridden to 15 min -> should not match 20 min
|
||||
const restricted = SlaGuardianSkill.evaluate(rows, fixedNow, { slaRiskWindowMin: 15 });
|
||||
expect(restricted.some((f) => f.id === 'sla_at_risk')).toBe(false);
|
||||
});
|
||||
|
||||
it('detects unassigned aging orders', () => {
|
||||
const rows = [
|
||||
{
|
||||
bookingid: 20,
|
||||
bookingno: 'BK-20',
|
||||
orderstatus: 'pending',
|
||||
orderdate: '2026-08-31 10:30:00', // 90 min old
|
||||
},
|
||||
];
|
||||
|
||||
const findings = SlaGuardianSkill.evaluate(rows, fixedNow, { unassignedAgingMin: 60 });
|
||||
expect(findings.some((f) => f.id === 'unassigned_aging')).toBe(true);
|
||||
});
|
||||
|
||||
it('executes reassign_sla_critical_order tool handler', async () => {
|
||||
const tool = SlaGuardianSkill.tools.find((t) => t.name === 'reassign_sla_critical_order');
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const result = await tool.handler({
|
||||
bookingId: 101,
|
||||
targetMilerId: 55,
|
||||
reason: 'Urgent priority reassignment',
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(result.proposal.action).toBe('reassign_miler');
|
||||
expect(result.proposal.bookingId).toBe(101);
|
||||
expect(result.proposal.milerId).toBe(55);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user