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
12 changes: 8 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ reasons behind the design, and the things that have been removed on purpose.
| Profile | `app/src/lib/profile.js`, `app/src/profile.jsx` | A `Popover`, not a `FullScreen`. Opens on a list of sections (`homePages`), each a page with a back button; Testing and Why (`testing.jsx`) are under Climbing. |
| Number inputs | `app/src/numinput.jsx`, `app/src/lib/numtext.js` | Text inputs that own their text (§6.4). |
| Body diagram | `app/src/lib/bodymap.jsx`, `app/muscles.build.mjs` | `react-body-highlighter` + `free-exercise-db`; nothing hand-drawn. |
| How-to figures | `app/src/howto.jsx`, `app/src/lib/figures.jsx` | Registry of SVG figures named by content. |
| How-to figures | `app/src/howto.jsx`, `app/src/lib/figuredata.js`, `app/src/lib/figures.jsx` | The drawings are data in `figuredata.js` (one skeleton, `body()`; copied byte for byte to mobile), and `figures.jsx` / `figures.tsx` only render them. Tested by `app/figures.test.jsx` (#109). |
| Palette | `app/src/styles.css` `:root`, `app/validate_palette.js` | `npm run palette`; a real gate (§6.10). The rest of the token contract is pinned by `app/smoke/system.jsx` (§10.13). |
| Styles | `app/src/styles.css` (tokens, base components, shell), `app/src/css/<area>.css` (each screen area's rules, one owner each), `app/src/timer.css` | A new rule goes in its area's file (`sheet.css`, `today.css`, `planner.css`, `editor.css`, `runner.css`, `workout.css`, …); `main.jsx` imports them in cascade order. See `docs/DESIGN.md`, "Visual system". |
| Notifications client | `app/src/lib/push.js`, `app/src/notifications.jsx` | |
Expand Down Expand Up @@ -493,9 +493,13 @@ no rebuild. An older plan file may also carry `recommender`, `checkin`, `journal
- **Every exercise has a `how`**: a `figure`, a one-line `gist`, three to five short
`steps`, the one `watch` error, optional `easier`. The length limits in
`workout.test.js` are the feature: long protocol prose demonstrably did not get read
mid-session. Figures are hand-written SVG in `lib/figures.jsx` because accurate,
licensable photos of these drills mostly do not exist and the app must work offline;
the smoke suite checks every named figure exists and every figure is used.
mid-session. Figures are hand-drawn SVG, kept as data in `lib/figuredata.js`, because
accurate, licensable photos of these drills mostly do not exist and the app must work
offline; the smoke suite checks every named figure exists and every figure is used.
Every person is built by `body()` from the one skeleton (`BONES`), hands and feet are
placed by IK so they touch what they hold or stand on, and each figure has ONE cue in
the accent on what its `watch` is about (#109, the vocabulary is at the top of the
file). `app/figures.test.jsx` holds limb lengths, contacts, cues and the native copy.
- **Every claim is graded and sourced.** `evidence.grade` is one of `rct`,
`controlled-trial`, `observational`, `mechanistic`, `expert-consensus`, `folklore`;
`transfer` states what is assumed versus demonstrated. Verify citations against the
Expand Down
137 changes: 137 additions & 0 deletions app/figures.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/* The how-to figures (#109):
* npm --prefix app run test:figures
*
* The drawings are data (src/lib/figuredata.js) that both apps render, so this
* holds the things a picture test cannot see by looking:
* - the phone draws exactly the web's shapes: the same data file, and two
* renderers that hold no drawing of their own;
* - ONE body: every limb in every figure has the skeleton's lengths, and a
* hand or foot sent to a hold, an edge or the floor actually gets there
* (the old scap-pull's arms shrank 31 → 18 between poses and read as a
* pull-up; climbers floated 20 units off their walls);
* - every figure has its one cue, every movement figure moves, and the
* sibling figures a session shows side by side do not share a silhouette;
* - the web renders every shape the data has.
* The smoke suite (smoke/sheet.jsx) still checks every figure the plan names
* exists and every figure is used.
*/

import { readFileSync } from 'node:fs'
import { renderToStaticMarkup } from 'react-dom/server'
import { FIGURES, KINDS, BONES, LIMBS, dist } from './src/lib/figuredata.js'
import { Figure } from './src/lib/figures.jsx'

let failed = 0
const check = (name, fn) => {
try { fn(); console.log(` PASS ${name}`) }
catch (err) { failed++; console.error(` FAIL ${name}\n ${err.message}`) }
}
const ok = (cond, msg) => { if (!cond) throw new Error(msg) }
const read = (p) => readFileSync(new URL(p, import.meta.url), 'utf8')
const layers = (f) => ['props', 's', 'a', 'b', 'over', 'detail'].flatMap(l => f[l] || [])
const names = Object.keys(FIGURES)

check('the phone copies the web figure data byte for byte', () => {
ok(read('./src/lib/figuredata.js') === read('../mobile/src/lib/figuredata.js'),
'mobile/src/lib/figuredata.js differs from app/src/lib/figuredata.js: copy it again')
})

check('neither renderer draws anything of its own', () => {
for (const file of ['./src/lib/figures.jsx', '../mobile/src/lib/figures.tsx']) {
const src = read(file)
ok(/from '\.\/figuredata\.js'/.test(src), `${file} does not render from figuredata.js`)
ok(!/\bd="[^"]/.test(src) && !/\bd=\{`/.test(src) && !/\bd: ['"`]/.test(src), `${file} has path data in it`)
ok(!/c[xy]=\{?\d/.test(src), `${file} has a coordinate in it`)
}
})

check('every shape is a known kind with a path or a circle', () => {
for (const n of names) {
for (const s of layers(FIGURES[n])) {
ok(KINDS[s.k], `${n}: unknown kind ${s.k}`)
ok(typeof s.d === 'string' ? !s.d.includes('NaN') : Array.isArray(s.c) && s.c.every(Number.isFinite),
`${n}: a ${s.k} with no geometry`)
}
}
})

check('one skeleton: every limb has the bones’ lengths', () => {
ok(LIMBS.length > 60, `only ${LIMBS.length} limbs were built`)
for (const l of LIMBS) {
const [a, b] = [dist(l.root, l.mid), dist(l.mid, l.end)]
ok(Math.abs(a - l.lengths[0]) < 0.05 && Math.abs(b - l.lengths[1]) < 0.05,
`a limb from ${l.root.map(Math.round)} is ${a.toFixed(1)} + ${b.toFixed(1)}, not ${l.lengths.join(' + ')}`)
const pair = l.lengths.join()
ok([`${BONES.upperArm},${BONES.forearm}`, `${BONES.thigh},${BONES.shin}`].includes(pair), `a limb of ${pair} is not an arm or a leg`)
}
})

check('contacts touch: every hand and foot sent somewhere gets there', () => {
for (const l of LIMBS.filter(l => l.target)) {
const miss = dist(l.end, l.target)
ok(miss < 0.3, `a limb from ${l.root.map(Math.round)} stops ${miss.toFixed(1)} short of ${l.target.map(Math.round)}`)
}
})

check('every figure has a cue, and the alt text says what it shows', () => {
for (const n of names) {
const f = FIGURES[n]
ok(layers(f).some(s => KINDS[s.k].cue), `${n} has no cue`)
ok(typeof f.alt === 'string' && f.alt.length > 20, `${n} has no alt text`)
ok(f.a?.length, `${n} has no pose`)
}
})

check('every movement figure moves, and a hold has nothing to crossfade', () => {
for (const n of names) {
const f = FIGURES[n]
if (f.b) ok(JSON.stringify(f.a) !== JSON.stringify(f.b), `${n}: pose B is pose A`)
}
})

check('siblings shown side by side do not share a silhouette', () => {
const same = (x, y) => JSON.stringify(FIGURES[x].a) === JSON.stringify(FIGURES[y].a)
for (const [x, y] of [
['forearm-supination', 'forearm-pronation'], ['grip-four', 'grip-front-three'], ['grip-four', 'grip-two'],
['grip-front-three', 'grip-two'], ['climb-board', 'boulder'], ['climb-route', 'crag'], ['climb-route', 'climb-double'],
['hang-edge', 'hang-assisted'], ['plank-reach', 'side-bridge'],
]) ok(!same(x, y), `${x} and ${y} start on the same picture`)
// The two eccentric figures turn opposite ways.
const arc = (n) => FIGURES[n].s.find(s => s.dash).d
ok(arc('forearm-supination') !== arc('forearm-pronation'), 'supination and pronation arrows are the same')
})

check('scap-pull: the arms are the same lines in both poses (they never bend)', () => {
const f = FIGURES['scap-pull']
const arms = f.s.filter(s => s.k === 'cueBody')
ok(arms.length === 2, 'the arms are not the fixed cue')
ok(!f.a.some(s => s.k === 'cueBody') && !f.b.some(s => s.k === 'cueBody'), 'an arm moves between poses')
})

check('the web renders every shape the data has; thumbnails leave the inset out', () => {
for (const n of names) {
const f = FIGURES[n]
const html = renderToStaticMarkup(<Figure name={n} />)
const want = layers(f).filter(s => s.d).length + layers(f).filter(s => s.c).length
const got = (html.match(/<path /g) || []).length + (html.match(/<circle /g) || []).length
ok(got === want, `${n}: ${got} elements for ${want} shapes`)
for (const s of layers(f).filter(s => s.d)) ok(html.includes(`d="${s.d}"`), `${n}: a path is missing`)
if (f.detail) {
ok(html.includes('fig-detail'), `${n}: the card has no inset`)
ok(!renderToStaticMarkup(<Figure name={n} detail={false} />).includes('fig-detail'), `${n}: the thumbnail draws the inset`)
}
ok(!html.includes('NaN'), `${n}: NaN in the markup`)
}
})

check('the cue is drawn in --fig-cue, never a fixed colour', () => {
const html = renderToStaticMarkup(<Figure name="hang-edge" />)
ok(html.includes('class="fig-cue"'), 'no cue element carries .fig-cue')
ok(!/#[0-9a-f]{3,6}/i.test(html), 'a figure carries a literal colour')
const css = read('./src/css/sheet.css')
ok(/\.fig \{[^}]*color: inherit/.test(css), '.fig does not inherit its container colour')
ok(/\.fig-cue \{[^}]*var\(--fig-cue/.test(css), '.fig-cue is not --fig-cue')
})

if (failed) { console.error(`\n${failed} failed`); process.exit(1) }
console.log('\nfigures: all passed')
1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"test:gear": "node gear.test.js",
"test:progress": "node progress.test.js",
"palette": "node validate_palette.js",
"test:figures": "esbuild figures.test.jsx --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.figurestest.mjs --log-level=error && node .figurestest.mjs",
"test:md": "esbuild markdown.test.jsx --bundle --platform=node --format=esm --jsx=automatic --packages=external --outfile=.mdtest.mjs --log-level=error && node .mdtest.mjs",
"test:streak": "node streak.test.js",
"test:presc": "node prescription.test.js",
Expand Down
16 changes: 16 additions & 0 deletions app/smoke/sheet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,22 @@ export default [
...Object.keys(FIGURES).map(name => [`Figure(${name})`,
<HowRow exercise={{ name, how: { figure: name, gist: 'x' } }} open onToggle={noop} />,
html => { if (!html.includes('<svg')) throw new Error('drew nothing') }]),
/* #109: the session sheet showed the figure only as the 50×42 thumbnail,
* because an open row's card left its own figure out. An open row now shows
* the card's figure, large; a closed row does not; the thumbnail never draws
* the finger inset (noise at that size), the card does. Pinned from both
* sides, so the move is not a deletion. */
['HowRow(open shows the figure large, closed does not)', null, () => {
const ex = { name: 'Max hangs', how: { figure: 'hang-edge', gist: 'x', steps: ['a'] } }
const open = renderToString(<HowRow exercise={ex} open onToggle={noop} />)
const shut = renderToString(<HowRow exercise={ex} open={false} onToggle={noop} />)
if (!/class="how-fig"/.test(open)) throw new Error('an open row has no large figure')
if (/class="how-fig"/.test(shut)) throw new Error('a closed row draws the large figure')
const thumb = /<span class="how-thumb">([\s\S]*?)<\/span>/.exec(open)?.[1] || ''
if (!thumb.includes('<svg')) throw new Error('the row lost its thumbnail')
if (thumb.includes('fig-detail')) throw new Error('the thumbnail draws the finger inset')
if (!/class="how-fig"[\s\S]*fig-detail/.test(open)) throw new Error('the card lost its finger inset')
}],
// The moves list on every session that has one, and the mid-set sheet.
...plan.dailyMenu.filter(m => m.logSpec?.exercises?.length)
.map(m => [`Moves(${m.id})`, <MovesList session={m} />]),
Expand Down
10 changes: 8 additions & 2 deletions app/src/css/sheet.css
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@
the drawing goes first, the sentence goes second, and the paragraphs stay one
tap away instead of first in the queue. */

.fig { display: block; width: 100%; height: 100%; color: var(--ink-dim); }
/* The figure takes its ink from where it sits (the card --ink, a row --ink-dim,
an open row or workout mode --accent), as the phone passes it explicitly. It
used to set --ink-dim on itself, which beat every container's colour. The one
cue per figure (figuredata.js) is --fig-cue: the accent, or the ink where the
body itself is drawn in the accent. */
.fig { display: block; width: 100%; height: 100%; color: inherit; }
.fig-cue { color: var(--fig-cue, var(--accent)); }

/* Two poses crossfading. Neither ever goes fully transparent — a figure that
blinks out reads as a glitch, where one that fades to a ghost reads as "and
Expand Down Expand Up @@ -205,7 +211,7 @@
flex: 0 0 auto; width: 50px; height: 42px;
display: grid; place-items: center; color: var(--ink-dim);
}
.how-row.on .how-thumb { color: var(--accent); }
.how-row.on .how-thumb { color: var(--accent); --fig-cue: var(--ink); }
.how-heads { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.how-name { font-size: var(--fs-body); font-weight: 600; }
.how-sub {
Expand Down
2 changes: 1 addition & 1 deletion app/src/css/workout.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ button.btn.quiet.wo-sound { align-self: center; }
background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-control);
color: inherit; font: inherit;
}
.wo-howfig { flex: 0 0 auto; width: 44px; height: 38px; color: var(--accent); }
.wo-howfig { flex: 0 0 auto; width: 44px; height: 38px; color: var(--accent); --fig-cue: var(--ink); }
.wo-howgist { flex: 1; min-width: 0; font-size: var(--fs-label); line-height: 1.4; color: var(--ink-dim); }
.wo-howmore {
flex: 0 0 auto; font-size: var(--fs-label); font-weight: 600; color: var(--ink);
Expand Down
4 changes: 2 additions & 2 deletions app/src/howto.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ export function HowRow({ exercise, open, onToggle, meta }) {
return (
<div className={`how-row ${open ? 'on' : ''}`}>
<button className="how-head" onClick={onToggle} aria-expanded={open}>
<span className="how-thumb"><Figure name={how?.figure} /></span>
<span className="how-thumb"><Figure name={how?.figure} detail={false} /></span>
<span className="how-heads">
<span className="how-name">{exercise.name}</span>
{how?.gist && <span className="how-sub">{how.gist}</span>}
</span>
{dose && <span className="how-dose">{dose}</span>}
<span className="how-chev"><Icon name="ChevronDown" size={17} /></span>
</button>
{open && how && <HowBody how={how} showFigure={false} />}
{open && how && <HowBody how={how} />}
{open && !how && (
<p className="how-none">
No step-by-step for this one yet — the full protocol is in the sections above.
Expand Down
Loading
Loading