40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
import { FleetBalancerSkill } from '@/lib/assistant/skills/definitions/FleetBalancerSkill';
|
|
|
|
describe('FleetBalancerSkill', () => {
|
|
it('detects saturated riders when pending orders are waiting in queue', () => {
|
|
const rows = [
|
|
// 3 active jobs for rider 10
|
|
{ bookingid: 1, userid: 10, ridername: 'Rider A', orderstatus: 'picked' },
|
|
{ bookingid: 2, userid: 10, ridername: 'Rider A', orderstatus: 'active' },
|
|
{ bookingid: 3, userid: 10, ridername: 'Rider A', orderstatus: 'accepted' },
|
|
// 1 pending order in queue
|
|
{ bookingid: 4, userid: null, orderstatus: 'pending' },
|
|
];
|
|
|
|
const findings = FleetBalancerSkill.evaluate(rows, '2026-08-31 12:00:00', { riderActiveCap: 3 });
|
|
expect(findings.length).toBe(1);
|
|
expect(findings[0].id).toBe('rider_saturation');
|
|
expect(findings[0].count).toBe(1);
|
|
});
|
|
|
|
it('does not flag saturation if no unassigned orders are waiting in queue', () => {
|
|
const rows = [
|
|
{ bookingid: 1, userid: 10, ridername: 'Rider A', orderstatus: 'picked' },
|
|
{ bookingid: 2, userid: 10, ridername: 'Rider A', orderstatus: 'active' },
|
|
{ bookingid: 3, userid: 10, ridername: 'Rider A', orderstatus: 'accepted' },
|
|
];
|
|
|
|
const findings = FleetBalancerSkill.evaluate(rows, '2026-08-31 12:00:00', { riderActiveCap: 3 });
|
|
expect(findings.length).toBe(0);
|
|
});
|
|
|
|
it('executes balance_rider_load tool handler', async () => {
|
|
const tool = FleetBalancerSkill.tools.find((t) => t.name === 'balance_rider_load');
|
|
expect(tool).toBeDefined();
|
|
|
|
const result = await tool.handler({ fromMilerId: 10, toMilerId: 20 });
|
|
expect(result.success).toBe(true);
|
|
expect(result.proposal.action).toBe('rebalance_workload');
|
|
});
|
|
});
|