diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js index f74c6a4..1ad7c69 100644 --- a/frontend/src/lib/history.test.js +++ b/frontend/src/lib/history.test.js @@ -501,6 +501,72 @@ describe('buildSets', () => { .toEqual([{ w: 40, r: 12, done: false }, { w: 40, r: 12, done: false }]) }) + it('uses the current routine target instead of another routine\'s bodyweight history', () => { + const S = { + exWeights: {}, + workouts: [{ + d: '2026-01-01', + routineId: 'routine-a', + entries: [{ + id: BW, + target: { sets: 2, reps: 15, weight: 0, bodyweight: true }, + sets: [{ w: 0, r: 15, done: true }, { w: 0, r: 15, done: true }] + }] + }] + } + const cfg = { id: BW, sets: 4, reps: 8, weight: 0, bodyweight: true, prog: 'off' } + + expect(buildSets(S, cfg, { useTarget: true })).toEqual([ + { w: 0, r: 8, done: false }, + { w: 0, r: 8, done: false }, + { w: 0, r: 8, done: false }, + { w: 0, r: 8, done: false } + ]) + + const reverseS = { + exWeights: {}, + workouts: [{ + d: '2026-01-02', + routineId: 'routine-b', + entries: [{ + id: BW, + target: { sets: 4, reps: 8, weight: 0, bodyweight: true }, + sets: [ + { w: 0, r: 8, done: true }, { w: 0, r: 8, done: true }, + { w: 0, r: 8, done: true }, { w: 0, r: 8, done: true } + ] + }] + }] + } + expect(buildSets(reverseS, { ...cfg, sets: 2, reps: 15 }, { useTarget: true })).toEqual([ + { w: 0, r: 15, done: false }, + { w: 0, r: 15, done: false } + ]) + }) + + it('preserves configured load, reps, duration and cardio targets when history is present', () => { + const repsS = { + exWeights: { [LIFT]: { w: 75 } }, + workouts: [{ d: '2026-01-01', entries: [{ id: LIFT, sets: [{ w: 75, r: 15, done: true }] }] }] + } + expect(buildSets(repsS, { id: LIFT, sets: 2, reps: 8, weight: 40 }, { useTarget: true })) + .toEqual([{ w: 40, r: 8, done: false }, { w: 40, r: 8, done: false }]) + + const timedS = { + exWeights: {}, + workouts: [{ d: '2026-01-02', entries: [{ id: LIFT, target: { mode: 'time' }, sets: [{ sec: 90, w: 20, done: true }] }] }] + } + expect(buildSets(timedS, { id: LIFT, mode: 'time', sets: 2, sec: 30, weight: 5 }, { useTarget: true })) + .toEqual([{ sec: 30, w: 5, done: false }, { sec: 30, w: 5, done: false }]) + + const cardioS = { + exWeights: {}, + workouts: [{ d: '2026-01-03', entries: [{ id: CARDIO, sets: [{ min: 45, speed: 10, done: true }] }] }] + } + expect(buildSets(cardioS, { id: CARDIO, sets: 2, min: 20, speed: 8 }, { useTarget: true })) + .toEqual([{ min: 20, speed: 8, done: false }, { min: 20, speed: 8, done: false }]) + }) + }) describe('applyIntensifierPlan', () => { diff --git a/frontend/src/lib/session-start.js b/frontend/src/lib/session-start.js index 5ca9f50..cf3dd1b 100644 --- a/frontend/src/lib/session-start.js +++ b/frontend/src/lib/session-start.js @@ -14,7 +14,7 @@ export function buildSessionEntries(st, r) { const entries = (r ? r.ex : []).map(cfg => { const plan = excluded ? { policy: 'off', kind: 'off' } : nextPrescription(st, cfg, r) const step = defaultIncrement(cfg.id, st.unit) - const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step, useTarget: excluded }), plan, step), cfg) + const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step, useTarget: plan.kind === 'off' }), plan, step), cfg) return { id: cfg.id, sg: cfg.sg, target: { ...cfg }, plan, sets } }) return { entries, excluded } diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index fafab26..290d7d1 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -662,12 +662,17 @@ function ActiveWorkout() { const routine = S.routines.find(r => r.id === A.routineId) const freestyle = !A.routineId // Freestyle has no routine prescription to apply: show the last target in the config - // sheet and carry its completed rows forward. A planned session keeps its existing path. + // sheet and carry its completed rows forward. A planned session uses its configured + // target when progression is off, while progression-enabled sessions keep their path. const seed = freestyle ? freestyleConfig(S, { id: ex.id, ...defaultConfig(ex.id) }) : null exConfigSheet(ex, null, cfg => update(s => { const full = { ...cfg, id: ex.id } const plan = freestyle ? null : nextPrescription(s, full, s.routines.find(r => r.id === s.active.routineId)) - const sets = buildSets(s, full, { step: defaultIncrement(ex.id, s.unit), ...(freestyle ? { preferLast: true } : {}) }) + const sets = buildSets(s, full, { + step: defaultIncrement(ex.id, s.unit), + ...(freestyle ? { preferLast: true } : {}), + ...(plan?.kind === 'off' ? { useTarget: true } : {}) + }) const progressed = freestyle ? sets : applyPrescription(sets, plan, defaultIncrement(ex.id, s.unit)) const insertAt = insertionIndexAfterCurrentUnit(supersetUnits(s.active.entries), s.active.cur, s.active.entries.length) s.active.entries.splice(insertAt, 0, { id: ex.id, target: { ...cfg }, plan, sets: applyIntensifierPlan(progressed, full) })