feat(benchmark): enhance benchmark documentation and add emulated run details
fix(benchmark): update deterministic checks and improve measurement accuracy fix(service): refine candidate recording and enhance balance assignment logic test(service): add test for balance recording with preference assignment
This commit is contained in:
1 parent
ff86cf48b4
commit
f1f08356df
5 files changed
+300
-98
No files matched your search
@@ -1660,6 +1660,53 @@ describe('planning calculation context', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('records every eligible balance when a preference keeps the first assignment', async () => {
|
||||
const browserWindow = globalThis.window;
|
||||
vi.stubGlobal('window', undefined);
|
||||
try {
|
||||
const calculation = createPlanningCalculation({
|
||||
horizon: { start: '2024-01-01', end: '2024-01-10' },
|
||||
balances: [
|
||||
balance('later', 'cp', 1, '2026-01-01'),
|
||||
balance('earlier', 'cp', 1, '2025-01-01'),
|
||||
],
|
||||
rules: [
|
||||
{
|
||||
id: 'window',
|
||||
type: 'time_window',
|
||||
force: 'preference',
|
||||
startDate: '2024-01-02',
|
||||
endDate: '2024-01-02',
|
||||
placeDays: 1,
|
||||
placeType: 'cp',
|
||||
},
|
||||
],
|
||||
});
|
||||
const outcome = await calculation.outcome;
|
||||
expect(outcome.kind).toBe('Plan');
|
||||
if (outcome.kind !== 'Plan') return;
|
||||
expect(outcome.placements[0].balanceId).toBe('earlier');
|
||||
|
||||
const trace = await calculation.trace;
|
||||
const candidates =
|
||||
trace?.phases
|
||||
.find((phase) => phase.name === 'preference:window')
|
||||
?.decisions.flatMap((decision) => decision.candidates)
|
||||
.filter((candidate) => candidate.date === '2024-01-02' && candidate.placement)
|
||||
.map((candidate) => ({
|
||||
balanceId: candidate.placement!.balanceId,
|
||||
status: candidate.status,
|
||||
reason: candidate.reason?.code,
|
||||
})) ?? [];
|
||||
expect(candidates.slice(0, 2)).toEqual([
|
||||
{ balanceId: 'earlier', status: 'evaluated-rejected', reason: undefined },
|
||||
{ balanceId: 'later', status: 'not-examined', reason: 'first-compatible-balance' },
|
||||
]);
|
||||
} finally {
|
||||
vi.stubGlobal('window', browserWindow);
|
||||
}
|
||||
});
|
||||
|
||||
it('offers no explanation trace for invalid input and explains conflicts', async () => {
|
||||
const browserWindow = globalThis.window;
|
||||
vi.stubGlobal('window', undefined);
|
||||
|
||||
Reference in new issue
Block a user