Repository navigation
fix(api): declare problem details in WES spec - #170
Conversation
Error responses have been problem details since FOCA 0.22 (#107), but the served spec still declared `ErrorResponse` (`msg`, `status_code`). `additions.openapi.yaml` now declares `ProblemDetails` (title, status, detail, and type, code and errors for invalid fields) and uses it for all error responses of all operations; `413` of `POST /runs` and `501` of the task endpoints are declared as proWES extensions. The vendored file is unchanged. The contract tests make the deviations explicit: the vendored file is the published one but for the service info `$ref` (checked against the SHA-256 of the published file), and the served spec deviates from it only in a named list of deviations, each of which must be used. New tests send failing requests (400, 404, 413, 500, 501) and validate the responses against the declared status, media type and schema. The deviations are documented in the header of the additions and in docs/api.md; the upgrade notes say to regenerate clients. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Address review findings: jsonschema (and its stubs) are dev dependencies instead of a transitive import with a mypy override; the header of the additions points to the one list of deviations in docs/api.md and the test; the `info` rule can't raise IndexError; the deviation test is named for the merged spec it checks; the docs tell the vendored file from the served spec and name what clients lose. Co-Authored-By: Claude Opus 5.5 <[email protected]>
All operations reject unknown or invalid parameters (strict
validation) with 400 problem details, but WES declares no 400 for the
endpoints of a run (/runs/{run_id}...). Declare it there as a proWES
extension, allow it in the deviation test, and test unknown parameters
on every operation. `errors` of `ProblemDetails` gets `maxItems: 100`,
as FOCA caps it; the docs say what FOCA adds when serving.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review: POST /runs gets its own unknown-parameter test instead of a branch in the parametrized one, whose URLs now come from the paths; uv.lock is locked again with the repo's uv (revision 5); the upgrade notes and the deviation table read more clearly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
404 for unknown paths, 405 and 413 for too large bodies can answer any request; say so instead of declaring them on every operation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAPIDeclare FOCA’s problem-details schema and use it for WES error responses, including the proWES-specific 400, 413, and 501 status extensions.
ConfigurationAdd jsonschema and its typing package as development dependencies for the response-validation tests.
DocumentationDocument the specification deviations, problem-details behavior, and the need to regenerate clients after upgrading.
TestsValidate error responses against the served specification and ensure the vendored and merged specifications change only in explicitly allowed ways.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #170 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 18
Lines 860 861 +1
=========================================
+ Hits 860 861 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit a831abe #142 docs: declare problem details in the WES API spec · 2 of 2 met
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/ga4gh/wes/test_error_responses.py" line_range="136" />
<code_context>
+ the status, the media type or the body isn't declared for the
+ operation.
+ """
+ assert response.status_code == status
+ declared = spec["paths"][path][method]["responses"]
+ assert str(status) in declared, f"{status} not declared for {method} {path}"
</code_context>
<issue_to_address>
**Mismatched status field passes**
When an error response has an integer `body.status` different from its HTTP status, `assert_declared_error` checks only the HTTP status at `tests/ga4gh/wes/test_error_responses.py:136`; its schema validation at `:145` accepts any integer for `status`, so an HTTP 404 response with `body.status: 200` passes.
Assert that `response.json()["status"] == status` in `assert_declared_error`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: tests/ga4gh/wes/test_error_responses.py:136
The schema accepts any integer as `status`, so the check of declared errors also compares it with the HTTP status (Sourcery review). Co-Authored-By: Claude Opus 5.5 <[email protected]>
* feat!: configure WES backends Runs go to the WES instances of `custom.wes.backends`, a typed backend list of FOCA (`foca.plugins.backends`): WES instances (`type: ga4gh-wes`, with an optional `api_path`) and service registries whose verified WES instances are used (`type: ga4gh-service-registry`). New runs go to the first backend; without any, `POST /runs` is refused with `503 Service Unavailable` before anything is stored. The hard-coded WES is gone, and the app refuses to start with a configured WES instance at or below its public URL. FOCA 0.22 knows the backends of TES gateways only: the API type of WES is registered in `API_TYPES` (unless FOCA has one), and the entries of proWES subclass FOCA's, with `auth: none` only until #120. BREAKING CHANGE: deployments must configure their WES instances. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test: send smoke runs to a configured fake WES The fake WES is the WES instance of the smoke test's config overlay, at its Compose service name, instead of taking the host name of the former hard-coded WES. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs: describe WES backends Configuration, deployment (chart values `config.custom.wes.backends`), upgrade note, getting started, API and reference; a chart test checks that the backends reach the config overlay as the app reads them. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: guard against forwarding runs to proWES Review fixes: `server.public_url` is the root URL (docs said with the API path, which disabled the check); backend lists with registry entries need it; the startup check also covers `url` with `api_path`; the client's token is never passed on to WES instances (`auth: none`). Tests assert the reason of each invalid config; comments explain the reliance on FOCA 0.22 internals. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test: check that client tokens aren't passed on Round-2 review fixes: a regression test that no WES instance gets the client's token (runs, cancellations, tracking); the upgrade note says so; the docs explain public URLs of WES instances on the same host. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(api): declare 503 of POST /runs The response for runs without a WES instance, as the problem details of the other error responses (#170), with a test and the docs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: follow no redirects of WES instances Sourcery review fixes: WES clients don't follow redirects (e.g., of a discovered WES instance to an internal service), and the tracking task ignores client tokens of tasks queued by earlier versions. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Error responses have been problem details since FOCA 0.22 (#107). The served WES 1.1.0 spec still declared
ErrorResponse(msg,status_code), so clients generated from it didn't match the responses.pro_wes/api/additions.openapi.yamldeclaresProblemDetailsand uses it for every error response of every operation. The schema hastitleandstatus(required),detail, and, for requests with invalid fields,type,codeanderrors(at most 100), as FOCA sends them. FOCA merges the additions over the vendored spec, which replaces each$refthere; YAML anchors keep the file short.400on the endpoints of a run (/runs/{run_id}...), because all operations reject unknown or invalid parameters413onPOST /runs501on the two task endpointsjsonschemaandtypes-jsonschemaare added as dev dependencies; the tests use them to validate the responses."Only differs in X", made explicit
test_vendored_spec_changes_only_service_info_ref: the vendored file, with its one change (VENDORED_CHANGES, the local service info$ref) reverted, has the SHA-256 of the published WES 1.1.0 file (tag 1.1.0).test_merged_spec_deviates_only_as_allowed: every value in which the merged spec (vendored + additions, as FOCA merges them) differs from the vendored file must match a named entry ofALLOWED_DEVIATIONS, and every entry must be used.docs/api.md. The header ofadditions.openapi.yamlpoints to it and to the test.Responses match the declarations
tests/ga4gh/wes/test_error_responses.pyreads the servedopenapi.jsonand checks that every error response of every operation referencesProblemDetails. It then sends requests that fail and validates each response's status, media type and body against what the operation declares (jsonschema, Draft 4):page_size; an invalid run formDocs
docs/api.md: the deviation table; the statuses that any request can get and that aren't declared per operation (404 for unknown paths, 405, 413 for too large bodies); the errors section.docs/upgrading.md:ErrorResponseis replaced, so generated clients need to be regenerated.Verification
uv run coverage run -m pytest && uv run coverage report(after merging origin/dev): 329 passed, coverage 100%.tests/test_chart.pywas deselected because it needs Helm, which isn't installed locally; CI runs it.uv run mypy: no issues..semgrep.pre-commit run --all-filesitself couldn't fetch the hook repos through the sandbox proxy.uv lockwas run with the repo's uv 0.13.8;uv.lockonly adds the two dev dependencies.uv run --extra docs mkdocs build --strict: OK.Declined review findings
BOUNDARY,RUN_REQUEST,_multipart,_post_runandclient_withinto one shared module; the new test file now has a third copy. Declined here because the other two copies are intest_workflow_runs.pyandtest_run_request_limits.py, which parallel PRs (feat: configure WES backends #118, fix: drop Bearer None and stuck INITIALIZING runs #166) are editing. A follow-up issue has been drafted.413declared on every operation. FOCA can answer any operation with413for bodies overserver.max_content_length. This is documented as a status any request can get, like 404 for unknown paths and 405, instead of being declared on every operation.POST /runswith a JSON ortext/plainbody, andGET /runs?page_token=zzz, get500instead of400or415. Both responses are still declared problem details. A follow-up issue has been drafted.Open questions
None.
Closes #142
🤖 Generated with Claude Code
Summary by Sourcery
Align the served WES specification with proWES problem-detail error responses and enforce the contract with specification and response validation tests.
Bug Fixes:
Enhancements:
Build:
Documentation: