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:
lucioandClaude Opus 5 committed 2026-07-25 09:23:19 -07:00
commit 5a61890011
31 files changed
+3576

No files matched your search

+165
View File
@@ -0,0 +1,165 @@
"""Read-only action allowlist, and the guard that enforces it.
The session credential this client uses is a full login -- Wodify issues no
read-only token -- so nothing at the credential layer prevents a write. This
module *is* the enforcement. Two independent layers, both required:
1. ``ACTIONS`` -- an explicit allowlist. Anything unregistered cannot be called.
2. ``assert_read_only`` -- refuses any path containing a write marker, applied
even to allowlisted entries, so a careless registry edit still fails closed.
Keep both. See tests/test_actions.py.
"""
from __future__ import annotations
import dataclasses
#: Substrings that mark a mutating OutSystems action. Matched case-insensitively
#: against the action path. Deliberately blunt: a false positive is a developer
#: annoyance, a false negative charges the user money or takes someone's spot.
WRITE_MARKERS: tuple[str, ...] = (
"create", "update", "delete", "save", "insert", "remove",
"reserve", "cancel", "signin", "checkin", "check_in", "enroll", "book",
"waitlistjoin", "leavewaitlist", "like", "comment", "accept", "submit",
"purchase", "pay", "charge", "logout", "setresult", "addresult",
)
class WriteAttemptError(RuntimeError):
"""Raised when something tries to call a mutating endpoint."""
class UnknownActionError(KeyError):
"""Raised when an action key is not in the allowlist."""
@dataclasses.dataclass(frozen=True)
class Action:
"""A single read-only data action.
``path`` is everything after ``/screenservices/``.
``view_name`` is the OutSystems screen the real client reports.
``inputs`` documents the inputParameters keys; an empty tuple means the
action takes none. Actual values are supplied per call.
"""
key: str
path: str
view_name: str
summary: str
inputs: tuple[str, ...] = ()
_FETCH = "WodifyClient_DataFetch_WB"
ACTIONS: dict[str, Action] = {
a.key: a
for a in (
Action(
key="bookings",
path=f"{_FETCH}/Schedule_OS/GetClientAttendancesDataFetch_WB/DataActionGetAttendances",
view_name="MainScreens.Home",
summary="Classes the user has reserved or attended",
inputs=("Request",),
),
# The actual workout content. Fires only on the properly-reached workout
# screen (class detail -> Go to workout), which is why a cold load of
# /WodifyClient/Exercise never reveals it.
Action(
key="workout",
path=f"{_FETCH}/WOD_Flow/GetAllWorkoutData_WB/DataActionGetAllWorkoutData",
view_name="MainScreens.Exercise",
summary="Workout / WOD content for a date and program",
inputs=("In_Request",),
),
# NOTE: despite the name, this returns only {"Response": bool} -- a probe
# for whether the WOD has leaderboard components. It is NOT the workout
# content; `workout` above is. Keeping it registered because the name is
# a trap: something will eventually reach for it expecting content.
Action(
key="wodflags",
path=f"{_FETCH}/WOD_Flow/GetWorkoutData_HasWodLeaderboardComponents"
f"/DataActionGetWorkoutDataHasWodLeaderboardComponents",
view_name="MainScreens.Home",
summary="Boolean probe: does this WOD have leaderboard components "
"(NOT the workout text)",
inputs=("Request",),
),
Action(
key="attendees",
path=f"{_FETCH}/Schedule_OS/GetClassAttendees_WB/DataActionGetClassAttendees",
view_name="Classes.Class",
summary="Who is signed up for a class",
inputs=("Request",),
),
Action(
key="classdetail",
path=f"{_FETCH}/Schedule_OS/GetClass_WB/DataActionGetClass",
view_name="Classes.Class",
summary="Single class: time, program, description",
inputs=("Request",),
),
Action(
key="coach",
path=f"{_FETCH}/Schedule_OS/GetEmployeesForClass_WB/DataActionGetEmployeesForClass",
view_name="Classes.Class",
summary="Coach assigned to a class",
inputs=("Request",),
),
# The schedule screen's class list, with reservation counts. This is the
# one that actually populates; `classes` below (the Home variant) returns
# placeholder records only.
Action(
key="schedule",
path=f"{_FETCH}/Schedule_OS/GetClassList_ForClient_WithReservationCounts_WB"
f"/DataActionGetClassList_ForClient_WithReservationCounts",
view_name="MainScreens.Scheduler",
summary="All classes on a given day, with reservation counts",
inputs=("In_Request",),
),
Action(
key="classes",
path="WodifyClient_Class/Classes/Attendance/DataActionGetClasses",
view_name="Classes.Attendance",
summary="Classes via the Home screen variant (returns placeholders; "
"prefer 'schedule')",
inputs=("Request",),
),
Action(
key="waitlist",
path=f"{_FETCH}/Schedule_OS/GetClassWaitList_WB/DataActionGetClassWaitList",
view_name="Classes.Class",
summary="Waitlist for a class (read only -- never join or leave)",
inputs=("Request",),
),
)
}
def assert_read_only(path: str) -> None:
"""Raise :class:`WriteAttemptError` if ``path`` looks mutating.
Applied to every request, including allowlisted ones.
"""
lowered = path.lower()
for marker in WRITE_MARKERS:
if marker in lowered:
raise WriteAttemptError(
f"refusing to call {path!r}: contains write marker {marker!r}. "
"This client is read-only by design."
)
def get(key: str) -> Action:
"""Look up an allowlisted action, verifying it is still read-only."""
try:
action = ACTIONS[key]
except KeyError as exc:
known = ", ".join(sorted(ACTIONS))
raise UnknownActionError(f"unknown action {key!r}; known: {known}") from exc
assert_read_only(action.path)
return action
def keys() -> list[str]:
return sorted(ACTIONS)