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: renaming a routine with a long name is no longer shown as stale
Duarte Santos7f4cb9b87b9a
diff --git a/frontend/src/lib/coach.js b/frontend/src/lib/coach.jsindex ea4f6e919..b8946c50e 100644--- a/frontend/src/lib/coach.js+++ b/frontend/src/lib/coach.js@@ -133,6 +133,13 @@ export const planHash = S => hashPlan(canonicalPlan(S))const findRoutine = (S, id) => (S.routines || []).find(r => r.id === id) || nullconst findEx = (routine, id) => (routine?.ex || []).find(e => e.id === id) || null+// The Coach reads a routine's name cut at 80 characters (NAME_MAX in api/coach/core/payload.js),+// and the server copies that cut name into a rename's `before`. Compared whole, a longer name+// never matched, and every rename of it was shown as already overtaken by an edit. Not imported+// from payload.js, which would pull the exercise catalogue into the main bundle; coach.test.js+// pins the two together.+export const ROUTINE_NAME_SEEN = 80+/** The plan's current value for whatever a change is about — what `before` is checked against. */export function currentValue(S, change) {const r = findRoutine(S, change.target?.routineId)@@ -146,7 +153,7 @@ export function currentValue(S, change) {case 'inc': return e?.inc ?? nullcase 'exercise-prog': return e?.prog ?? nullcase 'routine-prog': return r?.prog ?? null- case 'rename-routine': return r?.name ?? null+ case 'rename-routine': return r?.name == null ? null : String(r.name).slice(0, ROUTINE_NAME_SEEN)case 'week': return [].concat(S.week?.[change.target?.weekday] ?? []) // routine-id list; [] = restdefault: return undefined // structural changes have no single scalar to compare}diff --git a/frontend/src/lib/coach.test.js b/frontend/src/lib/coach.test.jsindex 6ad25cc60..5fe21a6af 100644--- a/frontend/src/lib/coach.test.js+++ b/frontend/src/lib/coach.test.js@@ -1,6 +1,6 @@import { describe, it, expect } from 'vitest'import {- canonicalPlan, planHash, hashPlan, markStale, applicable, currentValue,+ canonicalPlan, planHash, hashPlan, markStale, applicable, currentValue, ROUTINE_NAME_SEEN,pushSnapshot, revertLast, canRevert, appendLog, applyChangeSet, applyCreatedPlan,recordDismissal, validateProposal, coachAvailable, hasConsent,recordDebrief, logEntry, lightBundle, changeValues,@@ -165,6 +165,22 @@ describe('staleness', () => {expect(markStale(wk(1, ['r1', 'r2']), state({ week: { 1: ['r1', 'r2', 'r3'] } })).changes[0].status).toBe('stale')})+ it('a rename of a routine whose name is longer than the Coach reads is not shown as stale', async () => {+ const { validateReview } = await import('../../../api/coach/core/validate.js')+ const S = state()+ S.routines[0].name = 'Upper body, heavy day — '.repeat(6)+ // The real path: the server's payload cuts the name, and the validator copies what the+ // payload held into `before`.+ const checked = validateReview({ coach_contract: 1, summary: 's', changes: [{ type: 'rename-routine', target: { routineId: 'r1' }, after: 'Upper', why: 'shorter' }] }, serverPayload.cleanPlan(S))+ const [c] = checked.proposal.changes+ expect(c.before.length).toBeLessThan(S.routines[0].name.length)+ expect(markStale(proposal([c]), S).changes[0].status).toBe('proposed')+ // A name edited since the Coach read it is still caught.+ S.routines[0].name = 'Lower ' + S.routines[0].name+ expect(markStale(proposal([c]), S).changes[0].status).toBe('stale')+ expect(ROUTINE_NAME_SEEN).toBe(serverPayload.NAME_MAX)+ })+it('reads the current value for every scalar change type', () => {const S = state()S.routines[0].ex[0].repsMax = 20