Repository navigation
test(utils): add unit tests, coverage in CI and a README - #1982
Conversation
|
No actionable comments were generated in the recent review. Summary
Change: Other Merge Risk:
|
…uide (#2017) ## Summary SDK-2702 asks for SDK-owned `Request`, `Response` and `Headers` types, a `send(request) -> Response` adapter protocol, httpx confined to its adapter, and a README that shows how to write an adapter. All of that already landed in #1977 (httpx only inside the adapter, guarded by the `import-without-httpx` job in the CI workflow) and #1982 (the README). This finishes the ticket by bringing the adapter guide up to date with the per-request `timeout` that #2010 added after the guide was written. ## Changes - The `Request` field table lists `timeout`, and the guide says to raise `RequestTimeoutError` when it elapses, so every adapter reports a timeout the same way. - The guide says what to do with credential headers on redirects, pointing at the `keeps_credentials` and `CREDENTIAL_HEADERS` helpers the built-in adapters use. - The `requests` example passes the timeout through, translates `requests.Timeout` into `RequestTimeoutError`, and does not follow redirects. - `supabase_utils.http.errors` and `supabase_utils.http.redirects` appear in the module table. ## Verification Ran the `requests` example, extracted from the README rather than retyped, through `SyncHttpIO` against a local `http.server`: repeated headers join to `a, b`, a 302 comes back unfollowed, and a slow endpoint raises `RequestTimeoutError` with the `requests.Timeout` as its cause. Linear: SDK-2702
Resolves SDK-2706.
supabase_utilsis the shared HTTP layer every v3 package builds on. Before this change it had no tests, its CI job only ran pyrefly, and its README was empty.Changes
src/utils/tests, covering 100% of the package:Headers: case insensitivity, repeated values,override,update, immutability andX-Client-Info.URLQuery: repeated values,merge, immutability and encoding into ayarl.URL.Content-Type, JSON bodies from dicts and pydantic models (exclude_none), text, multipart encoding, andResponse.is_success/is_errorbounds.SyncHttpIOandAsyncHttpIOwith multi-request generators,delay, methods that send no request and error propagation.handle_http_iowith both executors and its preserved name, docstring and signature.httpx.MockTransport(sync and async) and aiohttp against a localaiohttp.test_utils.TestServer, including closing the client when the context manager exits.utilswas already in the matrix, butmake utils.testsonly ran pyrefly. It now runs pytest with coverage like the other packages, and the Coveralls upload no longer skipsutils(PACKAGES_WITHOUT_COVERAGEis removed fromci_matrix.py).testsdependency group (pytest, pytest-cov, pytest-asyncio), pytest configuration, and pyrefly now checkstestsas well.requestsexample.Found while testing, not changed here
QueryValueincludesbool, but yarl raisesTypeErrorfor bool query values, soURLQuery.from_mapping({"flag": True})fails when the request is finalized. No caller passes a bool today.Headers.from_mappingkeeps only the last value of a repeated response header from aiohttp (for example severalSet-Cookieheaders), because a multidict yields every value as its own item andfrom_mappingoverwrites the key.