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.

warm-up round 3: applyPrescription/readSession never touch warm-up rows; per-phase set numbering; regression tests

root01072ef5e3b6
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index 6b01dc329..17d046369 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -101,7 +101,9 @@ function deloadTo(cur, step) {
export function readSession(entry, fallback) {
const target = (entry && entry.target) || fallback || {}
const mode = modeOf({ ...target, id: entry && entry.id })
- const sets = (entry && entry.sets) || []
+ // Warm-up rows are prep, not the session: one filtered read beats guarding every consumer
+ // below (an undone warm-up otherwise poisons `ok` forever and its reps drag `low`/`count`).
+ const sets = ((entry && entry.sets) || []).filter(s => !s.warmup)
const planned = target.sets || sets.length
const enough = sets.length >= planned
@@ -110,7 +112,7 @@ export function readSession(entry, fallback) {
const held = sets.map(s => (s.done ? (s.sec || 0) : 0))
return {
mode, goal, held,
- weight: Math.max(0, ...sets.filter(s => s.done && !s.warmup).map(s => s.w || 0)),
+ weight: Math.max(0, ...sets.filter(s => s.done).map(s => s.w || 0)),
best: Math.max(0, ...held),
ok: goal > 0 && enough && held.length > 0 && held.every(h => h >= goal)
}
@@ -119,7 +121,7 @@ export function readSession(entry, fallback) {
const reps = sets.map(s => (s.done ? (s.r || 0) : 0))
return {
mode, goal, reps,
- weight: Math.max(0, ...sets.filter(s => s.done && !s.warmup).map(s => s.w || 0)),
+ weight: Math.max(0, ...sets.filter(s => s.done).map(s => s.w || 0)),
count: reps.length, // the dimension bodyweight work grows (#33)
low: reps.length ? Math.min(...reps) : 0,
amrap: reps.length ? reps[reps.length - 1] : 0, // Greyskull's final set
@@ -250,7 +252,10 @@ export function nextPrescription(S, cfg, routine) {
export function applyPrescription(sets, p) {
if (!p || p.kind === 'off' || p.kind === 'first') return sets
const out = sets.map(s => {
- if (s.done && !s.warmup) return s
+ // Never rewrite a logged set, and never rewrite a warm-up: the prescription speaks to
+ // the work rows only (a ticked warm-up falling through here would be the data-loss the
+ // cascade fix removed, two files over).
+ if (s.done || s.warmup) return s
const o = { ...s }
if (p.weight != null) o.w = p.weight
if (p.reps != null) o.r = p.reps
@@ -260,9 +265,10 @@ export function applyPrescription(sets, p) {
// A policy that decided on a set count gets to grow the list — bodyweight progression adds
// a set where a barbell would have added a plate. Only ever upwards, and only by copying a
// row that is already there: a session in progress must not lose a set it has logged.
- if (p.sets > out.length) {
- const seed = out[out.length - 1]
- while (out.length < p.sets) out.push({ ...seed, done: false })
+ const workRows = out.filter(s => !s.warmup)
+ if (p.sets > workRows.length) {
+ const seed = workRows[workRows.length - 1] || out[out.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 e3689aace..315f016aa 100644
--- a/frontend/src/lib/progression.test.js
+++ b/frontend/src/lib/progression.test.js
@@ -450,3 +450,56 @@ describe('applyPrescription', () => {
expect(applyPrescription(sets, { kind: 'up', weight: 60, sets: 1 })).toHaveLength(sets.length)
})
})
+
+
+describe('warm-up rows in session reads (round 3)', () => {
+ it('readSession ignores warm-up rows for reps, count, low and ok', () => {
+ // An undone warm-up (r 0) must not poison `ok` forever; its lighter reps must not
+ // drag `low`/`count` - the warm-up is prep, the session is the work rows.
+ const s = readSession({ id: LIFT, target: { sets: 2, reps: 5, mode: 'reps' }, sets: [
+ { w: 20, r: 8, done: true, warmup: true },
+ { w: 60, r: 5, done: true },
+ { w: 60, r: 6, done: true },
+ ] })
+ expect(s.count).toBe(2)
+ expect(s.low).toBe(5)
+ expect(s.reps).toEqual([5, 6])
+ expect(s.ok).toBe(true)
+ })
+
+ it('readSession keeps an undone warm-up out of held/ok in time mode', () => {
+ const s = readSession({ id: LIFT, target: { sets: 2, sec: 45, mode: 'time' }, sets: [
+ { sec: 45, done: true, warmup: true },
+ { sec: 45, done: true },
+ { sec: 30, done: true },
+ ] })
+ expect(s.held).toEqual([45, 30])
+ expect(s.ok).toBe(false) // the 30s work row is the miss, not the warm-up
+ })
+})
+
+describe('applyPrescription never touches warm-up rows (round 3)', () => {
+ it('leaves a done warm-up exactly as logged', () => {
+ const sets = [
+ { w: 20, r: 8, done: true, warmup: true },
+ { w: 60, r: 5, done: true },
+ { w: 60, r: 5, done: false },
+ ]
+ const out = applyPrescription(sets, { kind: 'up', weight: 62.5, reps: 5 })
+ expect(out[0]).toEqual({ w: 20, r: 8, done: true, warmup: true })
+ expect(out[1]).toEqual({ w: 60, r: 5, done: true })
+ expect(out[2]).toEqual({ w: 62.5, r: 5, done: false })
+ })
+
+ it('grows the work rows, not the warm-up rows, when the policy adds sets', () => {
+ const sets = [
+ { w: 20, r: 8, done: true, warmup: true },
+ { w: 60, r: 5, done: true },
+ { w: 60, r: 5, done: false },
+ ]
+ const out = applyPrescription(sets, { kind: 'up', weight: 62.5, reps: 5, sets: 4 })
+ expect(out.filter(s => !s.warmup)).toHaveLength(4) // 2 existing + 2 grown
+ expect(out.filter(s => s.warmup)).toHaveLength(1) // warm-up untouched
+ expect(out[0]).toEqual({ w: 20, r: 8, done: true, warmup: true })
+ })
+})
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 11d83e97b..2b1a2fddf 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -134,11 +134,13 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
{entry.sets.map((s, i) => {
const warmBefore = i > 0 && !!entry.sets[i - 1].warmup
const isFirstWarmup = !!s.warmup && !warmBefore
+ // Numbering restarts per phase: with two warm-ups the first work set reads 1, not 3.
+ const phaseNum = entry.sets.slice(0, i + 1).filter(x => (x.warmup === true) === (s.warmup === true)).length
return <div key={i}>
{isFirstWarmup && <div className="setph">{t('Warm-up')}</div>}
{!s.warmup && warmBefore && <div className="setsep" />}
<div className={'setrow' + (s.done ? ' done' : '') + (col3 ? ' eff3' : '')}>
- <div className="n">{i + 1}</div>
+ <div className="n">{phaseNum}</div>
{cell(s, i, col1, 'w')}
{col2 && cell(s, i, col2, 'r')}
{col3 && cell(s, i, col3, 'eff')}