Repository navigation
feat(plugins): add WES to typed backend lists - #791
Conversation
Backend lists knew TES gateways only, so WES gateways (proWES) registered the WES API type themselves, overrode the type of ServiceEntry and bypassed the validation of BackendList. - API_TYPES gets "wes" (ga4gh-wes entries, /ga4gh/wes/v1). - ServiceEntry takes type ga4gh-wes and an optional api_path, by default the path of the entry type's API, checked and stored without trailing slash, as proTES and proWES do. - BackendList refuses backend entries of another API's type. - Docs: backend lists in plugins.md and the module docstring; a note for WES gateways in the 0.23.0 migration guide. Closes #789 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The field validator of ServiceEntry.api_path removed trailing slashes, so validators of subclasses that redefine the field (proTES, proWES) got "" for "/" and refused it. It now only checks the path; the model validator removes trailing slashes, also of subclass defaults, and refuses entry types without an API type instead of a KeyError. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideData structuresExtend the backend API type table for WES and add validated, normalized API paths to service entries, including subclass defaults.
APIMake backend lists enforce that service entries match the API type selected for the list.
DocumentationDocument WES backend-list types, configurable API paths, and the migration guidance for gateways that can remove their workarounds.
TestsAdd coverage for WES lists and discovery, API-type enforcement, API-path validation and normalization, subclass behavior, and candidate lookup.
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 #791 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 75 75
Lines 10048 10076 +28
=========================================
+ Hits 10048 10076 +28
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 84bb36a #789 feat(plugins): add WES to typed backend lists · 6 of 6 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="foca/plugins/backends/config.py" line_range="140" />
<code_context>
+ # the API path of the entry type by default (set when validated)
+ api_path: str | None = None
+
+ @field_validator("api_path")
+ @classmethod
+ def _check_api_path(cls, value: str | None) -> str | None:
</code_context>
<issue_to_address>
**Invalid subclass path default slips through**
When an app-defined `ServiceEntry` subclass supplies an invalid `api_path` default, `_check` only removes the trailing slash; Pydantic skips `_check_api_path` for an unvalidated field default, so the invalid path reaches app request construction and targets an incorrect endpoint.
Validate subclass defaults as well, or recheck the final normalized path in `_check`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: foca/plugins/backends/config.py:140
Field validators don't run on defaults, so an invalid api_path default of a ServiceEntry subclass went unchecked. The model validator now checks the final path too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Typed backend lists (
foca.plugins.backends) now know WES gateways, soproWES no longer needs to register the API type, override the
Literaltype of
ServiceEntryor bypass the validation ofBackendList.API_TYPES["wes"] = ApiType("org.ga4gh", "wes", "/ga4gh/wes/v1", "ga4gh-wes").ServiceEntry.typeisLiteral["ga4gh-tes", "ga4gh-wes"].BackendList(entries, api=...)refuses service entries whose type isn'tthe
entry_typeof the API (the check the old comment anticipated), socreate_app()fails on them.ServiceEntry.api_path(optional): by default the path of the entrytype's API; absolute, unreserved characters, no empty,
.or..segments; stored without trailing slash (
/becomes empty). The fieldvalidator only checks the value and leaves it as given; the model
validator normalizes it. That way, subclasses that redefine the field with
validators of their own (proTES
TesServiceEntry, proWESWesServiceEntry) keep working,api_path: /included (regression test).docs/plugins.md, the package docstring, and asection "Backend lists know WES" in
docs/migration-0.23.md(not abreaking change; it describes what WES gateways can drop). This repo
writes release notes when a release is prepared, so the changelog gets no
entry now.
Verification
pytest tests/plugins/test_plugin_backends.py: 84 passed. New tests coverWES and TES lists both ways, WES discovery through a registry, the
api_pathdefaults, normalization and invalid paths, subclass defaults,subclass validators, entry types without an API type, and
entry_for(...).api_path.ruff check,ruff format --checkandmypypass.integration, lint, docs build, chart, image scans; codecov patch and
project pass). Locally, the full suite wasn't run, because its MongoDB
tests use the hard-coded port 12345.
Review
Full lane:
adversarial-reviewerandquality-reviewer, then a secondadversarial round. Round 1 found a high issue: the base validator stripped
/to an empty string before the validators of proTES and proWES ran, whichrefuse it. Fixed in the second commit, with a regression test. Round 2 and
Sourcery noted that subclass defaults of
api_pathskipped the path check;fixed in the third commit (the model validator checks the final path).
Declined review findings
api_pathin one place only. Declined: thedocstring and the user docs serve different readers, and the wording now
matches.
BackendListwithServiceEntrysubclasses.Declined:
BackendListConfigkeeps model instances as they are, and thetype check is the same
isinstancepath that the base-class tests cover.ga4gh-wesentry in a TES gateway's list isrefused by
BackendList, not byBackendListConfig. Kept as designed:BackendListConfigdoesn't depend on the API, andcreate_app()stillfails at startup.
api_pathis typedstr | Nonealthough it isalways a
strafter validation. Declined: a sentinel default wouldoverwrite subclasses' own defaults (
model_fields_setdoesn't tell themapart), and proTES/proWES redeclare the field as
stranyway; thedocstring says it is set when validated.
Open questions
None.
Follow-up in proWES (drop its workaround once a FOCA release has this) is
drafted, not posted.
Closes #789
🤖 Generated with Claude Code
Summary by Sourcery
Add first-class WES support and API-path validation to typed backend lists.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: