Keep a repeating week on its weekday when the planner picks the dates
A yearly-repeating period kept the same calendar date instead of the same
weekday: 2026-10-05..10-11 (Mon-Sun) recurred as 2027-10-05..10-11 (Tue-Mon)
rather than 2027-10-04..10-10. The snap added in 224fe7a only ever covered
window_mode == 'fixed'; 'flexible' wishes were unaligned at both stages.
project_window now snaps both modes. A flexible bound is still a bounding
range, but it keeps its weekday alignment year over year with its span held
fixed, so the search space never shrinks and a bound that is exactly as long
as the target (its only candidate) repeats week-shaped.
_rank_candidate gains a Monday-start term between cost and start, so equal-cost
candidates break on week alignment instead of "earliest". It sits after cost
deliberately: a cheaper non-Monday start still wins, because red days outrank
alignment.
_reuse_already_funded_window would otherwise freeze a pre-existing misaligned
placement forever, so it now releases a year whose reuse winner is misaligned
when a fresh search ranks strictly better -- never when one of its days is
pinned or excluded, so a deliberate per-day override always survives.
Migration 008 realigns flexible series already materialised under the old rule;
projection runs once, at create/update, so nothing repairs them on read.
Alongside this, the planner now says when it moved a period to catch red days.
WindowOutcome carries shift_gain_days (the saving over the naive bound-start
placement) and the calendar toasts it, once, on the sync that decided it.
A fixed window is never auto-moved -- its "exact requested placement,
unconditionally" guarantee stands -- but its shift suggestion is no longer
hidden behind a shortfall, so a fully-funded one can surface a cheaper week too.
Editing a period in the popover now also sends window_mode: 'fixed' with a
matching target. Preset chips create flexible wishes; dragging one down to an
exact week left it flexible with a week-long bound, which is the degenerate
single-candidate case that produced the reported dates.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXPBfr1v7F71t6QcbHCaaT
This commit is contained in:
@@ -1557,6 +1557,7 @@ describe('endpoint functions (representative coverage)', () => {
|
||||
},
|
||||
cost_breakdown: { free: 12, vacation: 19, sjukpenning: 11, lagsta: 0 },
|
||||
remedies: [],
|
||||
shift_gain_days: 3,
|
||||
},
|
||||
],
|
||||
warnings: [
|
||||
@@ -1637,6 +1638,7 @@ describe('endpoint functions (representative coverage)', () => {
|
||||
expect(result.surplusAdvice[0]!.daysInvolved).toBe(10)
|
||||
expect(result.age4Projections[0]!.expiringAtB4).toBe(10)
|
||||
expect(result.age4Projections[0]!.fourthBirthday).toBe('2030-01-01')
|
||||
expect(result.outcomes[0]!.shiftGainDays).toBe(3)
|
||||
})
|
||||
|
||||
it('proposePlan defaults a missing cost breakdown field to 0', async () => {
|
||||
@@ -1662,6 +1664,7 @@ describe('endpoint functions (representative coverage)', () => {
|
||||
// must default each one rather than surfacing `undefined`.
|
||||
cost_breakdown: {},
|
||||
remedies: [],
|
||||
shift_gain_days: 0,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
@@ -1680,6 +1683,7 @@ describe('endpoint functions (representative coverage)', () => {
|
||||
sjukpenning: 0,
|
||||
lagsta: 0,
|
||||
})
|
||||
expect(result.outcomes[0]!.shiftGainDays).toBe(0)
|
||||
})
|
||||
|
||||
it('syncPlan posts the workspace id and maps the nested proposal/applyResult/changes', async () => {
|
||||
|
||||
@@ -407,6 +407,7 @@ interface RawWindowOutcome {
|
||||
data: Record<string, unknown>
|
||||
cost_breakdown: Record<string, number>
|
||||
remedies: RawShortfallRemedy[]
|
||||
shift_gain_days: number
|
||||
}
|
||||
|
||||
interface RawPlanWarning {
|
||||
@@ -498,6 +499,7 @@ function toPlanProposal(raw: RawPlanProposal): PlanProposal {
|
||||
data: r.data,
|
||||
daysFreed: r.days_freed,
|
||||
})),
|
||||
shiftGainDays: o.shift_gain_days,
|
||||
})),
|
||||
warnings: raw.warnings.map((w) => ({ kind: w.kind, messageKey: w.message_key, data: w.data })),
|
||||
poolBalances: raw.pool_balances.map((p) => ({
|
||||
|
||||
Reference in New Issue
Block a user