Skip to content

feat(wes/workflow/git): fetch workflows from Git - #91

Merged
uniqueg merged 6 commits into
devfrom
feat/88-wes-workflow-git
Nov 17, 2026
Merged

uniqueg merged 6 commits into
devfrom
feat/88-wes-workflow-git

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the plugin wes.workflow.git (request phase, group wes, subgroup workflow), the sibling of wes.workflow.trs (#89): WES clients pass the URL of a workflow's main file in a public Git repository as workflow_url, and every WES backend gets a self-contained run with attached files.

  • URLs recognized (documented in the plugin README): https://github.com/<owner>/<repo>/blob/<ref>/<path>, https://<gitlab host>/<namespace...>/<project>/-/blob/<ref>/<path> (gitlab.com, or other GitLab hosts in allowed_hosts), https://bitbucket.org/<workspace>/<repo>/src/<ref>/<path>. Refs are branches, tags or commits; refs with / are URL-encoded (feature%2Fx), which all three services accept in their archive URLs (checked live). Other forms (raw, tree, raw.githubusercontent.com) don't apply.
  • Fetch: one GET of the repository's tar.gz archive (codeload.github.com/.../tar.gz/<ref>, GitLab's -/archive/<ref>/archive.tar.gz, Bitbucket's get/<ref>.tar.gz; all served without redirects) through ctx.http; no git binary.
  • Attach: the files of the whole repository (default) or, with attach: directory, of the main file's directory; workflow_url becomes the main file's relative path.
  • Settings: allowed_hosts (empty by default), attach, max_files, max_size, max_archive_size (decompressed archive); the step's timeout bounds the download, the gateway's max_response_size the compressed archive. Private repositories are out of scope (404 → 422).
  • Archive safety: the archive is decompressed as a stream behind a size bound checked while reading (archive bombs, also huge pax headers, stop at max_archive_size); file sizes are checked against max_size before reading; entries with absolute paths or .././empty segments are refused anywhere in the archive; links (symbolic, hard), devices, FIFOs and sparse files among the files to attach are refused; all entries must be below one top directory; filenames go through FOCA's check_filename, conflicts through check_attachments. GitLab's redirect to its sign-in page (missing or private projects) counts as 422 like 404. Entry names longer than 4096 characters are refused before they are split; the tar stream must end with zero blocks only (tarfile otherwise ends streams silently at an invalid header, which would attach a partial file list); tarfile's ValueError/OverflowError map to GitError. Nothing is written to disk. Only tar.gz is read (no zip), as all three services offer it.
  • Shared helpers: attach.py of wes.workflow.trs is copied unchanged (only its docstring now names both copies). A shared library distribution doesn't fit the repository's package conventions (every workspace package is a plugin with an entry point, scripts/checks.py), so tests/test_shared_modules.py checks that the copies stay identical; docs/writing-plugins.md describes this. feat(wes/workflow/trs): fetch workflows from TRS #89's behaviour is unchanged.
  • FOCA: like wes.workflow.trs, the plugin requires foca>=0.22.1.dev0,<0.24 (WES run requests of the plugin API, FOCA dev only), so CI's "Check FOCA version" step tests it with FOCA's dev branch only; moving to a FOCA release is build(wes/workflow/trs): require released FOCA #90.
  • Docs: plugin README and CHANGELOG, plugins/wes/README.md, plugins/README.md, root README status, docs/installing.md, docs/writing-plugins.md, root pyproject.toml comments.

Verification

  • Recorded archives (plugins/wes/workflow/git/tests/data/): GitHub's real archive of octocat/Hello-World from codeload.github.com, and a small repository of our own CWL files archived with git archive --format=tar.gz --prefix=<top>/ under each service's top-directory naming (GitHub, GitLab, Bitbucket), which is how the services build their archives (pax global header with the commit; checked against live archives of all three).
  • coverage run --source plugins/wes/workflow/git/src -m pytest plugins/wes/workflow/git: 202 passed, 100% line and branch coverage.
  • coverage run --source scripts,docs -m pytest tests: 151 passed (tests/test_shared_modules.py included), 100%.
  • pytest plugins/wes/workflow/trs: passed (unchanged behaviour).
  • ruff check, ruff format --check, ast-grep scan, python -m scripts.packages mypy: clean.
  • pre-commit run --all-files: all hooks passed except actionlint, which fails locally only because the local shellcheck shim has no version set (no workflow files changed).
  • mkdocs build --strict: passed; the catalogue lists the plugin.
  • uv build --all-packages + python -m scripts.checks dist: passed.
  • CI: all checks passed on the head commit (117 checks, before the Sourcery fixes, run 44084498826; re-run on the final head), including wes.workflow.git on Python 3.11, 3.13 and 3.15 with FOCA dev (the FOCA releases skipped by the "Check FOCA version" step), Codecov patch and project.

Reviews: adversarial and quality reviewer, two rounds. Round 1 found 1 medium (GitLab sign-in redirect gave GitError instead of 422) and 3 low archive findings (ValueError escaping, silent end at invalid headers, memory blow-up of very long names), all fixed; quality findings on the shared-module test (now glob-based) and text wrapping fixed. Round 2: no findings; is_end checked against valid and invalid archives on Python 3.11–3.14.

Sourcery (3 threads, all replied and resolved): GitLab sign-in redirects now count only for the same host (fixed); refs may start with - (fixed); negative tar sizes declined, see below.

Declined review findings

  • Sourcery: reject negative entry sizes before FileLimits.add. Declined: tarfile never yields them (base-256 negatives raise ReadError; a negative pax size ends the stream, which the end-of-archive check turns into GitError), verified on Python 3.11 to 3.14.

  • Quality: move duplicated test constants (REPO_FILES) into a shared test helper. Declined: pytest runs with --import-mode=importlib, so test modules can't import a sibling helper without making tests a package; wes.workflow.trs follows the same per-module pattern.

  • Quality: upper bounds for max_size/max_archive_size. Declined: consistent with wes.workflow.trs; the README names the gateway limits that cap them.

  • Quality: rename _BoundedReader.remaining to private. Declined: the class itself is private, and tests read its attributes.

Open questions

None.

Closes #88

🤖 Generated with Claude Code

uniqueg and others added 4 commits November 17, 2026 12:49
Add the plugin wes.workflow.git: for runs whose workflow_url is the URL
of a file at a ref of a public repository on GitHub, GitLab or
Bitbucket, download the repository's tar.gz archive through ctx.http,
attach its files (the whole repository or the main file's directory)
and point workflow_url to the file.

Archives are read in memory, as a stream whose decompressed size is
checked while it is read; entries with unsafe paths, links and special
entries are refused. The helpers of wes.workflow.trs (attach.py) are
copied unchanged; tests/test_shared_modules.py keeps the copies equal.

Tests use recorded archives of each service.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
List the plugin in the group README, the status and the install docs,
and describe how plugins share helpers (identical copies, checked by
tests/test_shared_modules.py).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Treat GitLab's redirect to its sign-in page (missing or private
  projects) as "no such public repository" (422), as documented.
- Require the end of the tar stream (zero blocks only): tarfile ends
  streams silently at an invalid header after the first entry, which
  would attach a partial list of files.
- Map ValueError and OverflowError of tarfile (e.g., malformed GNU
  sparse headers) to GitError.
- Refuse entry names longer than 4096 characters before splitting
  them, so that long names can't take memory far beyond their size.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check every copy of attach.py in the wes.workflow plugins, not a fixed
list, so that new copies are checked too; re-wrap the edited docs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Expose the Git workflow plugin, its validated settings, and its request-phase behavior through FOCA’s plugin interface.

  • plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/__init__.py L1-193

Implementation

Parse supported Git-hosting file URLs into repository, ref, path, and archive URL details.

  • plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/repo.py L1-228

Download repository archives and read them in memory with bounded decompression and checks for unsafe paths, entries, filenames, and incomplete tar streams.

  • plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/archive.py L1-309

Provide shared host, attachment-limit, filename-conflict, and run-mutation helpers for WES workflow plugins.

  • plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/attach.py L1-250
  • plugins/wes/workflow/trs/src/foca_plugins/wes/workflow/trs/attach.py L7-11

Configuration

Define the standalone distribution, dependencies, plugin entry point, and package data for the Git workflow plugin.

  • plugins/wes/workflow/git/pyproject.toml L1-67

Record the Git plugin’s license file.

  • plugins/wes/workflow/git/LICENSE L1-201

Configure the workspace to resolve FOCA from its development branch until the WES plugin API is released.

  • pyproject.toml L23-28

Documentation

Document supported Git URL forms, archive handling, attachment behavior, safety limits, configuration, data transfers, and FOCA version requirements.

  • plugins/wes/workflow/git/README.md L1-170

Add the Git workflow plugin’s unreleased feature to its changelog.

  • plugins/wes/workflow/git/CHANGELOG.md L1-15

List Git repositories as a source for WES workflow plugins.

  • plugins/README.md L24

Add the Git workflow plugin to the WES plugin catalogue.

  • plugins/wes/README.md L13-14

Update project status to mention the unreleased Git workflow plugin.

  • README.md L47-51

Update installation guidance with the FOCA API requirement shared by both WES workflow plugins.

  • docs/installing.md L37-39

Explain the identical-copy convention for shared helpers and update FOCA development-branch guidance for both WES workflow plugins.

  • docs/writing-plugins.md L77-80, L159-162

Tests

Verify that every copy of the shared attachment helper remains identical.

  • tests/test_shared_modules.py L1-31

Test archive reading, download handling, size bounds, and rejection of malformed or unsafe tar contents.

  • plugins/wes/workflow/git/tests/test_archive.py L1-704

Test shared host and path helpers, file limits, attachment ordering, and name conflicts.

  • plugins/wes/workflow/git/tests/test_attach.py L1-155

Test plugin settings, URL-to-run behavior, annotations, FOCA contracts, and execution through the plugin engine.

  • plugins/wes/workflow/git/tests/test_git.py L1-573

Test recognition and validation of GitHub, GitLab, and Bitbucket repository-file URLs.

  • plugins/wes/workflow/git/tests/test_repo.py L1-212

Provide recorded GitHub, GitLab, and Bitbucket archives for deterministic tests.

  • plugins/wes/workflow/git/tests/data/bitbucket.tar.gz
  • plugins/wes/workflow/git/tests/data/github-hello-world.tar.gz
  • plugins/wes/workflow/git/tests/data/github.tar.gz
  • plugins/wes/workflow/git/tests/data/gitlab.tar.gz

Lock files and vendored code

Update the workspace lockfile for the new plugin package and dependency resolution.

  • uv.lock L15, L1341-1355

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

@read-the-docs-community

read-the-docs-community Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 foca-plugins | 🛠️ Build #35957190 | 📁 Comparing da4fa05 against latest (087ea70)

  🔍 Preview build  

4 files changed
± index.html
± catalogue/index.html
± installing/index.html
± writing-plugins/index.html

@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (087ea70) to head (da4fa05).

Additional details and impacted files
@@            Coverage Diff             @@
##               dev       #91    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           14        18     +4     
  Lines         1239      1552   +313     
  Branches       171       209    +38     
==========================================
+ Hits          1239      1552   +313     
Flag Coverage Δ
foca-plugin-generic-example-noop 100.00% <ø> (ø)
foca-plugin-generic-routing-random 100.00% <ø> (ø)
foca-plugin-tes-data-crypt4gh 100.00% <ø> (ø)
foca-plugin-tes-routing-distance 100.00% <ø> (ø)
foca-plugin-wes-workflow-git 100.00% <100.00%> (?)
foca-plugin-wes-workflow-trs 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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 17, 2026 12:37
@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit abb1f47

#88 feat(wes/workflow): fetch workflows from Git repos · 8 of 8 met

# Requirement Status Notes
1 Add a request-phase WES plugin ✅ Met The wes.workflow.git plugin implements on_request and declares the wes API.
2 Recognize and document GitHub, GitLab and Bitbucket repository file URLs at a ref ✅ Met The parser handles the documented URL forms, including nested GitLab groups and URL-encoded refs.
3 Fetch repository files over HTTPS and attach them, setting workflow_url to the main file's relative path ✅ Met The plugin downloads a tar.gz archive through ctx.http, attaches the whole repository or the main file's directory, and rewrites workflow_url.
4 Configure allowed hosts, file-count and total-size limits, and timeouts; use FOCA's guarded HTTP client ✅ Met The plugin provides host and file limits, uses ctx.http, and documents that the pipeline step's timeout bounds the download.
5 Keep private repositories out of scope ✅ Met No credentials are used; missing or private repositories are treated as unavailable.
6 Check that FOCA's WES API lets request plugins add workflow attachments ✅ Met The plugin uses FOCA's WES attachment API and tests the resulting run request with FOCA's WES request checker.
7 Test recorded archive responses for each host, including ref and path resolution, limits, and missing refs or files ✅ Met Tests cover recorded archives for GitHub, GitLab and Bitbucket, plus host and file limits and missing refs or files.
8 Document the plugin and its configuration in the README ✅ Met The plugin README documents accepted URLs, behavior, configuration, limits and timeout.

@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 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/archive.py" line_range="286" />
<code_context>
+                    )
+                filename = relative_path(path[len(directory) :])
+                limits.check_count(len(files) + 1)
+                limits.add(entry.size)
+                reader = tar.extractfile(entry)
+                data = reader.read() if reader is not None else b""
</code_context>
<issue_to_address>
**Negative sizes bypass the file limit**

When an archive contains a regular-file header with a negative size followed by files whose total exceeds `max_size`, `FileLimits.add` subtracts a negative tar entry size from the running total, so a later regular file can exceed `max_size` while passing the check and being attached; callers receive a run whose fetched files exceed the configured limit.

Reject negative entry sizes as an invalid archive before updating `FileLimits`.
</issue_to_address>

### Comment 2
<location path="plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/archive.py" line_range="182" />
<code_context>
+        location = urlsplit(headers.get("location", ""))
+    except ValueError:
+        return False
+    return location.path.rstrip("/").endswith(GITLAB_SIGN_IN)
+
+
</code_context>
<issue_to_address>
**Unrelated redirects look like missing repositories**

When A GitLab archive response redirects to an unrelated URL whose path ends in `/users/sign_in`, `_is_sign_in` classifies any redirect whose path ends in `/users/sign_in` as a missing repository, so `download_archive` raises `Rejected` with status 422 instead of `GitError`; callers see a false missing-repository error and the step's `on_failure` handling is bypassed.

Validate that the redirect target is the GitLab sign-in endpoint (including supported path prefixes) before treating it as a missing project.
</issue_to_address>

### Comment 3
<location path="plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/repo.py" line_range="117" />
<code_context>
+        not ref
+        or len(ref.encode("utf-8", "surrogatepass")) > MAX_REF_SIZE
+        or _REF_FORBIDDEN.search(ref)
+        or ref.startswith(("/", ".", "-"))
+        or ref.endswith(("/", "."))
+        or ref == "@"
</code_context>
<issue_to_address>
**Hyphen-leading branches are rejected**

When a repository uses a valid branch name beginning with `-`, `_ref` rejects a valid branch ref beginning with `-`, so `parse_repo_file` raises `InvalidRepoUrl` and the run is rejected with 400 instead of fetching that workflow.

Allow valid hyphen-leading refs and update the parser tests to cover them.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and if URL parsing or archive handling selects the wrong workflow file or ref, the gateway can submit unintended repository code as an executable WES workflow. Reverting stops future use, but cannot undo side effects of runs that already started.

Blocking findings: plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/archive.py:286, plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/archive.py:182, plugins/wes/workflow/git/src/foca_plugins/wes/workflow/git/repo.py:117


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

- Count only redirects to the sign-in page of the same GitLab host as
  missing projects; other redirects still fail the call.
- Accept refs that start with `-` (valid tag names); they are encoded
  in the archive URLs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg
uniqueg merged commit 200b5fe into dev Nov 17, 2026
216 of 225 checks passed
@uniqueg
uniqueg deleted the feat/88-wes-workflow-git branch November 17, 2026 13:37
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.

feat(wes/workflow): fetch workflows from Git repos

1 participant