From bee9b64b78da853fc126419bb153b549b62d06a2 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 7 Aug 2026 17:03:57 +0200 Subject: [PATCH] progression: guard set growth against an all-warm-up entry (no work seed, no infinite loop) --- frontend/src/lib/progression.js | 5 ++++- frontend/src/lib/progression.test.js | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js index 17d0463..aa613d0 100644 --- a/frontend/src/lib/progression.js +++ b/frontend/src/lib/progression.js @@ -267,7 +267,10 @@ export function applyPrescription(sets, p) { // row that is already there: a session in progress must not lose a set it has logged. const workRows = out.filter(s => !s.warmup) if (p.sets > workRows.length) { - const seed = workRows[workRows.length - 1] || out[out.length - 1] + // An all-warm-up entry has no work row to seed growth from - growing warm-up copies + // would both invent work and never terminate the loop. Leave the entry untouched. + if (!workRows.length) return out + const seed = workRows[workRows.length - 1] while (out.filter(s => !s.warmup).length < p.sets) out.push({ ...seed, done: false }) } return out diff --git a/frontend/src/lib/progression.test.js b/frontend/src/lib/progression.test.js index 315f016..b1857fd 100644 --- a/frontend/src/lib/progression.test.js +++ b/frontend/src/lib/progression.test.js @@ -502,4 +502,13 @@ describe('applyPrescription never touches warm-up rows (round 3)', () => { expect(out.filter(s => s.warmup)).toHaveLength(1) // warm-up untouched expect(out[0]).toEqual({ w: 20, r: 8, done: true, warmup: true }) }) + + it('an all-warm-up entry terminates and stays untouched', () => { + const sets = [ + { w: 20, r: 8, done: true, warmup: true }, + { w: 25, r: 6, done: true, warmup: true }, + ] + const out = applyPrescription(sets, { kind: 'up', weight: 62.5, reps: 5, sets: 4 }) + expect(out).toEqual(sets) // no work row to seed growth from - nothing grows, no loop + }) })