From 55b9dcb864ef3071e8afaa3278ffabf2b49d162c Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Tue, 18 Aug 2026 11:57:40 +0200 Subject: [PATCH] Warm-up: die vier verbliebenen Roh-Lesungen von .warmup ueber isWarmupRow, mit Regressionstests --- frontend/src/lib/history.js | 4 ++-- frontend/src/lib/history.test.js | 24 +++++++++++++++++++++++- frontend/src/lib/progression.js | 2 +- frontend/src/lib/recovery.js | 3 ++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js index a32c3c3..a39b199 100644 --- a/frontend/src/lib/history.js +++ b/frontend/src/lib/history.js @@ -334,7 +334,7 @@ export function cascadeWeight(rows, from, value) { const warm = isWarmupRow(rows[from]) const next = rows.slice() for (let j = from + 1; j < next.length; j++) { - if (!!next[j].warmup === warm && !next[j].done) { + if (isWarmupRow(next[j]) === warm && !next[j].done) { if (value == null) delete next[j].w else next[j].w = value } @@ -368,6 +368,6 @@ export function removeRowAt(rows, i) { /** Completed non-warm-up sets across a workout's entries. */ export function workSetsDone(w) { return (w?.entries || []).reduce( - (n, e) => n + (e.sets || []).filter(s => s.done && !s.warmup).length, 0, + (n, e) => n + (e.sets || []).filter(s => s.done && !isWarmupRow(s)).length, 0, ) } diff --git a/frontend/src/lib/history.test.js b/frontend/src/lib/history.test.js index b264b89..650eada 100644 --- a/frontend/src/lib/history.test.js +++ b/frontend/src/lib/history.test.js @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest' -import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, supersetUnits } from './history.js' +import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, supersetUnits, workSetsDone } from './history.js' import { EXDB } from './exercises.js' // Real ids out of the shipped catalogue, so the body-part fallback is exercised for real. @@ -569,3 +569,25 @@ describe('session row helpers', () => { expect(next[0].w).toBe(70) }) }) + +// The importer writes `phase: 'warmup'` and no `warmup` boolean (import-csv.js), so anything +// reading the raw flag counts an imported warm-up as work. Read through the model instead. +describe('warm-up rows identified by phase alone', () => { + const imported = { w: 40, r: 10, done: true, phase: 'warmup' } + const work = { w: 100, r: 5, done: true } + + it('workSetsDone does not count a phase-only warm-up', () => { + expect(workSetsDone({ entries: [{ sets: [imported, work] }] })).toBe(1) + }) + + it('cascadeWeight keeps phase-only warm-ups in their own lane', () => { + const rows = [ + { w: 40, r: 10, phase: 'warmup' }, + { w: 45, r: 10, phase: 'warmup' }, + { w: 100, r: 5 }, + ] + const next = cascadeWeight(rows, 0, 50) + expect(next[1].w).toBe(50) + expect(next[2].w).toBe(100) + }) +}) diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js index d8f9df6..8248df7 100644 --- a/frontend/src/lib/progression.js +++ b/frontend/src/lib/progression.js @@ -272,7 +272,7 @@ export function applyPrescription(sets, p) { // would both invent work and never terminate the loop. Leave the entry untouched. if (!workRows.length) return out const seed = workRows[workRows.length - 1] - while (out.filter(s => !s.warmup).length < p.sets) out.push({ ...seed, done: false }) + while (out.filter(s => !isWarmupRow(s)).length < p.sets) out.push({ ...seed, done: false }) } return out } diff --git a/frontend/src/lib/recovery.js b/frontend/src/lib/recovery.js index 5d63f00..373786e 100644 --- a/frontend/src/lib/recovery.js +++ b/frontend/src/lib/recovery.js @@ -1,5 +1,6 @@ import { EXIDX } from './exercises.js' import { MUSCLES, musclesOf } from './muscles.js' +import { isWarmupRow } from './workout-model.js' // A "normal" hard session for one muscle, in primary-set equivalents. The saturation curve // 1 - exp(-stimulus / REF) maps any session size onto [0,1) so volume raises the starting @@ -303,7 +304,7 @@ export function strengthOf(workouts, now, opts = {}) { const timestamp = workoutTimestamp(workout) if (!Number.isFinite(timestamp)) continue for (const entry of workout.entries || []) { - if (!(entry.sets || []).some(set => set?.done === true && !set?.warmup)) continue + if (!(entry.sets || []).some(set => set?.done === true && !isWarmupRow(set))) continue for (const slug of Object.keys(musclesOf(EXIDX[entry.id]))) { if (Object.prototype.hasOwnProperty.call(MUSCLES_BY_SLUG, slug) && timestamp > latest[slug]) { latest[slug] = timestamp