Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

progression: guard set growth against an all-warm-up entry (no work seed, no infinite loop)

rootbee9b64b78da
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index 17d046369..aa613d0a1 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 315f016aa..b1857fde6 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
+ })
})