From 221e365ee8003d92a2c3537f5222e85eddf54fd2 Mon Sep 17 00:00:00 2001 From: Space_Hermes Date: Fri, 28 Aug 2026 08:04:59 +0200 Subject: [PATCH] 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