Skip to content

Encode coach ids, keep the API key on the base URL, read HTTP-date Retry-After; tests for 14 untested methods - #33

Merged
DrAlexHarrison merged 2 commits into
mainfrom
muse/sdk-py-fixes
Nov 22, 2026
Merged

DrAlexHarrison merged 2 commits into
mainfrom
muse/sdk-py-fixes

Conversation

@DrAlexHarrison

Copy link
Copy Markdown
Member

Security and robustness fixes, plus request tests for 14 partner methods that had no test. Muse (Meta Muse Code, Meta training off) wrote it in a code lane. A Claude read the whole diff, changed one check (below), and reran the suite: uv run --with pytest --with pytest-asyncio --with httpx pytest -q gives 277 passed, 2 skipped. No version bump, changelog or workflow change; the release is your call. No landing label.

Fixed, each with a test

  • Coach ids (athlete uid, activity id, webhook id) go through _seg. Before, coach.fueling_rollup("../../partner") called /v1/partner/fueling-rollup with the coach key.
  • _seg refuses . and ...
  • request() refuses an absolute or scheme-relative URL. Before, request("GET", "https://other.host/x") sent the API key to that host.
  • request() upper-cases the method once at entry.
  • Retry-After as an HTTP date is read (wait = date minus now, never below 0). An empty or unreadable header counts as absent. Before, an HTTP date on a 429 read as a daily ceiling.
  • An error body that is not an object, or whose error is not an object, gives the normal error class with HTTP <status> and code unknown (before: AttributeError).
  • The message taken from a non-JSON error body is cut to 200 characters (before: a whole HTML error page).
  • The constructor checks options: timeout must be a finite number above 0, max_retries an integer of 0 or more, and the credential sent must be non-empty with no control characters. Muse's version refused api_key="" even with bearer_token, which an OAuth-only client passes; the Claude review allowed that case and added a test.
  • Computed backoff stops growing at the 30-second cap that Retry-After already had.

Tests added: request method, path and body for nutrition.extract, both infer calls, integrations.disconnect, organizations.update_subscription, the three license calls, knowledge.list_topics and get_article, activities.get, organizations.get, update and get_offer, and 14 coach routes.

Behavior a partner could notice: bad constructor options and dot-only ids now raise ValueError at once instead of failing later.

Design questions, left untouched for you

  • A webhook signature helper in the SDK (none today; every partner writes their own HMAC check).
  • Requiring https base URLs (http:// is accepted silently today).
  • Raising SaturdayError for an unreadable success body (today a bare JSONDecodeError).
  • Retrying a 429 on POST creates (safe only if the server never writes before a 429).
  • Redirect handling, keeping the key off the client object, and per-call timeouts.
  • Jitter on retries.
  • Release process: unpinned hatchling and httpx with no upper bound, and actions pinned by tag.

🤖 Generated with Claude Code

DrAlexHarrison and others added 2 commits November 22, 2026 11:14
- Encode coach athlete/activity/webhook ids; reject . and .. segments
- Normalize method, refuse absolute URLs, cap backoff and error text
- Parse Retry-After HTTP-dates; handle null/non-object error bodies
- Validate api_key, timeout and max_retries in constructor
- Add coach route tests and 14 partner method request tests
…sses bearer_token

The new validation refused api_key="" even with a bearer token, which is how an OAuth-only partner
constructs the client. Control characters are refused in whichever credential is sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DrAlexHarrison

Copy link
Copy Markdown
Member Author

Review verdict: MERGE

Read the whole diff against main and the confirmed coach-id finding:

  • Coach ids: fueling_rollup, report, report_pdf, session_detail and the three coach webhook writes now go through _seg; no f"/v1/..." path in saturday/client.py interpolates an id without it. On main's saturday/ test_coach_ids_are_segment_encoded fails (the path became /v1/partner/fueling-rollup); here it passes.
  • Method case: Python's retry guard already upper-cased, so this was not a live bug here; request() now upper-cases once at entry, which keeps transport and guard on one value.
  • The rest (dot segments, absolute URLs refused before the API key is sent, Retry-After dates, non-object error bodies, the 200-character cap, constructor checks, the 30 s backoff cap) is as described.

Runs: pytest -q: 277 passed, 2 skipped. Live suite against fuel-app-test: 2 passed in 104.67s. Merged together with #32 and #34: 280 passed, 2 skipped, no conflicts.

Minor, no hold: the constructor now raises ValueError for an empty api_key (unless bearer_token is set) where it used to fail at the first request: the 0.9.0 CHANGELOG lists it as a breaking change.

@DrAlexHarrison
DrAlexHarrison merged commit 81a0c83 into main Nov 22, 2026
1 check failed
@DrAlexHarrison
DrAlexHarrison deleted the muse/sdk-py-fixes branch November 22, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant