feat: isolate planned deloads from progression

This commit is contained in:
tkyouw committed 2026-08-26 09:54:24 +02:00
1 parent 5314b342ff
commit 26579e4261
25 files changed
+137 -12

No files matched your search

+1
View File
@@ -35,6 +35,7 @@ export function buildCompletedWorkout(active, { end = Date.now(), prs = [], snap
bw: active.bw,
entries,
prs,
...(active.excludeFromProgression === true ? { excludeFromProgression: true } : {}),
...(sessionNote ? { note: sessionNote } : {}),
}
}
+12
View File
@@ -15,6 +15,18 @@ describe('completed workout boundary', () => {
})
})
it('persists progression exclusion only for a marked session', () => {
const active = {
id: 'active-1', d: '2026-08-08', start: 1000, routineId: 'routine-1', name: 'Deload', bw: 80,
excludeFromProgression: true,
entries: [{ id: '0025', sets: [{ done: true, w: 30, r: 8 }], target: { sets: 1, reps: 8 } }],
}
expect(buildCompletedWorkout(active, { end: 2000 }).excludeFromProgression).toBe(true)
const { excludeFromProgression, ...regular } = active
expect(buildCompletedWorkout(regular, { end: 2000 })).not.toHaveProperty('excludeFromProgression')
})
it('persists a muscle snapshot only when the caller supplies one', () => {
const active = {
id: 'active-1', d: '2026-08-08', start: 1000,
+7 -3
View File
@@ -312,9 +312,11 @@ function buildWorkSets(S, cfg, options = {}) {
const n = Math.max(1, cfg.sets || 1)
const mode = modeOf(cfg)
const preferLast = !!options.preferLast
const useTarget = !!options.useTarget
const sets = []
// Last time's set at the same position, falling back to its final set when the plan grew.
const prevAt = i => (last ? (last.sets[i] || last.sets[last.sets.length - 1]) : null)
// A deload routine must use its own prescription instead of carrying regular-session values
// into the workout. Other planned sessions keep the existing history-first behaviour.
const prevAt = i => (!useTarget && last ? (last.sets[i] || last.sets[last.sets.length - 1]) : null)
if (mode === 'cardio') {
for (let i = 0; i < n; i++) {
@@ -339,7 +341,9 @@ function buildWorkSets(S, cfg, options = {}) {
const usable = prev && prev.r > 0 ? prev : null
// Planned sessions may use the confirmed working weight, while freestyle should reproduce
// the load of each matching set when that option is requested.
const w = preferLast && usable ? usable.w : (conf && conf.w > 0 ? conf.w : (usable ? usable.w : cfg.weight))
const w = useTarget
? cfg.weight
: preferLast && usable ? usable.w : (conf && conf.w > 0 ? conf.w : (usable ? usable.w : cfg.weight))
sets.push({ w, r: usable ? usable.r : cfg.reps, done: false })
}
return sets
+8
View File
@@ -493,6 +493,14 @@ describe('buildSets', () => {
.toEqual([{ w: 60, r: 10, done: false }, { w: 62.5, r: 8, done: false }])
})
it('can use a deload target without carrying regular-session values into it', () => {
const S = { exWeights: { [LIFT]: { w: 75 } }, workouts: [{ d: '2026-01-01', entries: [{ id: LIFT, sets: [
{ w: 75, r: 10, done: true }, { w: 75, r: 9, done: true }
] }] }] }
expect(buildSets(S, { id: LIFT, sets: 2, reps: 12, weight: 40 }, { useTarget: true }))
.toEqual([{ w: 40, r: 12, done: false }, { w: 40, r: 12, done: false }])
})
})
describe('applyIntensifierPlan', () => {
+5 -1
View File
@@ -79,7 +79,10 @@ function cleanIntensifier(x) {
/** Build the shareable bundle: every routine, the week schedule, referenced customs. */
export function buildPlanBundle(S, name) {
const routines = (S.routines || []).map(r => ({
id: r.id, name: r.name, emoji: r.emoji, ...(r.prog ? { prog: r.prog } : {}), ex: (r.ex || []).map(cleanEx)
id: r.id, name: r.name, emoji: r.emoji,
...(r.prog ? { prog: r.prog } : {}),
...(r.excludeFromProgression === true ? { excludeFromProgression: true } : {}),
ex: (r.ex || []).map(cleanEx)
}))
const usedIds = new Set(routines.flatMap(r => r.ex.map(e => e.id)))
const customEx = (S.customEx || [])
@@ -160,6 +163,7 @@ export function mergePlan(s, bundle, { schedule } = {}) {
name: r.name || t('Shared routine'),
emoji: r.emoji,
...(r.prog ? { prog: r.prog } : {}),
...(r.excludeFromProgression === true ? { excludeFromProgression: true } : {}),
ex: (r.ex || []).map(e => ({ ...e, id: exIdMap[e.id] || e.id }))
})
})
+12 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest'
import { buildPlanBundle, parsePlan } from './plan-share.js'
import { buildPlanBundle, mergePlan, parsePlan } from './plan-share.js'
// There was no test file for plan sharing at all, which is how a whole prescription field
// went missing without anyone noticing.
@@ -24,6 +24,17 @@ describe('what survives a shared plan', () => {
expect(roundTrip({ warmupSets: 3 }).warmupSets).toBe(3)
})
it('carries progression exclusion on a routine through export and merge', () => {
const source = stateWith({})
source.routines[0].excludeFromProgression = true
const bundle = parsePlan(buildPlanBundle(source, 'Plan'))
const target = { routines: [], week: {}, customEx: [] }
expect(bundle.routines[0].excludeFromProgression).toBe(true)
mergePlan(target, bundle)
expect(target.routines[0].excludeFromProgression).toBe(true)
})
it('drops an intensifier it does not recognise rather than passing it on', () => {
expect(roundTrip({ intensifier: { type: 'nonsense', count: 3 } }).intensifier).toBeUndefined()
})
+4
View File
@@ -134,6 +134,10 @@ export function readSession(entry, fallback) {
export function sessionsFor(S, exId, fallback) {
const out = []
;(S.workouts || []).forEach(w => {
// A planned deload remains a real workout for history and statistics, but it cannot become
// the baseline for the next regular prescription. The routine flag is copied onto the
// active session, then onto this completed workout, so later routine edits do not rewrite it.
if (w.excludeFromProgression === true) return
const entry = w.entries.find(e => e.id === exId)
if (entry && entry.sets.some(s => s.done && !isWarmupRow(s))) out.push({ d: w.d, ...readSession(entry, fallback) })
})
+19
View File
@@ -374,6 +374,25 @@ describe('sessionsFor', () => {
expect(sessionsFor(S, LIFT).map(s => s.d)).toEqual(['2026-01-01'])
})
it('ignores marked deload workouts when it calculates the next regular target', () => {
const target = { sets: 3, reps: 5, weight: 60 }
const entry = (weight, reps) => ({
id: LIFT,
target: { ...target, weight },
sets: reps.map(r => ({ w: weight, r, done: true }))
})
const S = {
unit: 'kg',
workouts: [
{ d: '2026-01-01', entries: [entry(60, [5, 5, 5])] },
{ d: '2026-01-08', excludeFromProgression: true, entries: [entry(30, [8, 8])] }
]
}
expect(sessionsFor(S, LIFT).map(s => s.d)).toEqual(['2026-01-01'])
expect(nextPrescription(S, { id: LIFT, ...target, prog: 'linear' }).weight).toBe(62.5)
})
it('reads a legacy entry that has no target without crashing', () => {
const S = { unit: 'kg', workouts: [{ d: '2026-01-01', entries: [{ id: LIFT, sets: [{ w: 60, r: 5, done: true }] }] }] }
expect(sessionsFor(S, LIFT)).toHaveLength(1)
+1 -1
View File
@@ -27,7 +27,7 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(291)
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(294)
expect(inherited).toHaveLength(449)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list