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]>
79 lines
3.0 KiB
Python
79 lines
3.0 KiB
Python
"""The read-only guard is the only thing preventing this client from spending
|
|
the user's money or taking someone's class spot. Test it hard."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from wodify import actions
|
|
|
|
|
|
def test_every_registered_action_is_read_only():
|
|
for key, action in actions.ACTIONS.items():
|
|
actions.assert_read_only(action.path) # must not raise
|
|
assert action.key == key, "registry key must match Action.key"
|
|
assert action.path, f"{key} has no path"
|
|
assert not action.path.startswith("/"), f"{key} path should be relative"
|
|
|
|
|
|
def test_get_returns_action():
|
|
assert actions.get("bookings").key == "bookings"
|
|
|
|
|
|
def test_unknown_action_rejected():
|
|
with pytest.raises(actions.UnknownActionError):
|
|
actions.get("definitely-not-a-real-action")
|
|
|
|
|
|
# Real mutating endpoint names observed in Wodify's client, plus plausible
|
|
# variants. None may ever pass the guard.
|
|
@pytest.mark.parametrize("path", [
|
|
"WodifyClient_Class/Classes/Class/ServiceAPICreateClassReservation",
|
|
"WodifyClient_Class/Classes/Class/ActionCancelReservation",
|
|
"WodifyClient_DataFetch_WB/WOD_Flow/SaveWorkoutResult",
|
|
"WodifyClient/Common/ActionAcceptTermsAndConditions",
|
|
"WodifyClient_Class/Classes/Class/ClientActionSignInToClass",
|
|
"WodifyClient/MainScreens/ActionSubmitAppReview",
|
|
"WodifyClient_Class/Classes/ActionLeaveWaitlist",
|
|
"WodifyClient/Account/ActionLogout",
|
|
"WodifyClient/POS/ActionPurchaseItem",
|
|
"WodifyClient/WOD/ActionAddResult",
|
|
])
|
|
def test_write_endpoints_are_refused(path):
|
|
with pytest.raises(actions.WriteAttemptError):
|
|
actions.assert_read_only(path)
|
|
|
|
|
|
def test_guard_is_case_insensitive():
|
|
with pytest.raises(actions.WriteAttemptError):
|
|
actions.assert_read_only("Module/Screen/ACTIONCREATERESERVATION")
|
|
|
|
|
|
def test_guard_does_not_block_legitimate_read_paths():
|
|
"""Guard markers must not false-positive on the reads we actually need.
|
|
|
|
'GetClassWaitList' in particular has to stay callable -- reading a waitlist
|
|
is fine, joining or leaving it is not.
|
|
"""
|
|
safe = [
|
|
"WodifyClient_DataFetch_WB/Schedule_OS/GetClassWaitList_WB/DataActionGetClassWaitList",
|
|
"WodifyClient_DataFetch_WB/Schedule_OS/GetClassAttendees_WB/DataActionGetClassAttendees",
|
|
"WodifyClient_DataFetch_WB/WOD_Flow/GetWorkoutData_HasWodLeaderboardComponents"
|
|
"/DataActionGetWorkoutDataHasWodLeaderboardComponents",
|
|
"WodifyClient_Class/Classes/Attendance/DataActionGetClasses",
|
|
]
|
|
for path in safe:
|
|
actions.assert_read_only(path)
|
|
|
|
|
|
def test_all_expected_actions_registered():
|
|
expected = {"bookings", "wodflags", "attendees", "classdetail",
|
|
"coach", "classes", "waitlist"}
|
|
assert expected <= set(actions.keys())
|
|
|
|
|
|
def test_get_returns_action_for_workout_probe():
|
|
"""wodflags is deliberately not called 'workout': it returns a boolean, and
|
|
naming it 'workout' invited reporting 'no workout' from a probe response."""
|
|
action = actions.get("wodflags")
|
|
assert "NOT the workout text" in action.summary
|