feat(workout): a per-exercise rest for warm-up ramp sets (warmupRestSec)

An exercise's restSec runs after every set, warm-up ramp included, so a heavy lift with a
150 s working rest also puts 150 s between two light ramp sets. Exercises may now carry a
second optional field, warmupRestSec: the rest between warm-up ramp sets.

- The break after the LAST ramp set (into the first work set) stays the working rest, because
  that is the rest the first heavy set actually needs.
- Without the field nothing changes: ramp sets rest like work sets, exactly as before.
- Like restSec, the field is set by plan files (and by external planners writing routines);
  no new UI, no new string, no locale change. It travels with a shared plan the same way
  restSec does and is dropped when unset.

Where:
- src/lib/supersetFlow.js: warmupRestSecFor(entry, setIdx, workRestSec), the pure rule,
  tested beside it (supersetFlow.test.js)
- src/views/Workout.jsx: the rest started after a checked set goes through it, at all four
  start sites (re-check, singleton, unit done, superset round done)
- src/lib/plan-share.js: export/import passthrough with the same clamp as restSec
  (plan-share.test.js)
- src/views/Workout.test.jsx: 45 s between ramp sets, 150 s after the last ramp set and
  after work sets

Why: a lifter asked for it after two sessions ("warm-up sets have way too large of a rest
period, it should only be 60-90 seconds max") while wanting 90-150 s on the working sets.
The only lever today is one number per exercise.

Tests: cd frontend && npm test -> 1338 passing (93 files), including the new cases.

Compatibility: additive. Old routines, old plan files and old sessions have no field and
behave exactly as before. The API stores routines as opaque JSON, so nothing server-side
changes. The AI Coach's payload allowlist does not include the field (not needed there).
This commit is contained in:
Boris Kurktchiev committed 2026-09-12 08:12:00 -04:00
1 parent 35c810a663
commit 82db21100a
6 files changed
+102 -8

No files matched your search

+4 -2
View File
@@ -53,6 +53,7 @@ function cleanEx(e) {
// only when set, so a plan that never asked for one leaves the recipient's own default
// timer in charge. parsePlan and mergePlan carry it through by spread.
if (e.restSec > 0) o.restSec = e.restSec
if (e.warmupRestSec > 0) o.warmupRestSec = e.warmupRestSec // the ramp's own rest travels with the work rest
if (e.sg) o.sg = e.sg
if (e.note) o.note = e.note
const warm = cleanWarmupSets(e.warmupSets)
@@ -141,8 +142,9 @@ export function parsePlan(raw) {
const warm = cleanWarmupSets(e.warmupSets)
const intens = cleanIntensifier(e.intensifier)
const rest = cleanRestSec(e.restSec)
const { warmupSets, intensifier, restSec, ...passthrough } = e
return { ...passthrough, ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}) }
const warmRest = cleanRestSec(e.warmupRestSec)
const { warmupSets, intensifier, restSec, warmupRestSec, ...passthrough } = e
return { ...passthrough, ...(warm ? { warmupSets: warm } : {}), ...(intens ? { intensifier: intens } : {}), ...(rest ? { restSec: rest } : {}), ...(warmRest ? { warmupRestSec: warmRest } : {}) }
})
}))
return {
+8
View File
@@ -46,6 +46,14 @@ describe('what survives a shared plan', () => {
expect(roundTrip({ restSec: 180 }).restSec).toBe(180)
})
// The ramp's own rest is the same kind of prescription: a shared plan whose warm-up sets
// arrive resting the full working rest is not the plan that was written.
it('carries a per-exercise warm-up rest, and leaves it out when unset', () => {
expect(roundTrip({ restSec: 150, warmupRestSec: 45 }).warmupRestSec).toBe(45)
expect('warmupRestSec' in roundTrip({})).toBe(false)
expect('warmupRestSec' in roundTrip({ warmupRestSec: 0 })).toBe(false)
})
// The absence has to survive too: writing a 0 would pin the recipient's timer to "off"
// instead of letting the exercise keep inheriting whatever their own default is.
it('leaves an exercise that set no rest free of the field', () => {
+21
View File
@@ -1,5 +1,7 @@
// Pure decisions for the active-workout superset flow. Keeping these independent of React and
// the stores makes the uneven-round and re-check rules explicit and directly testable.
import { isWarmupRow } from './workout-model.js'
const hasWork = (entries, idx) => !!entries[idx]?.sets?.some(set => !set.done)
// Return the first unfinished navigation unit after the current one, wrapping once so a user
@@ -89,6 +91,25 @@ export function restSecFor(entries, unit, defaultRestSec) {
}, 0)
}
/**
* The rest a completed set earns when it was a warm-up ramp set.
*
* Ramp sets are light and short, so an exercise may carry its own `warmupRestSec` in its target
* next to `restSec`. It applies between ramp sets only: the break after the LAST ramp set, into
* the first work set, is `workRestSec` (the value restSecFor resolved), because that is the rest
* the first heavy set actually needs. An exercise without the field, or a work set, rests
* `workRestSec` — exactly what every routine did before the field existed.
*/
export function warmupRestSecFor(entry, setIdx, workRestSec) {
const sets = Array.isArray(entry?.sets) ? entry.sets : []
const set = sets[setIdx]
if (!set || !isWarmupRow(set)) return workRestSec
const next = sets.slice(setIdx + 1).find(s => !s.done)
if (!next || !isWarmupRow(next)) return workRestSec
const own = Number(entry?.target?.warmupRestSec)
return own > 0 ? own : workRestSec
}
// Decide where a newly completed superset set goes next. Spent members are skipped, including
// across the wrap. A round ends when no later member in display order has work left; this makes
// the last *active* member the boundary rather than blindly using the group's last array index.
+42 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from './supersetFlow.js'
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor, warmupRestSecFor } from './supersetFlow.js'
const entry = done => ({ sets: done.map(value => ({ done: value })) })
@@ -137,3 +137,44 @@ describe('restSecFor', () => {
expect(restSecFor(undefined, [0], undefined)).toBe(0)
})
})
describe('warmupRestSecFor', () => {
const ramp = (warmupRestSec, done = [false, false, false, false]) => ({
target: { restSec: 150, ...(warmupRestSec ? { warmupRestSec } : {}) },
sets: [
{ phase: 'warmup', w: 60, r: 8, done: done[0] },
{ phase: 'warmup', w: 95, r: 5, done: done[1] },
{ phase: 'work', w: 125, r: 6, done: done[2] },
{ phase: 'work', w: 125, r: 6, done: done[3] },
],
})
it('rests the warm-up rest between ramp sets', () => {
expect(warmupRestSecFor(ramp(45), 0, 150)).toBe(45)
})
it('rests the working rest after the last ramp set, into the first work set', () => {
expect(warmupRestSecFor(ramp(45), 1, 150)).toBe(150)
})
it('rests the working rest after a work set', () => {
expect(warmupRestSecFor(ramp(45), 2, 150)).toBe(150)
expect(warmupRestSecFor(ramp(45), 3, 150)).toBe(150)
})
it('without the field a ramp set rests like a work set (the pre-field behaviour)', () => {
expect(warmupRestSecFor(ramp(null), 0, 150)).toBe(150)
expect(warmupRestSecFor({ target: { warmupRestSec: 0 }, sets: ramp(null).sets }, 0, 90)).toBe(90)
})
it('looks at the next UNFINISHED set: a ramp set re-checked after the work began rests the working rest', () => {
expect(warmupRestSecFor(ramp(45, [true, true, false, false]), 0, 150)).toBe(150)
})
it('is safe on a legacy warmup boolean and on missing entries', () => {
const legacy = { target: { warmupRestSec: 45 }, sets: [{ warmup: true, done: false }, { warmup: true, done: false }, { done: false }] }
expect(warmupRestSecFor(legacy, 0, 120)).toBe(45)
expect(warmupRestSecFor(undefined, 0, 120)).toBe(120)
expect(warmupRestSecFor({ target: {}, sets: [] }, 0, 120)).toBe(120)
})
})