fix(planning): stop IF_THEN patterns at a weekday public holiday
CI / policy (pull_request) Successful in 8s
CI / validate (pull_request) Successful in 30s
CI / test (pull_request) Successful in 3m25s
CI / benchmark (pull_request) Successful in 1m47s
CI / build (pull_request) Successful in 34s
CI / security (pull_request) Successful in 1m27s
CI / images (pull_request) Successful in 1m8s
CI / required (pull_request) Successful in 3s
CI / policy (push) Successful in 7s
CI / validate (push) Successful in 32s
CI / test (push) Successful in 3m25s
CI / benchmark (push) Successful in 1m48s
CI / build (push) Successful in 38s
CI / security (push) Successful in 1m17s
CI / images (push) Successful in 1m9s
CI / required (push) Successful in 1s
CI / policy (pull_request) Successful in 8s
CI / validate (pull_request) Successful in 30s
CI / test (pull_request) Successful in 3m25s
CI / benchmark (pull_request) Successful in 1m47s
CI / build (pull_request) Successful in 34s
CI / security (pull_request) Successful in 1m27s
CI / images (pull_request) Successful in 1m8s
CI / required (pull_request) Successful in 3s
CI / policy (push) Successful in 7s
CI / validate (push) Successful in 32s
CI / test (push) Successful in 3m25s
CI / benchmark (push) Successful in 1m48s
CI / build (push) Successful in 38s
CI / security (push) Successful in 1m17s
CI / images (push) Successful in 1m9s
CI / required (push) Successful in 1s
Pattern days were the nearest working days on each side, so a weekday public holiday was skipped. For Samedi Malin on Saturday 8 May 2027 the planner therefore picked Wednesday 5 and Friday 7 May across Ascension, a pattern the employer does not credit: the answer given at the October 2026 local representatives meeting (Thales group agreement, article 4) keeps only "one CP day on each side" and "two CP days after" that year. Each side now takes the nearest Monday-to-Friday dates, skipping only weekends; a weekday public holiday ends the side, so that split is unavailable. Fixtures that relied on Wednesday 8 May 2024 reaching across Ascension, including the chained earned entitlements benchmark scenario, now place their patterns on the other side of the holiday. The frozen-engine check is unchanged: its 5,000 generated requests plan identically, so the frozen bundle is not rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #334.
This commit is contained in:
1 parent
cfd9a69f33
commit
ea2feaf766
7 files changed
+135
-34
No files matched your search
+4
-1
@@ -118,7 +118,10 @@ A planning rule that guides placement but may remain unsatisfied to preserve val
|
||||
A planning rule evaluated independently for every French public holiday on its configured weekday. A preference requests a complete pattern around each occurrence when possible; an obligation requires it for every occurrence.
|
||||
|
||||
**IF_THEN placement mode**:
|
||||
`before` and `after` fix every requested day on one side; `around` considers every split with at least one day on each side; `auto` considers every split, including the all-before and all-after extremes.
|
||||
`before` and `after` fix every requested day on one side; `around` considers every split with at least one day on each side; `auto` considers every split, including the all-before and all-after extremes. Each side takes the Monday-to-Friday dates nearest the occurrence, skipping only weekends; a split whose side would reach a weekday public holiday is unavailable.
|
||||
|
||||
**Samedi Malin**:
|
||||
The default IF_THEN preference that earns one Other day for a public holiday falling on a Saturday when CP leave placements or declared CP days surround it with at least one working day on each side, or precede or follow it with at least two. RTT and Other days do not count, and a weekday public holiday interrupts a side: in 2027, Saturday 8 May cannot be preceded by two CP days because Thursday 6 May is Ascension.
|
||||
|
||||
**TIME_WINDOW rule**:
|
||||
A planning rule counting compatible leave placements and declared non-working days in an inclusive date window. A preference requests up to its configured quantity; an obligation requires exactly that quantity.
|
||||
|
||||
@@ -85,7 +85,7 @@ Rules are either:
|
||||
- **obligations**, which must all be feasible in the same plan; or
|
||||
- **preferences**, optimized lexicographically in user order.
|
||||
|
||||
`TIME_WINDOW` places a quantity inside an inclusive date window. `IF_THEN` creates before, after, around, or automatic patterns for each matching French public holiday. A completed `IF_THEN` occurrence may earn a new dated leave entitlement after its final time-off period ends.
|
||||
`TIME_WINDOW` places a quantity inside an inclusive date window. `IF_THEN` creates before, after, around, or automatic patterns for each matching French public holiday, from the nearest weekdays on each side; a weekday public holiday interrupts a side. A completed `IF_THEN` occurrence may earn a new dated leave entitlement after its final time-off period ends.
|
||||
|
||||
The outcome is one of:
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ export function benchmarkScenarios(): BenchmarkScenario[] {
|
||||
dayOfWeek: 3,
|
||||
placeDays: 1,
|
||||
placeType: 'cp',
|
||||
placement: 'after',
|
||||
placement: 'before',
|
||||
rewardDays: 1,
|
||||
rewardType: 'rtt',
|
||||
},
|
||||
@@ -102,7 +102,7 @@ export function benchmarkScenarios(): BenchmarkScenario[] {
|
||||
dayOfWeek: 4,
|
||||
placeDays: 1,
|
||||
placeType: 'rtt',
|
||||
placement: 'before',
|
||||
placement: 'after',
|
||||
rewardDays: 0,
|
||||
},
|
||||
],
|
||||
|
||||
@@ -611,7 +611,7 @@ describe('planner explanation and alternative dates', () => {
|
||||
|
||||
it('keeps earned balance metadata consistent when a shared period extends', async () => {
|
||||
const calculation = createPlanningCalculation({
|
||||
horizon: { start: '2024-04-25', end: '2024-05-15' },
|
||||
horizon: { start: '2024-04-25', end: '2024-05-08' },
|
||||
balances: [
|
||||
balance('cp', 'cp', 3, '2024-12-31'),
|
||||
balance('rtt', 'rtt', 0, '2026-01-01'),
|
||||
@@ -749,7 +749,7 @@ describe('planner explanation and alternative dates', () => {
|
||||
})),
|
||||
},
|
||||
{
|
||||
horizon: { start: '2024-04-25', end: '2024-05-15' },
|
||||
horizon: { start: '2024-04-25', end: '2024-05-08' },
|
||||
balances: [
|
||||
balance('cp', 'cp', 2, '2025-01-01'),
|
||||
balance('rtt', 'rtt', 3, '2026-01-01'),
|
||||
@@ -767,14 +767,14 @@ describe('planner explanation and alternative dates', () => {
|
||||
rewardType: 'rtt',
|
||||
},
|
||||
{
|
||||
// Four RTT days from 2 May extend the producing period, so its right comes too late.
|
||||
id: 'consumer',
|
||||
type: 'if_then' as const,
|
||||
type: 'time_window' as const,
|
||||
force: 'obligation' as const,
|
||||
dayOfWeek: 4,
|
||||
startDate: '2024-05-02',
|
||||
endDate: '2024-05-07',
|
||||
placeDays: 4,
|
||||
placeType: 'rtt',
|
||||
placement: 'before',
|
||||
rewardDays: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -360,9 +360,7 @@ describe('supporting placement economy and provenance', () => {
|
||||
}),
|
||||
expect.objectContaining({
|
||||
date: '2024-05-10',
|
||||
// The best-ranked obligation solution placed this date for the producer's
|
||||
// after-pattern before gain ran, so the date keeps no gain credit (ADR 0010).
|
||||
ruleIds: force === 'obligation' ? [] : ['gain'],
|
||||
ruleIds: ['gain'],
|
||||
supporting: true,
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -1159,6 +1159,11 @@ function occurrences(rule: NormalizedRule, context: SearchContext): string[] {
|
||||
return dates;
|
||||
}
|
||||
|
||||
/**
|
||||
* The `count` Monday-to-Friday dates next to `date` on one side. Only weekends
|
||||
* are skipped: a weekday public holiday ends the side early, so no pattern can
|
||||
* reach across it (8 May 2027 cannot be preceded by two days across Ascension).
|
||||
*/
|
||||
function workingNeighbors(
|
||||
date: string,
|
||||
direction: 1 | -1,
|
||||
@@ -1172,7 +1177,10 @@ function workingNeighbors(
|
||||
current = addDays(current, direction)
|
||||
) {
|
||||
context.check?.();
|
||||
if (isWorking(current, context.holidays)) result.push(current);
|
||||
if (!isWeekend(current)) {
|
||||
if (context.holidays.has(current)) break;
|
||||
result.push(current);
|
||||
}
|
||||
// A one-year horizon makes an unbounded malformed search unnecessary.
|
||||
if (
|
||||
compareDate(current, addDays(context.horizon.start, -400)) < 0 ||
|
||||
|
||||
@@ -813,6 +813,94 @@ describe('declared holiday patterns and captured entitlement date', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('Samedi Malin next to another public holiday', () => {
|
||||
// In 2027, 1 and 8 May are Saturdays and Thursday 6 May is Ascension.
|
||||
const samediMalin = {
|
||||
id: 'samedi-malin',
|
||||
type: 'if_then' as const,
|
||||
force: 'preference' as const,
|
||||
dayOfWeek: 6,
|
||||
placement: 'auto' as const,
|
||||
placeDays: 2,
|
||||
placeType: 'cp' as const,
|
||||
rewardDays: 1,
|
||||
rewardType: 'other' as const,
|
||||
};
|
||||
const horizon = { start: '2027-04-26', end: '2027-05-15' };
|
||||
|
||||
beforeEach(() => vi.setSystemTime(new Date('2027-01-04T12:00:00Z')));
|
||||
|
||||
it.each([
|
||||
['2027-05-08', ['2027-05-07', '2027-05-10'], true],
|
||||
['2027-05-08', ['2027-05-10', '2027-05-11'], true],
|
||||
['2027-05-08', ['2027-05-05', '2027-05-07'], false],
|
||||
['2027-05-01', ['2027-04-29', '2027-04-30'], true],
|
||||
] as const)(
|
||||
'decides whether the %s Saturday holiday is earned by declared CP on %j',
|
||||
async (occurrence, dates, earned) => {
|
||||
const result = isPlan(
|
||||
await runInNonBrowser({
|
||||
horizon,
|
||||
balances: [],
|
||||
rules: [samediMalin],
|
||||
declaredDays: dates.map((date) => ({ date, type: 'cp' as const })),
|
||||
}),
|
||||
);
|
||||
const contribution = result.ifThenContributions?.find(
|
||||
(item) => item.occurrence === occurrence,
|
||||
);
|
||||
expect(Boolean(contribution?.earnedEntitlement)).toBe(earned);
|
||||
expect(
|
||||
result.remainingBalances.some(
|
||||
({ id }) => id === `earned:samedi-malin:${occurrence}`,
|
||||
),
|
||||
).toBe(earned);
|
||||
},
|
||||
);
|
||||
|
||||
it('does not place the 8 May 2027 Samedi Malin across Ascension', async () => {
|
||||
const result = isPlan(
|
||||
await runInNonBrowser({
|
||||
horizon: { start: '2027-05-03', end: '2027-05-15' },
|
||||
balances: [
|
||||
{
|
||||
id: 'cp',
|
||||
type: 'cp',
|
||||
quantity: 2,
|
||||
availableFrom: '2027-01-01',
|
||||
expiryDate: '2027-05-31',
|
||||
},
|
||||
],
|
||||
rules: [samediMalin],
|
||||
}),
|
||||
);
|
||||
const dates = result.placements.map(({ date }) => date);
|
||||
expect(dates).not.toContain('2027-05-05');
|
||||
expect(dates).toHaveLength(2);
|
||||
expect(
|
||||
result.ifThenContributions?.find(({ occurrence }) => occurrence === '2027-05-08')
|
||||
?.earnedEntitlement,
|
||||
).toBeDefined();
|
||||
});
|
||||
|
||||
it('cannot oblige two CP immediately before 8 May 2027', async () => {
|
||||
const result = await runInNonBrowser({
|
||||
horizon: { start: '2027-05-03', end: '2027-05-15' },
|
||||
balances: [
|
||||
{
|
||||
id: 'cp',
|
||||
type: 'cp',
|
||||
quantity: 2,
|
||||
availableFrom: '2027-01-01',
|
||||
expiryDate: '2027-05-31',
|
||||
},
|
||||
],
|
||||
rules: [{ ...samediMalin, force: 'obligation', placement: 'before' }],
|
||||
});
|
||||
expect(result.kind).toBe('PlanningConflict');
|
||||
});
|
||||
});
|
||||
|
||||
describe('planLeave', () => {
|
||||
it.each([
|
||||
['obligation', false],
|
||||
@@ -2736,24 +2824,28 @@ describe('planLeave', () => {
|
||||
expect(aroundTwo.placements).toHaveLength(2);
|
||||
|
||||
for (const mode of ['before', 'after', 'auto'] as const) {
|
||||
const result = isPlan(
|
||||
await runInNonBrowser({
|
||||
horizon: { start: '2024-04-25', end: '2024-05-15' },
|
||||
balances: [balance(`cp-${mode}`, 'cp', 2)],
|
||||
rules: [
|
||||
{
|
||||
id: `rule-${mode}`,
|
||||
type: 'if_then',
|
||||
force: 'obligation',
|
||||
dayOfWeek: 3,
|
||||
placeDays: 1,
|
||||
placeType: 'cp',
|
||||
placement: mode,
|
||||
rewardDays: 0,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
const outcome = await runInNonBrowser({
|
||||
horizon: { start: '2024-04-25', end: '2024-05-15' },
|
||||
balances: [balance(`cp-${mode}`, 'cp', 2)],
|
||||
rules: [
|
||||
{
|
||||
id: `rule-${mode}`,
|
||||
type: 'if_then',
|
||||
force: 'obligation',
|
||||
dayOfWeek: 3,
|
||||
placeDays: 1,
|
||||
placeType: 'cp',
|
||||
placement: mode,
|
||||
rewardDays: 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
// Ascension on Thursday 9 May 2024 leaves Wednesday 8 May without a day after it.
|
||||
if (mode === 'after') {
|
||||
expect(outcome.kind).toBe('PlanningConflict');
|
||||
continue;
|
||||
}
|
||||
const result = isPlan(outcome);
|
||||
expect(result.placements).toHaveLength(2);
|
||||
expect(
|
||||
result.placements.every((placement) => placement.ruleIds.includes(`rule-${mode}`)),
|
||||
@@ -3959,7 +4051,7 @@ describe('planning calculation context', () => {
|
||||
dayOfWeek: 3,
|
||||
placeDays: 1,
|
||||
placeType: 'cp',
|
||||
placement: 'after',
|
||||
placement: 'before',
|
||||
rewardDays: 1,
|
||||
rewardType: 'rtt',
|
||||
},
|
||||
@@ -3970,7 +4062,7 @@ describe('planning calculation context', () => {
|
||||
dayOfWeek: 4,
|
||||
placeDays: 1,
|
||||
placeType: 'rtt',
|
||||
placement: 'before',
|
||||
placement: 'after',
|
||||
rewardDays: 0,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user