Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

history: never seed a session from last time's warm-up rows

Duarte Santos5ff6b7d0a8a8
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.js
index e3aa526ba..ab5e36a97 100644
--- a/frontend/src/lib/history.js
+++ b/frontend/src/lib/history.js
@@ -209,10 +209,18 @@ export function unpairSuperset(items, idx) {
export function lastEntryFor(S, exId) {
for (let i = S.workouts.length - 1; i >= 0; i--) {
const en = S.workouts[i].entries.find(e => e.id === exId)
+ if (!en) continue
+ // Work sets only. Every caller asks the same question — "what did you actually lift last
+ // time" — to seed the next session's rows, to size a freestyle config, and to print "Last
+ // time" on the card. A warm-up answers none of them: seeding position 0 from a 50% ramp row
+ // walks the working weight DOWN a little every session, and counting the ramp rows makes a
+ // 3x5 come back as a 5-set exercise. Warm-ups are already excluded from volume, records and
+ // progression; this is the same rule one level up.
+ const done = en.sets.filter(s => s.done && !isWarmupRow(s))
// `target` is what the session prescribed; finished workouts carry it so labels and the
// progression engine can read a session back the way it was logged. Older workouts have
// none — modeOf() falls back to the body part for them, which is what they were.
- if (en && en.sets.some(s => s.done)) return { d: S.workouts[i].d, sets: en.sets.filter(s => s.done), target: en.target || null }
+ if (done.length) return { d: S.workouts[i].d, sets: done, target: en.target || null }
}
return null
}
diff --git a/frontend/src/lib/notes-render.test.jsx b/frontend/src/lib/notes-render.test.jsx
index 153f829f7..e685b625b 100644
--- a/frontend/src/lib/notes-render.test.jsx
+++ b/frontend/src/lib/notes-render.test.jsx
@@ -2,24 +2,26 @@
// The note sheet is new JSX and nothing else mounts it, so a bad hook order, a missing import or
// a wrong store path would only surface on a real device. Render it through the real sheet stack
// and drive a save, so the wiring is checked and not just the shape of the module.
-import { describe, expect, it, beforeEach } from 'vitest'
+import { describe, expect, it, beforeEach, afterEach } from 'vitest'
import React, { act } from 'react'
import { createRoot } from 'react-dom/client'
-
-// React only enables act() when it is told it is in a test environment.
-globalThis.IS_REACT_ACT_ENVIRONMENT = true
import { useStore } from '../store/useStore.js'
import { useUI } from '../store/useUI.js'
import { exerciseNoteSheet } from '../sheets.jsx'
const activeWith = entry => ({ id: 'w1', d: '2026-08-25', start: 1, routineId: 'r1', name: 'Push', entries: [entry] })
+// Roots have to be torn down between tests: the sheet subscribes to the store, so a root left
+// mounted reacts to the next test's setState — outside act(), which React rightly complains about.
+const mounted = []
+
function renderSheet() {
exerciseNoteSheet(0)
const sheet = useUI.getState().sheets.at(-1)
const host = document.createElement('div')
document.body.appendChild(host)
const root = createRoot(host)
+ mounted.push(root)
act(() => root.render(sheet.render(sheet_close(sheet))))
return host
}
@@ -33,6 +35,9 @@ const type = (el, value) => {
describe('exercise note sheet', () => {
beforeEach(() => {
+ // React only treats act() as real when told it is in a test environment, and vitest shares
+ // a worker across files — so set it per test rather than once at module scope.
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true
useUI.setState({ sheets: [] })
useStore.setState(s => ({
S: { ...s.S, exNotes: {}, active: activeWith({ id: 'bench', sets: [] }) },
@@ -40,6 +45,10 @@ describe('exercise note sheet', () => {
document.body.innerHTML = ''
})
+ afterEach(() => {
+ act(() => { mounted.splice(0).forEach(r => r.unmount()) })
+ })
+
it('renders the session note, the pin and the standing note', () => {
const host = renderSheet()
const areas = host.querySelectorAll('textarea')
diff --git a/frontend/src/lib/warmup-seed.test.js b/frontend/src/lib/warmup-seed.test.js
new file mode 100644
index 000000000..8bdf9929e
--- /dev/null
+++ b/frontend/src/lib/warmup-seed.test.js
@@ -0,0 +1,39 @@
+import { describe, expect, it } from 'vitest'
+import { buildSets } from './history.js'
+
+// A session that logged warm-ups, the way finish-workout persists it: warm-up rows and work
+// rows in one `sets` array, all done.
+const S = {
+ workouts: [{
+ d: '2026-08-24',
+ entries: [{
+ id: 'bench',
+ target: { id: 'bench', sets: 3, reps: 5, weight: 100 },
+ sets: [
+ { w: 50, r: 5, done: true, phase: 'warmup', warmup: true },
+ { w: 75, r: 5, done: true, phase: 'warmup', warmup: true },
+ { w: 100, r: 5, done: true },
+ { w: 100, r: 5, done: true },
+ { w: 100, r: 5, done: true },
+ ],
+ }],
+ }],
+ exWeights: {}, // no confirmed working weight for this exercise
+ routines: [],
+}
+
+describe('seeding the next session from one that had warm-ups', () => {
+ it('does not seed the work sets from the warm-up rows', () => {
+ const cfg = { id: 'bench', sets: 3, reps: 5, weight: 100 }
+ const rows = buildSets(S, cfg)
+ const work = rows.filter(r => r.phase !== 'warmup')
+ expect(work.map(r => r.w)).toEqual([100, 100, 100])
+ })
+
+ it('freestyle reproducing last time also skips the warm-ups', () => {
+ const cfg = { id: 'bench', sets: 3, reps: 5, weight: 100 }
+ const rows = buildSets(S, cfg, { preferLast: true })
+ const work = rows.filter(r => r.phase !== 'warmup')
+ expect(work.map(r => r.w)).toEqual([100, 100, 100])
+ })
+})