fix: preserve per-side double progression reps

This commit is contained in:
Manuel committed 2026-08-30 01:37:14 +02:00
1 parent a62c75d160
commit 5e6c4d1a75
5 files changed
+46 -19

No files matched your search

+1 -1
View File
@@ -211,7 +211,7 @@ export function nextPrescription(S, cfg, routine) {
return { policy, kind: 'up', weight: 0, reps: next, why: ['Bodyweight — every rep last time, so go for {0} this time.', next] }
}
if (policy === 'double') {
const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin)
const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg))
const top = range.reps
const bottom = range.repsMin
if (last.ok) return { policy, kind: 'up', weight: snap(w + inc, inc), reps: bottom, why: ['Top of the rep range in every set — {0} {1} more, back to {2} reps.', inc, unit, bottom] }
+7
View File
@@ -311,6 +311,13 @@ describe('double progression', () => {
expect(p.reps).toBe(8)
expect(p.weight).toBe(35) // 40 × 0.9 = 36 → nearest loadable 2.5 step
})
it('normalizes persisted per-side bounds before prescribing', () => {
const perSide = { ...cfg, reps: 13, repsMin: 7, side: true }
const p = nextPrescription(hist(LIFT, [[40, 12, 12, 12]], { sets: 3, reps: 13 }), perSide)
expect(p.kind).toBe('hold')
expect(p.reps).toBe(14)
})
})
describe('timed progression', () => {
+9 -4
View File
@@ -1,13 +1,18 @@
// Normalize the two bounds used by double progression.
// `reps` is the upper bound and `repsMin` is the lower bound in persisted configs.
export function normalizeRepRange(reps, repsMin) {
const upper = positiveInt(reps, 10)
const lower = positiveInt(repsMin, Math.max(1, upper - 2))
export function normalizeRepRange(reps, repsMin, stride = 1) {
const step = Number.isInteger(stride) && stride > 0 ? stride : 1
const upper = align(positiveInt(reps, 10), step)
const lower = align(positiveInt(repsMin, Math.max(1, upper - 2)), step)
return lower >= upper
? { reps: lower + 1, repsMin: lower }
? { reps: lower + step, repsMin: lower }
: { reps: upper, repsMin: lower }
}
function align(value, stride) {
return Math.max(stride, Math.ceil(value / stride) * stride)
}
function positiveInt(value, fallback) {
const n = Number(value)
return Number.isFinite(n) && n > 0 ? Math.max(1, Math.round(n)) : fallback
+9
View File
@@ -26,4 +26,13 @@ describe('normalizeRepRange', () => {
it('supplies a usable default lower bound for a small upper bound', () => {
expect(normalizeRepRange(1, undefined)).toEqual({ reps: 2, repsMin: 1 })
})
it('aligns both bounds to an even stride', () => {
expect(normalizeRepRange(13, 7, 2)).toEqual({ reps: 14, repsMin: 8 })
})
it('keeps a valid gap when per-side bounds are invalid', () => {
expect(normalizeRepRange(8, 9, 2)).toEqual({ reps: 12, repsMin: 10 })
expect(normalizeRepRange(0, -2, 2)).toEqual({ reps: 10, repsMin: 8 })
})
})