feat: read-only Wodify athlete client
A CLI that answers "what classes ran", "who was there" and "what was the workout" with a single HTTP POST each -- no browser at query time. Wodify's athlete app is an OutSystems Reactive SPA. Driving it with a headless browser works but is slow and, for an LLM agent, expensive: a full page render to read a few lines back out of the DOM. Its data actions are plain JSON endpoints, so this talks to them directly. wodify list date 2026-07-25 time, coach, booked/max, title, duration, ID wodify list workout <id> attendee names + that class's workout Two phases. `prime` attaches over CDP to a browser that is already logged in and captures the session cookies, the CSRF token, and each action's apiVersion and body shape. Everything after that is stdlib HTTP -- the query path has no third-party dependencies at all. Three things genuinely require the browser, which is why priming exists: - the session bearer nr1W_Theme_UI is HttpOnly, so it cannot be exported by hand - X-CSRFToken is not in cookies, localStorage, or any JS global - apiVersion is per-action, not global Read-only is enforced in code, not by the credential (Wodify issues no read-only token): an explicit allowlist plus a write-marker guard applied even to allowlisted paths, so a careless registry edit fails closed. Tests assert that real mutating endpoint names are refused. Responses are cached in SQLite, keyed by the local date they were fetched on, so a repeat query the same day touches no network. All fetching funnels through service.py so a call site cannot forget the cache. Staleness is explicit rather than silent: responses carry hasModuleVersionChanged/hasApiVersionChanged, and the client raises VersionStale/SessionExpired instead of returning a plausible empty result. That matters because every bug found while building this produced confident wrong output rather than an error -- see CLAUDE.md for the field-name traps. History squashed before first publication: earlier commits embedded real gym members' names in test fixtures. Fixtures now use fictional names. 122 tests, no network required. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
commit
5a61890011
31 files changed
+3576
No files matched your search
@@ -0,0 +1,104 @@
|
||||
"""Component field coverage.
|
||||
|
||||
Reading only Name/Comment silently dropped the actual movements -- the metcon
|
||||
lives in Description and the strength scheme in MeasureRepScheme. These tests
|
||||
exist so that regression cannot recur quietly.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from wodify import render
|
||||
|
||||
STRENGTH = {
|
||||
"Id": "123372266",
|
||||
"IsWeightlifting": True,
|
||||
"Name": "Shoulder Press",
|
||||
"Comment": "<p>--</p><p>Strict overhead pressing progression.</p>",
|
||||
"MeasureRepScheme": "Strict Press\nEvery 2:30 x 4 Sets\nSet 1: 10 Reps",
|
||||
"WODComponentVariableRepScheme": "(1 x 10) (1 x 8) (1 x 6) (1 x 4)",
|
||||
"WODComponentOrder": 2,
|
||||
}
|
||||
|
||||
METCON = {
|
||||
"Id": "123372267",
|
||||
"IsMetcon": True,
|
||||
"Name": '"Hat Trick"',
|
||||
"Comment": "<p>Goals: ~2:00 per set</p><p>RPE: 9/10</p>",
|
||||
"Description": "<p>For Time</p><p>Every 5:00 x 3 Sets</p><p>21 Wall Balls</p>",
|
||||
"Rounds": 3,
|
||||
"EachRoundTypeLabel": "For Time ↓ Shorter is Better",
|
||||
"WODComponentOrder": 3,
|
||||
}
|
||||
|
||||
SECTION = {"Id": "1", "IsSection": True, "Name": "WARM-UP",
|
||||
"Comment": "<p>2:00 Cardio Choice</p>", "WODComponentOrder": 1}
|
||||
|
||||
|
||||
def _wod(components):
|
||||
return {"Response": {"ResponseWOD": {"ResponseWorkout": {
|
||||
"Id": "25201299", "Name": "CrossFit - Mon, Jul 20", "Notes": "",
|
||||
"WorkoutComponents": {"List": components},
|
||||
}}}}
|
||||
|
||||
|
||||
def test_metcon_description_is_rendered():
|
||||
"""Description carries the movements. Without it the output looks complete
|
||||
but contains no workout."""
|
||||
out = render.workout(_wod([METCON]))
|
||||
assert "21 Wall Balls" in out
|
||||
assert "Every 5:00 x 3 Sets" in out
|
||||
|
||||
|
||||
def test_strength_rep_scheme_is_rendered():
|
||||
out = render.workout(_wod([STRENGTH]))
|
||||
assert "Every 2:30 x 4 Sets" in out
|
||||
assert "Set 1: 10 Reps" in out
|
||||
|
||||
|
||||
def test_variable_rep_scheme_included_when_distinct():
|
||||
assert "(1 x 10) (1 x 8)" in render.workout(_wod([STRENGTH]))
|
||||
|
||||
|
||||
def test_variable_rep_scheme_not_duplicated():
|
||||
comp = dict(STRENGTH, WODComponentVariableRepScheme="Every 2:30 x 4 Sets")
|
||||
out = render.workout(_wod([comp]))
|
||||
assert out.count("Every 2:30 x 4 Sets") == 1
|
||||
|
||||
|
||||
def test_rounds_and_scoring_are_surfaced():
|
||||
out = render.workout(_wod([METCON]))
|
||||
assert "3 rounds" in out
|
||||
assert "Shorter is Better" in out
|
||||
|
||||
|
||||
def test_dash_only_comment_is_dropped():
|
||||
"""Authors use '--' as a spacer; it should not appear as content."""
|
||||
comp = {"Id": "9", "Name": "Press", "Comment": "<p>--</p>", "WODComponentOrder": 1}
|
||||
out = render.workout(_wod([comp]))
|
||||
assert "--" not in out
|
||||
|
||||
|
||||
def test_real_comment_is_kept():
|
||||
assert "RPE: 9/10" in render.workout(_wod([METCON]))
|
||||
|
||||
|
||||
def test_dash_spacer_stripped_but_surrounding_comment_kept():
|
||||
"""Live data has '--' as a leading spacer before real prose."""
|
||||
out = render.workout(_wod([STRENGTH]))
|
||||
assert "Strict overhead pressing progression." in out
|
||||
assert "--" not in out
|
||||
|
||||
|
||||
def test_components_sorted_by_wod_component_order():
|
||||
out = render.workout(_wod([METCON, SECTION, STRENGTH]))
|
||||
assert out.index("WARM-UP") < out.index("Shoulder Press") < out.index("Hat Trick")
|
||||
|
||||
|
||||
def test_section_and_component_heading_levels_differ():
|
||||
out = render.workout(_wod([SECTION, METCON]))
|
||||
assert "## WARM-UP" in out
|
||||
assert '### "Hat Trick"' in out
|
||||
|
||||
|
||||
def test_missing_order_does_not_crash():
|
||||
comp = {k: v for k, v in METCON.items() if k != "WODComponentOrder"}
|
||||
assert "21 Wall Balls" in render.workout(_wod([comp]))
|
||||
Reference in new issue
Block a user