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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Coach tests: fixture dates move with today
Duarte Santosaa99e8fbc380
diff --git a/api/test/helpers.mjs b/api/test/helpers.mjsindex 418380719..f3403bd93 100644--- a/api/test/helpers.mjs+++ b/api/test/helpers.mjs@@ -53,6 +53,14 @@ export function writeState(dir, uid, S) {fs.writeFileSync(path.join(dir, 'state-' + uid + '.json'), JSON.stringify(S));}+/** A fixture date moved so that 2026-07-20 is always a week ago. The Coach only looks back 12+ weeks from today, so fixed dates expired on their own (2026-10-13); the gaps between them,+ which is what the tests are about, stay as written. */+export function recent(iso) {+ const anchor = Date.UTC(2026, 6, 20), today = new Date(new Date().toISOString().slice(0, 10) + 'T00:00:00Z').getTime();+ return new Date(Date.parse(iso + 'T00:00:00Z') - anchor + today - 7 * 86400000).toISOString().slice(0, 10);+}+/** A profile that has consented and has some history — the usual starting point. */export function sampleState(over = {}) {return {@@ -68,10 +76,10 @@ export function sampleState(over = {}) {week: { 1: 'r1', 3: 'r1', 5: 'r1' },dayPlan: {},exWeights: { '0001': { w: 20 } },- bodyweight: [{ d: '2026-07-01', w: 78 }, { d: '2026-07-20', w: 78.5 }],+ bodyweight: [{ d: recent('2026-07-01'), w: 78 }, { d: recent('2026-07-20'), w: 78.5 }],customEx: [],workouts: [{- id: 'w1', d: '2026-07-20', name: 'Full body A', start: 1000, end: 1000 + 45 * 60000, vol: 600, prs: [],+ id: 'w1', d: recent('2026-07-20'), name: 'Full body A', start: 1000, end: 1000 + 45 * 60000, vol: 600, prs: [],entries: [{id: '0001', target: { sets: 3, reps: 10, weight: 20 },sets: [{ w: 20, r: 10, done: true, rpe: 9.5 }, { w: 20, r: 9, done: true, rpe: 10 }, { w: 20, r: 8, done: true, rpe: 10 }]diff --git a/api/test/payload-bounds.test.js b/api/test/payload-bounds.test.jsindex 0a0b12baf..4f2640ef4 100644--- a/api/test/payload-bounds.test.js+++ b/api/test/payload-bounds.test.js@@ -7,7 +7,7 @@import test from 'node:test';import assert from 'node:assert/strict';import fs from 'node:fs';-import { tempData, sampleState } from './helpers.mjs';+import { tempData, sampleState, recent } from './helpers.mjs';tempData();const payload = await import('../coach/core/payload.js');@@ -144,7 +144,7 @@ const planAndLogFields = {'logged entry id': S => { S.workouts[0].entries[0].id = INJECT; },'logged target': S => { S.workouts[0].entries[0].target = { sets: INJECT, reps: INJECT, sec: INJECT, weight: INJECT }; },'logged set values': S => { Object.assign(S.workouts[0].entries[0].sets[0], { w: INJECT, r: INJECT, sec: INJECT, min: INJECT, speed: INJECT, rir: INJECT, rpe: INJECT }); },- 'body-weight weigh-in': S => { S.bodyweight.push({ d: '2026-07-21', w: INJECT }, { d: '2026-07-21' + INJECT, w: 80 }); },+ 'body-weight weigh-in': S => { S.bodyweight.push({ d: recent('2026-07-21'), w: INJECT }, { d: recent('2026-07-21') + INJECT, w: 80 }); },'target body weight': S => { S.targetW = INJECT; }};@@ -204,7 +204,7 @@ test('the plan and the log a real app writes pass through exactly as before', ()});assert.deepEqual(p.window.workouts.at(-1).entries[0].sets[0], { done: true, w: 20, r: 10, rpe: 9.5 });assert.deepEqual(p.window.workouts.at(-1).entries[0].target, { sets: 3, reps: 10, sec: undefined, weight: 20 });- assert.deepEqual(p.bodyweight, { goal: 80, series: [{ d: '2026-07-20', w: 78.5 }] });+ assert.deepEqual(p.bodyweight, { goal: 80, series: [{ d: recent('2026-07-20'), w: 78.5 }] });});test('the cohort is bounded where it joins the payload, whoever built it', () => {diff --git a/api/test/payload.test.js b/api/test/payload.test.jsindex e2cd95a15..94f580747 100644--- a/api/test/payload.test.js+++ b/api/test/payload.test.js@@ -1,6 +1,6 @@import test from 'node:test';import assert from 'node:assert/strict';-import { tempData, sampleState } from './helpers.mjs';+import { tempData, sampleState, recent } from './helpers.mjs';tempData();const payload = await import('../coach/core/payload.js');@@ -63,7 +63,7 @@ test('review payload carries the plan, the window, effort and aggregates', () =>test('a stalling exercise shows up in the aggregates the way the engine counts it', () => {const S = sampleState();// Three sessions that all fell short of the 10-rep target.- S.workouts = ['2026-07-06', '2026-07-13', '2026-07-20'].map((d, i) => ({+ S.workouts = [recent('2026-07-06'), recent('2026-07-13'), recent('2026-07-20')].map((d, i) => ({id: 'w' + i, d, name: 'A', start: 0, end: 60000, entries: [{id: '0001', target: { sets: 3, reps: 10, weight: 20 },sets: [{ w: 20, r: 9, done: true }, { w: 20, r: 8, done: true }, { w: 20, r: 7, done: true }]@@ -78,7 +78,7 @@ test('a stalling exercise shows up in the aggregates the way the engine counts itest('a set that was never ticked off is a miss, not a gap', () => {const S = sampleState();S.workouts = [{- id: 'w1', d: '2026-07-20', name: 'A', start: 0, end: 60000, entries: [{+ id: 'w1', d: recent('2026-07-20'), name: 'A', start: 0, end: 60000, entries: [{id: '0001', target: { sets: 3, reps: 10, weight: 20 },sets: [{ w: 20, r: 10, done: true }, { w: 20, r: 10, done: true }, { w: 20, r: 10, done: false }]}]@@ -212,10 +212,10 @@ test('declined changes are carried forward so the Coach does not nag', () => {/* ---------- debriefs and the cohort ---------- */const debriefState = () => sampleState({workouts: [- { id: 'w0', d: '2026-07-06', name: 'Full body A', start: 1000, end: 1000 + 40 * 60000, vol: 500, prs: [], entries: [{ id: '0001', sets: [{ w: 18, r: 10, done: true }] }] },- { id: 'wx', d: '2026-07-10', name: 'Other', start: 1000, end: 1000 + 30 * 60000, vol: 100, prs: [], entries: [{ id: '0007', sets: [{ sec: 45, done: true }] }] },- { id: 'w1', d: '2026-07-13', name: 'Full body A', start: 1000, end: 1000 + 42 * 60000, vol: 560, prs: [], entries: [{ id: '0001', sets: [{ w: 20, r: 9, done: true }] }] },- { id: 'w2', d: '2026-07-20', name: 'Full body A', start: 1000, end: 1000 + 45 * 60000, vol: 600, prs: ['0001'], entries: [{ id: '0001', target: { sets: 3, reps: 10, weight: 20 }, sets: [{ w: 20, r: 10, done: true, warmup: true }, { w: 20, r: 10, done: true }, { w: 20, r: 9, done: true }, { w: 20, r: 8, done: false }] }] }+ { id: 'w0', d: recent('2026-07-06'), name: 'Full body A', start: 1000, end: 1000 + 40 * 60000, vol: 500, prs: [], entries: [{ id: '0001', sets: [{ w: 18, r: 10, done: true }] }] },+ { id: 'wx', d: recent('2026-07-10'), name: 'Other', start: 1000, end: 1000 + 30 * 60000, vol: 100, prs: [], entries: [{ id: '0007', sets: [{ sec: 45, done: true }] }] },+ { id: 'w1', d: recent('2026-07-13'), name: 'Full body A', start: 1000, end: 1000 + 42 * 60000, vol: 560, prs: [], entries: [{ id: '0001', sets: [{ w: 20, r: 9, done: true }] }] },+ { id: 'w2', d: recent('2026-07-20'), name: 'Full body A', start: 1000, end: 1000 + 45 * 60000, vol: 600, prs: ['0001'], entries: [{ id: '0001', target: { sets: 3, reps: 10, weight: 20 }, sets: [{ w: 20, r: 10, done: true, warmup: true }, { w: 20, r: 10, done: true }, { w: 20, r: 9, done: true }, { w: 20, r: 8, done: false }] }] }]});@@ -224,11 +224,11 @@ test('a debrief payload carries one session, its predecessors of the same routinassert.equal(p.task, 'debrief');assert.equal(p.session.id, 'w2');assert.equal(p.session.entries[0].sets.length, 4);- assert.deepEqual(p.previous.map(w => w.d), ['2026-07-06', '2026-07-13']);+ assert.deepEqual(p.previous.map(w => w.d), [recent('2026-07-06'), recent('2026-07-13')]);assert.equal('library' in p, false);assert.equal('window' in p, false);assert.ok(p.aggregates && Array.isArray(p.aggregates.exercises));- assert.ok(p.bodyweight.series.every(b => b.d <= '2026-07-20'));+ assert.ok(p.bodyweight.series.every(b => b.d <= recent('2026-07-20')));});test('a set taken to failure reaches the coach as failure, a warm-up never does', () => {@@ -253,10 +253,10 @@ test('an unknown workout id falls back to the latest session', () => {test('workoutMeta counts done work sets, keeps the stored volume and the PR count', () => {const m = payload.workoutMeta(debriefState(), 'w2');- assert.deepEqual(m, { id: 'w2', d: '2026-07-20', name: 'Full body A', minutes: 45, vol: 600, sets: 2, prs: 1 });+ assert.deepEqual(m, { id: 'w2', d: recent('2026-07-20'), name: 'Full body A', minutes: 45, vol: 600, sets: 2, prs: 1 });assert.equal(payload.workoutMeta(sampleState({ workouts: [] }), 'w2'), null);// No stored volume: computed from the work sets.- const S = sampleState({ workouts: [{ id: 'q', d: '2026-07-01', start: 1, end: 60001, entries: [{ id: '0001', sets: [{ w: 10, r: 10, done: true }, { w: 10, r: 10, done: true, phase: 'warmup' }] }] }] });+ const S = sampleState({ workouts: [{ id: 'q', d: recent('2026-07-01'), start: 1, end: 60001, entries: [{ id: '0001', sets: [{ w: 10, r: 10, done: true }, { w: 10, r: 10, done: true, phase: 'warmup' }] }] }] });assert.equal(payload.workoutMeta(S, 'q').vol, 100);});@@ -401,7 +401,7 @@ test('a session note reaches the model whole, bounded only at the app\'s own capid: 'w' + d, d, name: 'A', start: 0, end: 60000, prs: [], note,entries: [{ id: '0001', target: { sets: 3, reps: 10, weight: 20 }, sets: [{ w: 20, r: 10, done: true }] }]});- S.workouts = [mk('2026-09-02', whole), mk('2026-09-03', 'y'.repeat(payload.NOTE_MAX + 100))]; // only a document edited outside the app carries the second+ S.workouts = [mk(recent('2026-09-02'), whole), mk(recent('2026-09-03'), 'y'.repeat(payload.NOTE_MAX + 100))]; // only a document edited outside the app carries the secondconst p = payload.build(S, { handle: handleFor('u1'), kind: 'review' });const [full, edited] = p.window.workouts;assert.equal(full.compact, undefined, 'both sessions are in full detail');diff --git a/api/test/prompt-split.test.js b/api/test/prompt-split.test.jsindex deb80c373..3de86f0c5 100644--- a/api/test/prompt-split.test.js+++ b/api/test/prompt-split.test.js@@ -5,6 +5,7 @@ import { SCHEMAS } from '../coach/core/schemas.js';import { build, FULL_DETAIL_SESSIONS } from '../coach/core/payload.js';import { chatCompletionsSpec } from '../coach/core/adapters/openai.js';import { validatePlan } from '../coach/core/validate.js';+import { recent as fixtureDay } from './helpers.mjs';const S = (workouts = []) => ({lang: 'en', unit: 'kg', routines: [{ id: 'r1', name: 'A', ex: [{ id: '0001', sets: 3, reps: 8 }] }],@@ -76,7 +77,7 @@ test('the create schema caps the two arrays the validator caps, so a repeating m});test('older sessions in a review window are compacted, the recent ones keep full sets', () => {- const many = Array.from({ length: FULL_DETAIL_SESSIONS + 4 }, (_, i) => workout('2026-08-' + String(i + 1).padStart(2, '0')));+ const many = Array.from({ length: FULL_DETAIL_SESSIONS + 4 }, (_, i) => workout(fixtureDay('2026-07-' + String(i + 1).padStart(2, '0'))));const p = build(S(many), { handle: 'h1', kind: 'review' });const w = p.window.workouts;assert.equal(w.length, many.length);diff --git a/api/test/routes.test.js b/api/test/routes.test.jsindex 0f6766a57..0b87cf12d 100644--- a/api/test/routes.test.js+++ b/api/test/routes.test.js@@ -4,7 +4,7 @@import test from 'node:test';import assert from 'node:assert/strict';import http from 'node:http';-import { tempData } from './helpers.mjs';+import { tempData, recent } from './helpers.mjs';tempData();const cfg = await import('../coach/config.js');@@ -229,7 +229,7 @@ test('a debrief is enqueued as its own kind, and the cohort routes gate on the awhile (jobs.status('admin-1').job && Date.now() < until) await new Promise(res => setTimeout(res, 25));const s = jobs.status('admin-1');assert.equal(s.pending.kind, 'debrief');- assert.deepEqual(s.pending.workout, { id: 'w1', d: '2026-07-20', name: 'Full body A', minutes: 45, vol: 600, sets: 3, prs: 0 });+ assert.deepEqual(s.pending.workout, { id: 'w1', d: recent('2026-07-20'), name: 'Full body A', minutes: 45, vol: 600, sets: 3, prs: 0 });assert.equal(s.pending.score, 8);assert.ok(s.pending.summary.includes('3 sets'));assert.ok(Array.isArray(s.pending.nextTime) && s.pending.nextTime.length);