From 221e365ee8003d92a2c3537f5222e85eddf54fd2 Mon Sep 17 00:00:00 2001 From: Space_Hermes Date: Fri, 28 Aug 2026 08:04:59 +0200 Subject: [PATCH 1/2] fix(workout): label progression guidance --- frontend/src/lib/progression-copy.js | 13 ++++++++++ frontend/src/lib/progression-copy.test.js | 30 +++++++++++++++++++++++ frontend/src/views/Workout.jsx | 6 +++-- frontend/src/views/Workout.test.jsx | 16 ++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 frontend/src/lib/progression-copy.js create mode 100644 frontend/src/lib/progression-copy.test.js diff --git a/frontend/src/lib/progression-copy.js b/frontend/src/lib/progression-copy.js new file mode 100644 index 0000000..d642db2 --- /dev/null +++ b/frontend/src/lib/progression-copy.js @@ -0,0 +1,13 @@ +import { POLICY_NAME } from './progression.js' + +/** + * Presentation-only view of a progression result. The engine remains the source of truth for + * both the outcome and its explanation; this helper only makes the policy behind that result + * explicit in the workout guidance. + */ +export function progressionGuidance(plan) { + if (!plan?.why || plan.kind === 'off' || plan.policy === 'off') return null + const policyLabel = POLICY_NAME[plan.policy] + if (!policyLabel) return null + return { policyLabel, why: plan.why } +} diff --git a/frontend/src/lib/progression-copy.test.js b/frontend/src/lib/progression-copy.test.js new file mode 100644 index 0000000..d49c050 --- /dev/null +++ b/frontend/src/lib/progression-copy.test.js @@ -0,0 +1,30 @@ +import { describe, expect, it } from 'vitest' +import { progressionGuidance } from './progression-copy.js' + +describe('policy-labelled progression guidance', () => { + it('keeps the calculated outcome and identifies the policy that produced it', () => { + const why = ['Every rep last time — {0} {1} more.', 2.5, 'kg'] + + expect(progressionGuidance({ policy: 'linear', kind: 'up', weight: 62.5, why })) + .toEqual({ policyLabel: 'Linear progression', why }) + }) + + it('labels hold and deload outcomes without changing their calculated reasons', () => { + const hold = ['Missed reps last time — same weight again ({0} of {1} to go).', 2, 3] + const deload = ['Missed reps — reset to {0} {1} and work back up.', 55, 'kg'] + + expect(progressionGuidance({ policy: 'double', kind: 'hold', why: hold })) + .toEqual({ policyLabel: 'Double progression', why: hold }) + expect(progressionGuidance({ policy: 'greyskull', kind: 'deload', why: deload })) + .toEqual({ policyLabel: 'Greyskull LP', why: deload }) + }) + + it('labels a baseline outcome and omits policies with no visible outcome', () => { + const baseline = ['Nothing logged yet — this session sets the baseline.'] + expect(progressionGuidance({ policy: 'linear', kind: 'first', why: baseline })) + .toEqual({ policyLabel: 'Linear progression', why: baseline }) + expect(progressionGuidance({ policy: 'off', kind: 'off' })).toBeNull() + expect(progressionGuidance({ policy: 'linear', kind: 'first' })).toBeNull() + expect(progressionGuidance(null)).toBeNull() + }) +}) diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index d0a6279..860f038 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -14,6 +14,7 @@ import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeigh import Icon from '../components/Icon.jsx' import { Button, Check, NumberField } from '../components/ui.jsx' import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.js' +import { progressionGuidance } from '../lib/progression-copy.js' import { glyphOf } from '../lib/glyphs.js' import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps } from '../lib/workout-model.js' @@ -106,6 +107,7 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov // What the progression policy decided for this session, and why (issue #17). Computed when // the session was built so the reason matches the numbers already in the rows. const plan = entry.plan + const guidance = progressionGuidance(plan) // A bodyweight set has no weight to type, so the column is not there (issue #32) — one // stepper instead of two, which is the whole point of the flag. Adding a belt weight in the // config brings it back, now labelled as the addition it is. @@ -190,9 +192,9 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov } {entry.note &&
{entry.note}
} {last &&
{t('Last time')} ({fmtDate(last.d)}): {last.sets.map(s => setLabel(entry.id, s, last.target)).join(', ')}
} - {plan && plan.why && plan.kind !== 'off' &&
+ {guidance &&
- {t(...plan.why)} + {t(guidance.policyLabel)} · {t(...guidance.why)}
}
{/* the header carries the same eff3 sizing as the rows, or the labels drift off their columns */} diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index 0564b8a..bc1c37a 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -155,6 +155,22 @@ describe('Workout set completion flow', () => { }) }) +describe('progression guidance', () => { + it('labels the visible outcome with the policy that calculated it', async () => { + await mount([exercise('plain-bench', [false, false, false], { + plan: { + policy: 'linear', + kind: 'up', + weight: 62.5, + why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'], + }, + })]) + + expect(container.querySelector('.progline')?.textContent) + .toContain('Linear progression · Every rep last time — 2.5 kg more.') + }) +}) + describe('superset flow survives an exercise being removed mid-session', () => { // removeActiveExercise splices A.entries, shifting every index above the removal down. // The high-water marks are index-keyed, so without re-baselining the shifted exercise From 23b1b719a8a24444ed4a87ef9644fe0c750298e7 Mon Sep 17 00:00:00 2001 From: Space_Hermes Date: Fri, 28 Aug 2026 13:45:45 +0200 Subject: [PATCH 2/2] fix(workout): open progression settings from guidance --- frontend/src/index.css | 4 +- frontend/src/views/Workout.jsx | 28 ++++++-- frontend/src/views/Workout.test.jsx | 102 +++++++++++++++++++++++++++- 3 files changed, 124 insertions(+), 10 deletions(-) diff --git a/frontend/src/index.css b/frontend/src/index.css index a348459..71efe1f 100644 --- a/frontend/src/index.css +++ b/frontend/src/index.css @@ -631,8 +631,8 @@ h4.sec{ .setextra .chip.add:disabled{opacity:.35} /* why the next target is what it is (issue #17) */ .progline{ - display:flex;align-items:flex-start;gap:7px;margin:6px 0 2px; - font-size:13px;line-height:1.38;color:var(--acc); + width:100%;display:flex;align-items:flex-start;gap:7px;margin:6px 0 2px;padding:0; + text-align:left;font-size:13px;line-height:1.38;color:var(--acc); } .progline.warn{color:var(--yellow)} .progline svg{flex:none;margin-top:2px} diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index 860f038..b645c92 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -57,7 +57,7 @@ function Elapsed({ start }) { } /* ---------- one exercise block (reps: weight×reps · time: a held duration · cardio: duration+speed) ---------- */ -function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext }) { +function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemoveSet, onAddWarmup, onRemoveSetAt, onStartTimed, onPairPrev, onPairNext, onProgressionSettings }) { const S = useStore(s => s.S) const update = useStore(s => s.update) const working = useUI(s => s.work) @@ -192,10 +192,11 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov
} {entry.note &&
{entry.note}
} {last &&
{t('Last time')} ({fmtDate(last.d)}): {last.sets.map(s => setLabel(entry.id, s, last.target)).join(', ')}
} - {guidance &&
+ {guidance &&
} + }
{/* the header carries the same eff3 sizing as the rows, or the labels drift off their columns */}
{col1.hd}{col2 && {col2.hd}}{col3 && {col3.hd}}{timed && }
@@ -337,6 +338,23 @@ function ActiveWorkout() { const onPairPrev = !isSuperset && cur > 0 ? () => pairAt(cur - 1, cur) : null const onPairNext = !isSuperset && cur < A.entries.length - 1 ? () => pairAt(cur, cur + 1) : null + const openProgressionSettings = idx => { + const state = useStore.getState().S + const entry = state.active?.entries?.[idx] + if (!entry) return + const routine = state.routines.find(r => r.id === state.active.routineId) + exConfigSheet(exOr(entry.id), entry.target, cfg => update(s => { + const activeEntry = s.active?.entries?.[idx] + if (!activeEntry) return + const full = { ...cfg, id: activeEntry.id } + const activeRoutine = s.routines.find(r => r.id === s.active.routineId) + const plan = nextPrescription(s, full, activeRoutine) + activeEntry.target = { ...cfg } + activeEntry.plan = plan + activeEntry.sets = applyPrescription(activeEntry.sets, plan, defaultIncrement(activeEntry.id, s.unit)) + }), null, routine) + } + // Remove a whole exercise from the session. The confirmation always asks first; in a // superset it asks WHICH exercise of the group to remove. const removeExercise = removeActiveExercise @@ -498,11 +516,11 @@ function ActiveWorkout() { {unit.map((idx, k) =>
{ exRefs.current[idx] = el }} className="ss-ex" data-exidx={idx}> {k > 0 &&
+
} toggle(idx, i)} onField={(i, f, v) => setField(idx, i, f, v)} onAddSet={() => addSet(idx)} onRemoveSet={() => removeSet(idx)} onAddWarmup={() => addWarmup(idx)} onRemoveSetAt={i => removeSetAt(idx, i)} onStartTimed={i => startTimed(idx, i)} /> + onToggle={i => toggle(idx, i)} onField={(i, f, v) => setField(idx, i, f, v)} onAddSet={() => addSet(idx)} onRemoveSet={() => removeSet(idx)} onAddWarmup={() => addWarmup(idx)} onRemoveSetAt={i => removeSetAt(idx, i)} onStartTimed={i => startTimed(idx, i)} onProgressionSettings={() => openProgressionSettings(idx)} />
)}
) : ( - toggle(cur, i)} onField={(i, f, v) => setField(cur, i, f, v)} onAddSet={() => addSet(cur)} onRemoveSet={() => removeSet(cur)} onAddWarmup={() => addWarmup(cur)} onRemoveSetAt={i => removeSetAt(cur, i)} onStartTimed={i => startTimed(cur, i)} onPairPrev={onPairPrev} onPairNext={onPairNext} /> + toggle(cur, i)} onField={(i, f, v) => setField(cur, i, f, v)} onAddSet={() => addSet(cur)} onRemoveSet={() => removeSet(cur)} onAddWarmup={() => addWarmup(cur)} onRemoveSetAt={i => removeSetAt(cur, i)} onStartTimed={i => startTimed(cur, i)} onPairPrev={onPairPrev} onPairNext={onPairNext} onProgressionSettings={() => openProgressionSettings(cur)} /> )} :
{t('Freestyle workout — add your first exercise.')}
} diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx index bc1c37a..7f8286f 100644 --- a/frontend/src/views/Workout.test.jsx +++ b/frontend/src/views/Workout.test.jsx @@ -9,6 +9,7 @@ const mocks = vi.hoisted(() => { S: null, startRest: vi.fn(), stopRest: vi.fn(), + exConfigSheet: vi.fn(), topWeightSheet: vi.fn(), } state.storeSnapshot = () => ({ @@ -40,7 +41,7 @@ vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} })) vi.mock('../sheets.jsx', () => ({ startFlow: vi.fn(), exercisePicker: vi.fn(), - exConfigSheet: vi.fn(), + exConfigSheet: mocks.exConfigSheet, exerciseDetailSheet: vi.fn(), topWeightSheet: mocks.topWeightSheet, finishWorkout: vi.fn(), @@ -73,10 +74,14 @@ function exercise(id, sets, extra = {}) { } function workout(entries, cur = 0) { + const routine = { + id: 'routine-1', name: 'Test routine', prog: 'linear', + ex: entries.map(entry => ({ id: entry.id, ...entry.target })), + } return { unit: 'kg', restSec: 90, sound: false, effort: 'none', gifSize: 'full', - workouts: [], exWeights: {}, routines: [], - active: { id: 'active', name: 'Test workout', start: Date.now(), cur, entries }, + workouts: [], exWeights: {}, routines: [routine], + active: { id: 'active', routineId: routine.id, name: 'Test workout', start: Date.now(), cur, entries }, } } @@ -112,6 +117,13 @@ async function toggleSet(index) { await act(async () => { checkbox.dispatchEvent(new dom.Event('click', { bubbles: true })) }) } +async function pressProgression(index = 0) { + const button = container.querySelectorAll('.progline')[index] + expect(button).toBeTruthy() + await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) }) + return button +} + beforeEach(() => { vi.clearAllMocks() }) @@ -169,6 +181,90 @@ describe('progression guidance', () => { expect(container.querySelector('.progline')?.textContent) .toContain('Linear progression · Every rep last time — 2.5 kg more.') }) + + it('is a keyboard-accessible button that opens settings for the pressed grouped entry', async () => { + const plan = { + policy: 'linear', kind: 'up', weight: 62.5, + why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'], + } + const first = exercise('plain-bench', [false], { sg: 'group', plan }) + const second = exercise('plain-bench', [false], { + sg: 'group', plan, target: { mode: 'reps', reps: 8, weight: 80, bodyweight: false }, + }) + await mount([first, second]) + const firstBefore = JSON.stringify(mocks.S.active.entries[0]) + + const button = await pressProgression(1) + + expect(button.tagName).toBe('BUTTON') + expect(button.getAttribute('type')).toBe('button') + expect(button.getAttribute('aria-label')).toBe('Open progression settings') + expect(mocks.exConfigSheet).toHaveBeenCalledOnce() + expect(mocks.exConfigSheet.mock.calls[0][1]).toBe(second.target) + expect(mocks.exConfigSheet.mock.calls[0][4]).toBe(mocks.S.routines[0]) + + mocks.exConfigSheet.mock.calls[0][2]({ ...second.target, prog: 'double', repsMin: 6 }) + expect(JSON.stringify(mocks.S.active.entries[0])).toBe(firstBefore) + expect(mocks.S.active.entries[1].target.prog).toBe('double') + expect(mocks.S.active.cur).toBe(0) + }) + + it('leaves the active entry unchanged when progression settings are cancelled', async () => { + const entry = exercise('plain-bench', [true, false], { + plan: { + policy: 'linear', kind: 'up', weight: 62.5, + why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'], + }, + }) + await mount([entry]) + const before = JSON.stringify(mocks.S.active.entries[0]) + + await pressProgression() + + expect(JSON.stringify(mocks.S.active.entries[0])).toBe(before) + }) + + it('saves the active policy, preserves completed rows, and refreshes guidance immediately', async () => { + const entry = exercise('plain-bench', [true, false], { + plan: { + policy: 'linear', kind: 'up', weight: 62.5, + why: ['Every rep last time — {0} {1} more.', 2.5, 'kg'], + }, + }) + await mount([entry]) + mocks.S.workouts = [{ + d: '2026-08-27', + entries: [{ + id: entry.id, + target: { sets: 2, reps: 5, weight: 60 }, + sets: [{ w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }], + }], + }] + const completed = mocks.S.active.entries[0].sets[0] + await pressProgression() + const save = mocks.exConfigSheet.mock.calls[0][2] + + await act(async () => { + save({ ...entry.target, prog: 'double', repsMin: 3 }) + root.render(React.createElement(Workout)) + }) + + const saved = mocks.S.active.entries[0] + expect(saved.target.prog).toBe('double') + expect(saved.sets[0]).toBe(completed) + expect(saved.sets[0]).toEqual({ w: 60, r: 5, done: true }) + expect(saved.sets[1]).toEqual({ w: 62.5, r: 3, done: false }) + expect(container.querySelector('.progline')?.textContent) + .toContain('Double progression · Top of the rep range in every set — 2.5 kg more, back to 3 reps.') + + const persisted = JSON.parse(JSON.stringify(mocks.S)) + await unmount() + mocks.S = persisted + installDom() + await act(async () => { root.render(React.createElement(Workout)) }) + expect(container.querySelector('.progline')?.textContent) + .toContain('Double progression · Top of the rep range in every set — 2.5 kg more, back to 3 reps.') + }) }) describe('superset flow survives an exercise being removed mid-session', () => {