Skip to content

fix(api): declare problem details in WES spec - #170

Merged
uniqueg merged 7 commits into
devfrom
docs/142-problem-details-spec
Nov 18, 2026
Merged

uniqueg merged 7 commits into
devfrom
docs/142-problem-details-spec

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

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.yaml declares ProblemDetails and uses it for every error response of every operation. The schema has title and status (required), detail, and, for requests with invalid fields, type, code and errors (at most 100), as FOCA sends them. FOCA merges the additions over the vendored spec, which replaces each $ref there; YAML anchors keep the file short.
  • proWES extensions declared (statuses that proWES answers with but WES doesn't declare):
    • 400 on the endpoints of a run (/runs/{run_id}...), because all operations reject unknown or invalid parameters
    • 413 on POST /runs
    • 501 on the two task endpoints
  • The vendored spec file is unchanged.
  • jsonschema and types-jsonschema are 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 of ALLOWED_DEVIATIONS, and every entry must be used.
  • The list is documented once, in docs/api.md. The header of additions.openapi.yaml points to it and to the test.

Responses match the declarations

tests/ga4gh/wes/test_error_responses.py reads the served openapi.json and checks that every error response of every operation references ProblemDetails. It then sends requests that fail and validates each response's status, media type and body against what the operation declares (jsonschema, Draft 4):

Status Requests
400 an unknown parameter on all 8 operations; an invalid page_size; an invalid run form
404 unknown runs, on 3 endpoints
413 a body that is too large
500 an unexpected error
501 the task endpoints

Docs

  • 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: ErrorResponse is 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.py was deselected because it needs Helm, which isn't installed locally; CI runs it.
  • The new tests failed before the spec change (11 failed).
  • uv run mypy: no issues.
  • These hooks were run individually and are clean: ruff 0.17.5 check and format, ast-grep scan and test, semgrep with .semgrep. pre-commit run --all-files itself couldn't fetch the hook repos through the sandbox proxy.
  • uv lock was run with the repo's uv 0.13.8; uv.lock only adds the two dev dependencies.
  • uv run --extra docs mkdocs build --strict: OK.
  • Reviews: two rounds of adversarial and quality review; findings fixed, except those declined below.
  • CI: all checks green (run 44304003610: Lint, Test, Docs, Chart, Chart install, Smoke test, codecov).

Declined review findings

  • Shared multipart test helpers. The quality reviewer suggested moving BOUNDARY, RUN_REQUEST, _multipart, _post_run and client_with into one shared module; the new test file now has a third copy. Declined here because the other two copies are in test_workflow_runs.py and test_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.
  • 413 declared on every operation. FOCA can answer any operation with 413 for bodies over server.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.
  • Pre-existing 500s (out of scope). POST /runs with a JSON or text/plain body, and GET /runs?page_token=zzz, get 500 instead of 400 or 415. 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:

  • Declare FOCA's RFC 9457 problem-detail responses throughout the served WES specification so generated clients can correctly handle error payloads.

Enhancements:

  • Document the intentional differences between the vendored WES 1.1.0 specification and the served proWES specification, including supported status-code extensions.
  • Add contract tests that verify the vendored specification remains aligned with upstream and that merged-spec deviations are explicitly allowed.
  • Add response validation tests covering declared error statuses, media types, and problem-detail bodies across WES operations.

Build:

  • Add jsonschema and types-jsonschema development dependencies for validating error responses in tests.

Documentation:

  • Document problem-detail fields, proWES-specific error statuses, specification deviations, and the need to regenerate clients when upgrading.

uniqueg and others added 6 commits November 18, 2026 11:35
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Declare FOCA’s problem-details schema and use it for WES error responses, including the proWES-specific 400, 413, and 501 status extensions.

  • pro_wes/api/additions.openapi.yaml L1-6, L26 (removed lines), L28-182

Configuration

Add jsonschema and its typing package as development dependencies for the response-validation tests.

  • pyproject.toml L127-128, L133

Documentation

Document the specification deviations, problem-details behavior, and the need to regenerate clients after upgrading.

  • docs/api.md L10-35, L98-102
  • docs/upgrading.md L78-83

Tests

Validate error responses against the served specification and ensure the vendored and merged specifications change only in explicitly allowed ways.

  • tests/ga4gh/wes/test_error_responses.py L1-311
  • tests/ga4gh/wes/test_spec.py L4-12, L28-140, L233-305 (+1 small edits)

Other changes

Files not grouped.

  • uv.lock L2379-2390 (+4 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (af74d0a) to head (a831abe).
⚠️ Report is 1 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 18, 2026 12:32
@sourcery-ai

sourcery-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit a831abe

#142 docs: declare problem details in the WES API spec · 2 of 2 met

# Requirement Status Notes
1 Declare the problem-details schema in additions.openapi.yaml and reference it from error responses. ✅ Met ProblemDetails is declared and used for error responses; contract tests check the served specification and validate failing responses against it.
2 Make this change together with WES 1.1.0 and the response type fixes, so the vendored spec changes only once. ✅ Met The vendored file remains the published WES 1.1.0 specification apart from the local service-info reference, verified by the upstream SHA-256 contract test.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/ga4gh/wes/test_error_responses.py Resolved
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]>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@uniqueg
uniqueg merged commit 2e13a3f into dev Nov 18, 2026
21 checks passed
@uniqueg
uniqueg deleted the docs/142-problem-details-spec branch November 18, 2026 12:55
uniqueg added a commit that referenced this pull request Nov 18, 2026
* 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]>
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.

docs: declare problem details in the WES API spec

1 participant