From c6d8e873ce01d99a0421f5a9e80a7de2510a3d2d Mon Sep 17 00:00:00 2001 From: arhx91 <41841804-arhx91@users.noreply.gitlab.com> Date: Wed, 2 Sep 2026 17:39:09 +0200 Subject: [PATCH] Fixed and tested deload spiral --- frontend/src/lib/progression.js | 6 +++++- frontend/src/lib/progression.test.js | 29 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js index 9b33cbd..817b48f 100644 --- a/frontend/src/lib/progression.js +++ b/frontend/src/lib/progression.js @@ -145,11 +145,15 @@ export function sessionsFor(S, exId, fallback) { return out } -// How many sessions in a row ended in a miss, counting back from the most recent. +// How many sessions in a row ended in a miss, counting back from the most recent. A change of +// weight starts a new streak, so there won't be a perpetual stall. +// Rationale: deload should reflect the failures in sessions with weight that earned it. +// Not the lighter weight that follows. export function stallCount(sessions) { let n = 0 for (let i = sessions.length - 1; i >= 0; i--) { if (sessions[i].ok) break + if (i < sessions.length -1 && sessions[i].weight !== sessions[i+1].weight) break n++ } return n diff --git a/frontend/src/lib/progression.test.js b/frontend/src/lib/progression.test.js index be56e79..3cc2ae6 100644 --- a/frontend/src/lib/progression.test.js +++ b/frontend/src/lib/progression.test.js @@ -142,6 +142,19 @@ describe('linear progression', () => { expect(p.kind).toBe('hold') }) + it('a deload starts a new streak, so one miss at the new weight does not deload again', () => { + // Three misses at 60 kg earn a deload. + const stalled = [[60, 4, 4, 4], [60, 4, 4, 4], [60, 4, 4, 4]] + const deload = nextPrescription(hist(LIFT, stalled), cfg) + expect(deload.kind).toBe('deload') + + // A bad day at the lighter weight is the first miss of a new run, not the fourth of the old + // one. A deload is owed a fresh set of attempts, not an immediate second cut. + const next = nextPrescription(hist(LIFT, [...stalled, [deload.weight, 4, 4, 4]]), cfg) + expect(next.kind).toBe('hold') + expect(next.weight).toBe(deload.weight) + }) + it('never deloads below one increment, however light the lift already is', () => { const p = nextPrescription(hist(LIFT, [[2.5, 1, 1, 1], [2.5, 1, 1, 1], [2.5, 1, 1, 1]]), cfg) expect(p.kind).toBe('deload') @@ -292,6 +305,22 @@ describe('double progression', () => { expect(p.reps).toBe(8) }) + it('does not deload again when the deload was performed exactly as prescribed', () => { + const target = { sets: 3, reps: 12 } + // Three sessions stuck mid-range where every set misses the top, so a deload falls due (see DELOAD_POLICY) + const stalled = [[40, 9, 9, 9], [40, 9, 9, 9], [40, 9, 9, 9]] + const deload = nextPrescription(hist(LIFT, stalled, target), cfg) + expect(deload.kind).toBe('deload') + + // Training exactly what it asked for: its weight, its reps, every set checked off. + const asPrescribed = [deload.weight, ...Array(target.sets).fill(deload.reps)] + const next = nextPrescription(hist(LIFT, [...stalled, asPrescribed], target), cfg) + + // Complying with the app's own prescription must not be scored as another failure. + expect(next.kind).not.toBe('deload') + expect(next.weight).toBeGreaterThanOrEqual(deload.weight) + }) + it('keeps the weight and asks for one more rep while inside the range', () => { const p = nextPrescription(hist(LIFT, [[40, 10, 9, 9]], { sets: 3, reps: 12 }), cfg) expect(p.kind).toBe('hold')