Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ app/node_modules/
app/smoke/.smoke.mjs
app/.mdtest.mjs
app/.planflowtest.mjs
app/.editingtest.mjs
app/.editingdomtest.mjs
app/.blockmenudomtest.mjs

# Your actual training log and its snapshots. Runtime state, not source:
# it changes on every session and would be pure merge noise. Back it up with
Expand Down
38 changes: 35 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ reasons behind the design, and the things that have been removed on purpose.
| `app/` | React 19 + Vite frontend. `app/src/` is the UI; `app/src/lib/` is the pure logic, tested without a DOM. |
| `server/` | Plain Node `http`/`fs`/`crypto`, no npm dependencies. |
| `mobile/` | The native iPhone app (Expo). The web's phone layout rebuilt in React Native, with `app/src/lib/` copied in at the same paths. Its own install and rules: read `mobile/AGENTS.md` before changing it, and port a web change there when it touches a screen the app has. |
| `content/starter.json` | What a fresh install runs on: catalogs and the rest card, no programme. **Generated.** |
| `content/starter.json` | What a fresh install runs on: catalogs, the rest card, and two plain climbing cards (Bouldering, Rock climbing, #97), no programme. **Generated.** |
| `content/exercises.json` | The shared exercise library (#63, written by #64), merged into every plan's lift catalog as it is served (§5). Optional: an install without it runs on the plan alone. `test/fixtures/exercises.json` is a small one the suites use. |
| `examples/plan.json` | A small, invented example plan (Settings → "Use the example plan"). **Generated.** |
| `test/fixtures/plan.json` | A large synthetic climbing-and-triathlon programme used by the test suites (smoke render, every app suite, `starter.test.mjs`) and by `starter.build.mjs` / `muscles.build.mjs`. The canonical fixture, and the source both generated files are built from. |
Expand Down Expand Up @@ -890,6 +890,23 @@ no rebuild. An older plan file may also carry `recommender`, `checkin`, `journal
`MAX_CLIMBS`, 99, the bound the per-rep grade pickers share). Switching it off strips the
list, and asks first when anything was said on it (`saidIn`). Per-rep grade pickers have
the same bound (`repCount`), so a lap's grade and its record always pair up.
- **Described climbs are the count** (#97). With the detail off a row counts its `reps`.
With it on, the list holds the count as blank records, which are the count standing in
(often the plan's prefill), never climbs: once ANY climb in a row is described (something
said on its record, or a doubled lap's grade picked), the described climbs are the row's
count; until one is, `reps` stands. `climbsCounted` in `lib/grades.js` is the one statement
of it, and every reader goes through it: `climbVolume` (Climbs per week, `climbLine`),
`lengthsIn`, `totalReps`, and the set logs' foot (`climbTotals`). The form says the rest
are "not described, so not counted". A read rule: nothing stored is rewritten, and a row
whose climbs are all described reads as it always did.
- **One climbing line everywhere** (#97): Today's row, "Last time you did this" and the Log
all say `climbLine` ("5 routes · hardest 5.10"), never "1 set". A card's typed "hardest"
field is left out of the form while the session has graded climbs on its ladder
(`mootHardest`): every reader takes the climbs then, so it was a second, ignored answer.
- **A climbing card being logged opens on its log** (#97): on a sheet for today or earlier,
a card whose log counts climbs (`climbLogLeads` in `session.jsx`) shows its dose, "last
time", the log, then the protocol and evidence in one fold ("About this session",
`SessionAbout`). A day still to come is planning and keeps the protocol open.
- **Lifts are chosen at log time**, so they are `out.lifts` (one record per exercise with
`implement` and `sets: [{ reps, weight }]`), not `out.sets`. Rows store their own
`name`/`implementLabel` so retiring a catalog entry never blanks history. The exercise
Expand Down Expand Up @@ -1180,7 +1197,22 @@ no rebuild. An older plan file may also carry `recommender`, `checkin`, `journal
the page draws whichever apply and have data. Two points minimum for a line.
- **Groups render in registry order, and Climbing is last.** The page leads with workouts
and time for the period; hard finger days are a Climbing chart. Pinned in
`progress.test.js` (`climbing charts come after the general ones`).
`progress.test.js` (`climbing charts come after the general ones`). The one exception
(#97): with **Climbing picked** as the activity the Climbing group leads (`metricsFor`),
because the person asked about climbing. Inside the group the pyramids and hardest sent
come first, then climbs per week and hard finger days.
- **Hardest sent is like with like** (#97): the best of each WEEK, at the day it was sent,
and each point carries the card it came from (`of`); the chart's change is measured
from the earliest point of the newest point's card (`deltaBase` in `lib/vizscale.js`).
Points with no `of` compare first to last. **Volume cards are not a hardest send**
(`volumeCard` in `metrics.js`): a card whose declared finger load (`sched.fingerLoad`,
else its category's) is `light`, `sub` or `none` (ARC, traverses, doubled lead laps,
the economy drill) is left out of both hardest lines, so an ARC day never reads as a
drop; its climbs still count in the pyramids and Climbs per week. Read off the
declaration, never a list of names; a card that declares neither is kept.
- **Hard finger days have one rule**, `hardDates` in `lib/fingers.js`; Progress reads it.
- **Gear hours are typed or measured time only** (`loggedMinutes`), never the card's
estimate that `data.minutes` carries when nothing was typed (#97).
- Charts are titled in plain words ("Effort per week", not "training load"); the effort
chart is still sRPE (RPE × minutes), which is why minutes are measured when possible.

Expand Down Expand Up @@ -1566,7 +1598,7 @@ What that means for the code that stays:
from `settings.json` on the next save, as any removed setting always was.
- **Climbing follows, it does not lead.** In Log a workout the sports catalog comes first
and the Climbing folders after it; on Progress the headline is general and the Climbing
group is last. Both are ordered in code, because the owner's plan file is outside the
group is last (unless Climbing is the activity picked, #97). Both are ordered in code, because the owner's plan file is outside the
repo and cannot be reordered from here. The one exception is a single **Climbing** row
under Recent in Log a workout (#81): a door, the same as Recent being the person's own
history, not climbing leading the catalog.
Expand Down
92 changes: 92 additions & 0 deletions app/blockmenu.dom.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// The block's ⋯ (editor.jsx BlockMenu) in a real DOM (happy-dom), driven as a
// phone drives it: a tap takes no focus, so a name being typed is never blurred
// into the plan. Every action in the menu carries it (#95 review: Circuit turned
// the block into another component and the name box reset to "New block").
// Bundled by esbuild (JSX) and run in node.
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
import { Window } from 'happy-dom'

const win = new Window({ url: 'http://localhost/' })
win.matchMedia = (q) => ({ matches: /coarse/.test(q), media: q, addEventListener() {}, removeEventListener() {}, addListener() {}, removeListener() {} })
for (const k of ['window', 'document', 'navigator', 'MutationObserver', 'HTMLElement', 'HTMLIFrameElement', 'HTMLInputElement', 'Node', 'Event', 'getComputedStyle', 'localStorage']) {
const value = k === 'window' ? win : k === 'getComputedStyle' ? win.getComputedStyle.bind(win) : win[k]
Object.defineProperty(globalThis, k, { value, configurable: true, writable: true })
}
win.scrollTo = () => {}
globalThis.IS_REACT_ACT_ENVIRONMENT = true

const { act, useState } = await import('react')
const { createRoot } = await import('react-dom/client')
const { PrescriptionEditor } = await import('./src/editor.jsx')
const { normalizePrescription } = await import('./src/lib/prescription.js')
const { liftFieldOf } = await import('./src/lib/lifts.js')
const PLAN = createRequire(import.meta.url)('../test/fixtures/plan.json')
const liftField = liftFieldOf(PLAN)

const tests = []
const test = (name, fn) => tests.push([name, fn])

let latest = null
function Host({ start }) {
const [pres, setPres] = useState(start)
latest = pres
return <PrescriptionEditor pres={pres} onChange={setPres} liftField={liftField} categories={PLAN.quotaCategories} />
}

async function mount(start) {
const host = document.createElement('div')
document.body.appendChild(host)
const root = createRoot(host)
await act(async () => root.render(<Host start={start} />))
return () => act(() => root.unmount())
}

const click = (el) => act(() => { el.dispatchEvent(new win.MouseEvent('click', { bubbles: true })) })
const byText = (re) => [...document.querySelectorAll('button')].find(b => re.test(b.textContent.trim()))
/** Type into a controlled box the way React hears it, and never blur it (a phone's tap). */
const typeInto = (input, value) => act(() => {
const set = Object.getOwnPropertyDescriptor(win.HTMLInputElement.prototype, 'value').set
set.call(input, value)
input.dispatchEvent(new win.Event('input', { bubbles: true }))
})
const nameBox = () => document.querySelector('.blockmenu-name input')

const START = normalizePrescription({ title: 'Legs', blocks: [
{ name: 'Main', items: [{ kind: 'interval', name: 'Spin', sets: [{ seconds: 300 }] }] },
] }, { liftField })

test('a name being typed survives Circuit (the block becomes another component)', async () => {
const done = await mount(START)
await click(byText(/^Add a block$/))
assert.equal(nameBox().value, 'New block')
await typeInto(nameBox(), 'Finisher')
await click(document.querySelector('.blockmenu input[role=switch]'))
const b = latest.blocks.at(-1)
assert.ok(b.circuit, 'Circuit did not switch on')
assert.equal(b.name, 'Finisher', 'the name being typed was thrown away when Circuit was tapped')
assert.equal(nameBox()?.value, 'Finisher', 'the reopened menu shows the old name')
await done()
})

test('a name being typed goes with a move, and with Where it lands', async () => {
const done = await mount(START)
await click(byText(/^Add a block$/))
await typeInto(nameBox(), 'Cool-down')
await click(byText(/^Move block up$/))
assert.deepEqual(latest.blocks.map(x => x.name), ['Cool-down', 'Main'], 'the move lost the name')
await typeInto(nameBox(), 'Warm-up')
await click(byText(/^Where it lands/))
const run = PLAN.quotaCategories.find(c => c.key === 'run') || PLAN.quotaCategories[0]
await click(byText(new RegExp(`^A separate ${run.name} workout$`)))
assert.deepEqual([latest.blocks[0].name, latest.blocks[0].category], ['Warm-up', run.key])
await done()
})

let failed = 0
for (const [name, fn] of tests) {
try { await fn(); console.log(` PASS ${name}`) } catch (e) { failed++; console.log(` FAIL ${name}\n ${e.message}`) }
}
console.log(`block menu (dom): ${tests.length - failed} passed${failed ? `, ${failed} failed` : ''}`)
await win.happyDOM.close()
process.exit(failed ? 1 : 0)
116 changes: 116 additions & 0 deletions app/editing.dom.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// The footer policy in a real DOM (happy-dom), for EACH layer that has a footer:
// the session sheet (`Modal`) and the planner (`FullScreen`'s sticky bar). The
// owner's bug class (#77) and its sequel (C N1, reproduced by the G regrade in
// both): a box that has focus is REMOVED, as the exercise picker's search box
// is when an exercise is picked, and on iOS the row tapped takes no focus, so
// no blur reaches React and the footer stayed hidden with nothing saying why.
// Bundled by esbuild (JSX) and run in node.
import assert from 'node:assert/strict'
import { Window } from 'happy-dom'

const win = new Window({ url: 'http://localhost/' })
// A finger, not a mouse: the footer only hides on a touch screen.
win.matchMedia = (q) => ({ matches: /coarse/.test(q), media: q, addEventListener() {}, removeEventListener() {}, addListener() {}, removeListener() {} })
for (const k of ['window', 'document', 'navigator', 'MutationObserver', 'HTMLElement', 'HTMLIFrameElement', 'Node', 'Event', 'getComputedStyle']) {
const value = k === 'window' ? win : k === 'getComputedStyle' ? win.getComputedStyle.bind(win) : win[k]
Object.defineProperty(globalThis, k, { value, configurable: true, writable: true })
}
win.scrollTo = () => {}
globalThis.IS_REACT_ACT_ENVIRONMENT = true

const { act, useState } = await import('react')
const { createRoot } = await import('react-dom/client')
const { Modal, FullScreen, Popover, EDIT_SETTLE_MS } = await import('./src/modal.jsx')

const tests = []
const test = (name, fn) => tests.push([name, fn])
const wait = (ms) => act(() => new Promise(r => setTimeout(r, ms)))

/** The picker's shape: a search box, and a row that takes it away when tapped (no focus moves). */
function Picker() {
const [open, setOpen] = useState(true)
return (
<>
{open && <input type="search" aria-label="Search exercises" />}
<button type="button" className="row" onClick={() => setOpen(false)}>Goblet squat</button>
<input type="number" aria-label="Weight" />
</>
)
}

async function mount(el) {
const host = document.createElement('div')
document.body.appendChild(host)
const root = createRoot(host)
await act(async () => root.render(el))
return { host, done: () => act(() => root.unmount()) }
}

const focusOn = (el) => act(() => { el.focus() })
const tapRow = (host) => act(() => { host.querySelector('.row').dispatchEvent(new win.MouseEvent('click', { bubbles: true })) })

test('the session sheet: its footer comes back after the focused search box is removed', async () => {
const { host, done } = await mount(
<Modal title="Back squat" onClose={() => {}} footer={<button type="button">Start workout</button>}><Picker /></Modal>)
assert.ok(host.querySelector('.modal-foot'), 'a sheet at rest has its footer')
await focusOn(host.querySelector('input[type=search]'))
assert.equal(host.querySelector('.modal-foot'), null, 'the footer stays up while a box has focus')
await tapRow(host)
assert.equal(host.querySelector('input[type=search]'), null)
await wait(EDIT_SETTLE_MS + 150)
assert.ok(host.querySelector('.modal-foot'), 'the sheet’s footer stayed hidden after the focused box went (C N1)')
await done()
})

test('the planner: its sticky bar comes back after the focused search box is removed', async () => {
const { host, done } = await mount(
<FullScreen title="Workout" onBack={() => {}}><Picker /><div className="plan-actions sticky"><button type="button">Add to Today</button></div></FullScreen>)
const fs = () => host.querySelector('.fs')
await focusOn(host.querySelector('input[type=search]'))
assert.ok(fs().hasAttribute('data-editing'), 'the bar stays up while a box has focus')
await tapRow(host)
await wait(EDIT_SETTLE_MS + 150)
assert.equal(fs().hasAttribute('data-editing'), false, 'the planner’s keep bar stayed hidden after the focused box went (C N1)')
await done()
})

/** A block's ⋯ (editor.jsx BlockMenu): a popover portalled to the body, its name box focused. */
function WithMenu() {
const [open, setOpen] = useState(true)
return (
<>
{open && <Popover label="Main: block options" onClose={() => setOpen(false)} over><input aria-label="Block name" /></Popover>}
<button type="button" className="row" onClick={() => setOpen(false)}>Close</button>
</>
)
}

test('the planner: a focused box in a popover over it, closed by its X, brings the bar back', async () => {
const { host, done } = await mount(
<FullScreen title="Workout" onBack={() => {}}><WithMenu /><div className="plan-actions sticky" /></FullScreen>)
await focusOn(document.querySelector('input[aria-label="Block name"]'))
assert.ok(host.querySelector('.fs').hasAttribute('data-editing'))
await tapRow(host)
assert.equal(document.querySelector('input[aria-label="Block name"]'), null)
await wait(EDIT_SETTLE_MS + 150)
assert.equal(host.querySelector('.fs').hasAttribute('data-editing'), false, 'a box closed away in a portal left the bar hidden')
await done()
})

test('both layers: a box still focused after the change keeps the footer hidden', async () => {
const { host, done } = await mount(
<Modal title="Back squat" onClose={() => {}} footer={<button type="button">Start workout</button>}><Picker /></Modal>)
await focusOn(host.querySelector('input[type=number]'))
await tapRow(host) // the search box goes; the weight box still has focus
await wait(EDIT_SETTLE_MS + 150)
assert.equal(host.querySelector('.modal-foot'), null, 'the footer came back under a box still being typed in')
await done()
})

let failed = 0
for (const [name, fn] of tests) {
try { await fn(); console.log(` PASS ${name}`) } catch (e) { failed++; console.log(` FAIL ${name}\n ${e.message}`) }
}
console.log(`editing (dom): ${tests.length - failed} passed${failed ? `, ${failed} failed` : ''}`)
await win.happyDOM.close()
process.exit(failed ? 1 : 0)
Loading
Loading