diff options
| author | Pjotr <wrk@bosa.lan> | 2026-10-08 11:24:58 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-08 11:55:30 +0000 |
| commit | 22540223c43342473d7d428dffeeab9d94afb55c (patch) | |
| tree | f81c6af04ea9157054a58d3fc20e99f55973a0ae /test/python/server_test_case.py | |
| parent | 5650076cdf45a26aed8c6166069d74281a7f4bd7 (diff) | |
| download | genenetwork4-22540223c43342473d7d428dffeeab9d94afb55c.tar.gz | |
* src/response.rs: wrap every success response in one envelope.
Breaking: every success body is now {"data", "meta": {"state",
"took_ms", "request_id"}, "notes", "next"}; clients read `data`. Only
`/` (plain text) and `/openapi.json` are unwrapped.
* src/response.rs (Envelope, Meta, State, Ctx, RequestInfo): handlers
take Ctx first and build the response with ctx.envelope(data), so
timing and the request id are never filled in by hand. `state` is
`complete` or `partial`; notes are server-authored only; `next` are
concrete relative hrefs (path_segment percent-encodes names).
* src/routes/*.rs, src/lib.rs (version): every handler returns
Envelope<..> with next links; /search is `partial` when the locus
lookup fails or a sorted 1000-hit window may be truncated, and
/publications/{pubmed_id}/traits when datasets were left out for
authorization.
* src/error.rs (ApiError): add `took_ms`, an RFC 7807 extension member.
* src/auth.rs (AuthToken): the 401 now carries request_id and took_ms
(it never had a request_id); Ctx stores RequestInfo in the request
extensions for it.
* tests: common::data / envelope_data parse every success body through
the envelope; tests/envelope.rs and test/python/test_envelope.py check
the shape, errors, and that every `next` link resolves;
tests/envelope_partial.rs checks the `partial` search without a
database; tests/openapi.rs fails if a JSON success response is not an
Envelope_* schema.
* README.md, docs/SKILL.md, docs/gn-auth.md, RELEASE_NOTES.md: document
the envelope and took_ms on errors.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'test/python/server_test_case.py')
| -rw-r--r-- | test/python/server_test_case.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/python/server_test_case.py b/test/python/server_test_case.py index be2dcf9..c400661 100644 --- a/test/python/server_test_case.py +++ b/test/python/server_test_case.py @@ -4,6 +4,7 @@ integration tests under tests/, which call the router in-process). """ import hashlib +import json import os import socket import struct @@ -17,6 +18,18 @@ HOST = "127.0.0.1" PORT = os.environ.get("GENENETWORK4_PORT", "3000") +def envelope_data(body): + """The `data` of a success response body, after checking that the + body is the standard envelope: `meta` (state, took_ms, request_id), + `notes` and `next` next to `data`.""" + envelope = json.loads(body) + assert isinstance(envelope["meta"]["state"], str), envelope + assert isinstance(envelope["meta"]["took_ms"], int), envelope + assert isinstance(envelope["notes"], list), envelope + assert isinstance(envelope["next"], list), envelope + return envelope["data"] + + def wait_for_port(host, port, timeout=10): deadline = time.time() + timeout while time.time() < deadline: |
