Repository navigation
feat(wes/workflow/trs): fetch workflows from TRS - #89
Conversation
Plugins that need features on FOCA's dev branch (e.g., the WES run requests for wes.workflow.trs) can't pass the tests of FOCA releases. The new command `python -m scripts.packages foca PATH OLDEST` checks the plugin's foca requirement against the installed FOCA version and the oldest version of the matrix; the test job skips its checks for excluded versions, and plugins that exclude the oldest version report coverage from the dev entry. Refs #87 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add the plugin wes.workflow.trs (request phase): for runs whose workflow_url is a TRS URI (trs://<host>/<tool>/<version>) or the URL of a TRS v2 tool version, fetch the primary and secondary descriptors of the run's workflow type from an allowed TRS host through ctx.http, attach them to workflow_attachment and set workflow_url to the primary descriptor, so that every WES backend gets a self-contained run. Allowed hosts are empty by default; the number and total size of the files are limited; other TRS files (tests, container files, IO_SCHEMA) are not fetched. Generic helpers (allowed hosts, limits, safe paths, attaching) are in their own module, so that wes.workflow.git (#88) can reuse them. The plugin needs FOCA's WES run requests (foca#782), which no FOCA release has yet: the workspace takes FOCA from its dev branch (locked to a commit), and the plugin requires foca>=0.22.1.dev0,<0.24. Closes #87 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fixes from the pre-push review: - Check the size of TRS responses before parsing them (listings at most 1 MiB, descriptors within what max_size leaves), so that a TRS can't make the gateway parse large JSON documents. - Reject responses beyond the HTTP client's limit with 422, not 413: the TRS's response is too large, not the client's request. - Check fetched files against all of FOCA's name checks (directories and files inside files too) and reject conflicts with 409. - Always run the checks of the FOCA dev entry, so that no plugin can skip every matrix entry (`foca --dev`). - Move the allowed-host type into the reusable module, name the workflow_url field once, document IPv6 limits, the pip-audit gap while FOCA comes from Git, and that the plugin is in no release train. Refs #87 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check name conflicts with FOCA's check_attachments only (check_names), both for the files that the TRS lists (422, before fetching, now also directory conflicts) and for the fetched files against the client's (409, with a field-prefixed message). Drop file_key and the FIELD alias, attach the Host docstring to its alias, state the pre-parse size bound in the README, and test IPv6 hosts and directory conflicts. Refs #87 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Refs #87 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAPIDefine the
ImplementationImplement safe host checks, file limits, relative-path validation, attachment conflict checks and run mutation for fetched workflow files.
Parse TRS URIs and tool-version URLs, map WES workflow types, and fetch bounded descriptor listings and file contents through the guarded HTTP client.
Add the package tooling command that checks a plugin’s FOCA requirement against installed and oldest matrix versions.
ConfigurationConfigure CI to skip checks for unsupported FOCA releases while retaining a supported coverage entry, and declare the plugin’s package metadata, dependency bounds and entry point.
Use FOCA’s development branch for the workspace until the WES run-request API is released.
DocumentationDocument the TRS plugin’s behavior, limits, configuration, security boundaries, FOCA dependency and unreleased status.
Update plugin and WES subgroup catalogs to include workflow fetching from TRS.
Explain the unreleased status and FOCA-version testing policy in repository guidance.
TestsTest TRS fetching, plugin configuration and behavior, FOCA contracts, harness execution and entry-point loading.
Test TRS URI parsing, malformed inputs and workflow-type mapping.
Test the FOCA compatibility command and its step outputs.
Other changesFiles not grouped.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
4 files changed± index.html± catalogue/index.html± installing/index.html± writing-plugins/index.html |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #89 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 11 14 +3
Lines 1001 1239 +238
Branches 143 171 +28
==========================================
+ Hits 1001 1239 +238
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 ca235e7 #87 feat(wes/workflow): fetch workflows from TRS · 6 of 6 met
|
There was a problem hiding this comment.
Hey - I've found 6 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py" line_range="336" />
<code_context>
+ http,
+ f"{base}/descriptor/{quote(path, safe='')}",
+ "TRS lacks a descriptor that it lists",
+ (limits.max_size - limits.size) * JSON_OVERHEAD + WRAPPER_OVERHEAD,
+ limits.too_large(),
+ )
</code_context>
<issue_to_address>
**Descriptor wrappers evade aggregate size cap**
When an allowed TRS returns many descriptor responses with little content but large wrapper metadata, and the operator configures a high `max_files` limit, `fetch_descriptors` allows `WRAPPER_OVERHEAD` for every response, while `FileLimits` counts only descriptor content bytes; with 10,000 small descriptors, an allowed TRS can make the gateway receive and parse roughly 640 MiB of wrapper data despite a 10 MiB `max_size`.
Apply an aggregate response-body budget across the listing and descriptor responses, in addition to the per-response limits.
Also at `plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/__init__.py:60`.
</issue_to_address>
### Comment 2
<location path="plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/__init__.py" line_range="102-104" />
<code_context>
+ Args:
+ config: Validated admin settings.
+ """
+ self.allowed_hosts = frozenset(config.allowed_hosts)
+ self.max_files = config.max_files
+ self.max_size = config.max_size
+
+ def on_request(self, request: InboundRequest, ctx: Context) -> None:
</code_context>
<issue_to_address>
**Concurrent setup mixes settings**
When the same plugin instance receives concurrent `setup()` calls with different configurations, concurrent `setup()` calls with different configs can interleave these assignments, leaving `allowed_hosts`, `max_files` and `max_size` from different configs; a request can then enforce a policy that the operator configured neither time.
Publish the settings together as one immutable object and have each hook capture that object once before checking the host or limits.
Also at `plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/__init__.py:136-146`.
</issue_to_address>
### Comment 3
<location path="plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py" line_range="316-332" />
<code_context>
+ foca.utils.http.HttpError: A request failed.
+ """
+ base = f"{tool.url}/{quote(type_, safe='')}"
+ listing = _get_json(
+ http,
+ f"{base}/files",
+ f"TRS has no such tool version with type {type_}",
+ MAX_LISTING_SIZE,
+ Rejected(f"{WORKFLOW_URL}: TRS lists too many files", 422),
+ )
+ paths = [relative_path(path) for path in _descriptor_paths(listing)]
+ check_names(
+ [Attachment(path, b"") for path in paths],
+ 422,
+ f"{WORKFLOW_URL}: TRS lists conflicting descriptors",
+ )
+ limits.check_count(len(paths))
+ files: list[Attachment] = []
+ for path in paths:
+ wrapper = _get_json(
+ http,
+ f"{base}/descriptor/{quote(path, safe='')}",
</code_context>
<issue_to_address>
**Runs mix descriptor revisions**
When the TRS changes a tool version while its descriptors are being fetched, `fetch_descriptors` combines the file listing with descriptor responses from separate requests, so the run receives files from different revisions or is rejected when a listed file disappears.
Fetch the listing and descriptors from the same TRS revision.
</issue_to_address>
### Comment 4
<location path="plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py" line_range="323-329" />
<code_context>
+ MAX_LISTING_SIZE,
+ Rejected(f"{WORKFLOW_URL}: TRS lists too many files", 422),
+ )
+ paths = [relative_path(path) for path in _descriptor_paths(listing)]
+ check_names(
+ [Attachment(path, b"") for path in paths],
+ 422,
+ f"{WORKFLOW_URL}: TRS lists conflicting descriptors",
+ )
+ limits.check_count(len(paths))
+ files: list[Attachment] = []
+ for path in paths:
</code_context>
<issue_to_address>
**File limit runs too late**
When an allowed TRS returns a near-1-MiB listing containing far more descriptors than the configured `max_files`, `fetch_descriptors` materializes every descriptor path and runs `check_names` before `limits.check_count`; an oversized listing therefore consumes path, attachment, and conflict-checking work before the configured file limit rejects it, increasing gateway resource use under concurrent requests.
Check the descriptor count before constructing conflict-check attachments, and reject excess entries as early as practical while processing the listing.
</issue_to_address>
### Comment 5
<location path="plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py" line_range="194-195" />
<code_context>
+ scheme = parts.scheme.lower()
+ if scheme == "trs":
+ match = _TRS_URI_PATH.fullmatch(parts.path)
+ if match is None:
+ raise InvalidTrsUri("TRS URI is not trs://<host>/<tool>/<version>")
+ host = _check_parts(parts)
+ base_url = f"https://{host}{API_PATH}"
+ elif scheme == "https":
+ match = _TOOL_VERSION_PATH.fullmatch(parts.path)
+ if match is None:
+ return None
+ host = _check_parts(parts)
+ base_url = f"https://{host}{match['prefix']}{API_PATH}"
</code_context>
<issue_to_address>
**Malformed tool URLs bypass rejection**
When an HTTPS URL under the TRS API namespace has a malformed tool-version path, `parse_tool_version` returns `None` on the path-regex miss, so `Trs.on_request` raises `NotApplicable` and the malformed URL proceeds to the next pipeline step or WES backend instead of receiving a 400.
Reject malformed URLs under the TRS API namespace as invalid TRS input instead of returning `None`.
</issue_to_address>
### Comment 6
<location path="plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py" line_range="334" />
<code_context>
+ for path in paths:
+ wrapper = _get_json(
+ http,
+ f"{base}/descriptor/{quote(path, safe='')}",
+ "TRS lacks a descriptor that it lists",
+ (limits.max_size - limits.size) * JSON_OVERHEAD + WRAPPER_OVERHEAD,
</code_context>
<issue_to_address>
**Nested descriptors fail on TRS routes**
When a TRS server does not match encoded slashes in its descriptor route, the request encodes every `/` in a nested descriptor path as `%2F`. A TRS server that routes `relative_path` as multiple path segments and does not accept encoded separators returns 404; `_get_json` then rejects the WES run instead of attaching the nested descriptor.
Preserve `/` when quoting descriptor paths, or verify against real TRS implementations that the encoded-separator form is accepted.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 6 findings to address first, and a parsing or host-checking flaw could let a submitted TRS URI fetch workflow code from an unintended source and pass it to a WES backend for execution; the configured host allowlist and guarded HTTP client limit that risk. Reverting stops future fetches but cannot undo workflows already run or effects they caused.
Blocking findings: plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py:336, plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/__init__.py:104, plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py:332, plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py:329, plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/trs.py:195, and 1 more
From Sourcery's review: - Bound the bodies of all descriptor responses of a tool version together (six times max_size plus 64 KiB), so that many small descriptors with large FileWrapper fields can't make the gateway parse far more than max_size. - Check the number of descriptors before their paths and names. - Replace the settings as one frozen object in setup(), read once per call, so that calls never mix two configurations. Refs #87 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Adds the plugin
wes.workflow.trs(request phase, groupwes, new subgroupworkflow): for WES runs whoseworkflow_urlis a TRS URI (trs://<host>/<tool>/<version>) or the URL of a TRS v2 tool version (https://<host>[/<prefix>]/ga4gh/trs/v2/tools/{id}/versions/{version_id}), it fetches the primary and secondary descriptors of the run'sworkflow_type(CWL,WDL,NFL/Nextflow,SMK/Snakemake,GALAXY) viaGET .../{type}/filesandGET .../{type}/descriptor/{relative_path}, attaches them toworkflow_attachment(after the client's files, nested paths kept) and setsworkflow_urlto the primary descriptor's relative path. Other TRS files (tests, container files,OTHER, TRS-Filer'sIO_SCHEMA) are not fetched.foca.plugins.wes,Attachment).ctx.http(FOCA's guarded client: https, public addresses, no redirects, bounded sizes, step deadline).allowed_hosts(empty by default: every TRS URI is rejected with 403 until the admin allows hosts),max_files(100),max_size(10 MiB). Timeouts come from the step'stimeout, which bounds the whole fetch (ctx.http is bound to the call deadline).workflow_type), 403 (host not allowed), 409 (name or directory conflicts with attached files), 413 (more or larger descriptors than allowed), 422 (unknown tool/version/type, missing descriptor, no single primary descriptor, unsafe or duplicate paths, no inline content, oversized TRS responses). Response bodies are size-checked before JSON parsing. Unexpected TRS responses (5xx, 401, redirects, invalid JSON) fail the call (TrsError).foca_plugins.wes.workflow.trs.attach, without TRS specifics, so thatwes.workflow.git(feat(wes/workflow): fetch workflows from Git repos #88) can reuse them (copy, or move to a shared distribution).FOCA dependency (Git head)
No FOCA release has the WES run requests yet (latest is 0.22.0). Following the org rule (test against Git heads between releases):
pyproject.tomltakes FOCA from itsdevbranch ([tool.uv.sources], locked inuv.lockto7bc6d9c8); this applies to the whole workspace.foca>=0.22.1.dev0,<0.24.python -m scripts.packages foca PATH OLDEST [--dev]) skips the checks of matrix entries whose FOCA release a plugin'sfocarequirement excludes; thedeventry always runs, so no plugin can skip everything. Plugins that exclude the oldest release (0.19.0) report coverage from thedeventry. Other plugins keep their full matrix.Closes #87
How it was verified
Locally (Python 3.13, FOCA dev
0.22.1.dev11+g7bc6d9c8f):uv run coverage run --source plugins/wes/workflow/trs/src -m pytest plugins/wes/workflow/trs+coverage report: 127 passed, 100% line and branch coverage. Tests use a fake TRS (FOCA'sFakeHttp): CWL with nested descriptors and non-descriptor files, WDL with leading-slash paths, Nextflow via tool-version URL, unknown tool/version (404), missing descriptor, count, total-size, response-size and pre-parse size limits, host allowlist (default empty, ports, case), malformed URIs, name and directory conflicts (among listed files: 422; with attached files: 409), IPv6 hosts refused in settings, unexpected responses; FOCA's contract check (api="wes"), the harness, and a pipeline loading the installed entry point.coverage run --source scripts,docs -m pytest tests+ report: 149 passed, 100%.pre-commit run --all-files: all hooks pass (ruff, ruff format, semgrep, gitleaks, actionlint with shellcheck, ast-grep, ast-grep rule tests, mypy, package conventions).mkdocs build --strict: passes.CI (run 44067953493, head ca235e7): all checks pass (101, incl. Sourcery). The gate works as intended:
wes.workflow.trsskips lint/types/tests/audit on FOCA 0.19.0 to 0.22.0 and runs them on FOCAdev(which reports its coverage to Codecov); the other plugins run every entry, with coverage reported from FOCA 0.19.0 as before.Declined review findings
0.19.0in the step (quality review): GitHub matrix values can't be shared with a step of other entries; the matrix comment names the step to update with the matrix.plugins.attachments) in the plugin (adversarial review): the plugin can't read the gateway's limits; the README tells admins to keepmax_files/max_sizewithin them, and the engine fails the call otherwise. Name and directory conflicts are now checked in the plugin (409)./ga4gh/trs/v2/(e.g.PLAIN_CWLdescriptor URLs are valid workflow URLs as they are), keep/unencoded inrelative_path(the spec's canonical form is encoded; TRS-Filer routes both). Replies in the threads.relative_pathfrom the primary descriptor's directory. TRS-Filer and the TRS spec use paths relative to the version; leading slashes are stripped for registries that list paths from the root.Open questions
None.
🤖 Generated with Claude Code