Warm-up: die vier verbliebenen Roh-Lesungen von .warmup ueber isWarmupRow, mit Regressionstests

This commit is contained in:
Duarte Santos committed 2026-08-18 11:57:40 +02:00
1 parent 76a2d3b7a5
commit 55b9dcb864
4 files changed
+28 -5

No files matched your search

+2 -2
View File
@@ -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,
)
}
+23 -1
View File
@@ -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)
})
})
+1 -1
View File
@@ -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
}
+2 -1
View File
@@ -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