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
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
pull_request:

permissions:
contents: read

concurrency:
group: test-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7

- uses: actions/setup-python@v7
with:
python-version: '3.12'
cache: pip
cache-dependency-path: pyproject.toml

- run: python -m pip install -e '.[test]'
- run: python -m pytest
- run: python -m mypy saturday tests/typecheck --check-untyped-defs --warn-unused-ignores
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ python -m pip install -e '.[test]'
python -m pytest
```

Every pull request runs the tests and the mypy check in `tests/fixtures/README.md` (`.github/workflows/test.yml`).

Update `saturday/` against the current [API documentation](https://docs.saturday.fit/introduction) and add coverage in `tests/` for behavior changes. `python -m pytest` uses mocked responses and recorded API responses and needs no API key. The live suite runs every method against a real API with a test key: see [tests/LIVE.md](tests/LIVE.md). After a change to the API, run it with `SATURDAY_LIVE_CAPTURE=tests/fixtures/live.json` and commit the new recording with the type changes.

## Code of conduct
Expand Down
3 changes: 2 additions & 1 deletion saturday/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class RateLimitError(SaturdayError):
"""

def __init__(self, *args: Any, retry_after: Optional[float] = None, now: Optional[datetime] = None, **kwargs: Any):
super().__init__(*args, retry_after=retry_after, **kwargs)
kwargs["retry_after"] = retry_after
super().__init__(*args, **kwargs)
# An API that predates the daily codes marks a daily ceiling by sending no Retry-After.
self.daily_limit = self.code in DAILY_LIMIT_CODES or retry_after is None
self.resets_at: Optional[datetime] = None
Expand Down
13 changes: 3 additions & 10 deletions tests/fixtures/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
# Contract fixtures

`contracts.json` is generated from fuel-backend's Go JSON types and its real stored-prescription, list and settings handlers, using synthetic data and in-memory services. It makes no API, Firestore, inference, auth, or trial calls. The backend commit is recorded in `_meta`.
`contracts.json` holds sample API responses that fuel-backend builds (`pkg/sdkcontracts`) from its Go response types and its real stored-prescription, list and settings handlers, with synthetic data and in-memory services. It makes no API, Firestore, inference, auth, or trial calls. `_meta.backend_sha` is the backend commit that last changed the samples.

Regenerate from a checked-out backend module, with Go 1.26+:
The backend fails a test when its copy of the samples no longer matches what its types and handlers produce. Once the regenerated samples are on the backend's main, `scripts/sdk-contracts-sync.sh --pr` in fuel-backend opens a pull request here carrying them, and the test run on that pull request shows whether the SDK types still match. Fix the types on that branch when it fails.

```bash
cd /path/to/fuel-backend
go run /path/to/saturday-python/tests/fixtures/generate.go \
-backend-sha "$(git rev-parse HEAD)" \
-out /path/to/saturday-python/tests/fixtures/contracts.json
```

Review generated differences before accepting them. `tests/test_contracts.py` checks payloads against TypedDict required/optional keys and value types, then exercises methods using mocked HTTP. Static examples are checked with `python -m mypy saturday tests/typecheck --check-untyped-defs --warn-unused-ignores`. This is local source-contract evidence, not a live deployed-API smoke test.
`tests/test_contracts.py` checks payloads against TypedDict required/optional keys and value types, then exercises methods using mocked HTTP. Static examples are checked with `python -m mypy saturday tests/typecheck --check-untyped-defs --warn-unused-ignores`. This is local source-contract evidence, not a live deployed-API smoke test.
Loading