Repository navigation
feat(wes/workflow/git): fetch workflows from Git - #91
Conversation
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]>
Reviewer's GuideAPIExpose the Git workflow plugin, its validated settings, and its request-phase behavior through FOCA’s plugin interface.
ImplementationParse supported Git-hosting file URLs into repository, ref, path, and archive URL details.
Download repository archives and read them in memory with bounded decompression and checks for unsafe paths, entries, filenames, and incomplete tar streams.
Provide shared host, attachment-limit, filename-conflict, and run-mutation helpers for WES workflow plugins.
ConfigurationDefine the standalone distribution, dependencies, plugin entry point, and package data for the Git workflow plugin.
Record the Git plugin’s license file.
Configure the workspace to resolve FOCA from its development branch until the WES plugin API is released.
DocumentationDocument supported Git URL forms, archive handling, attachment behavior, safety limits, configuration, data transfers, and FOCA version requirements.
Add the Git workflow plugin’s unreleased feature to its changelog.
List Git repositories as a source for WES workflow plugins.
Add the Git workflow plugin to the WES plugin catalogue.
Update project status to mention the unreleased Git workflow plugin.
Update installation guidance with the FOCA API requirement shared by both WES workflow plugins.
Explain the identical-copy convention for shared helpers and update FOCA development-branch guidance for both WES workflow plugins.
TestsVerify that every copy of the shared attachment helper remains identical.
Test archive reading, download handling, size bounds, and rejection of malformed or unsafe tar contents.
Test shared host and path helpers, file limits, attachment ordering, and name conflicts.
Test plugin settings, URL-to-run behavior, annotations, FOCA contracts, and execution through the plugin engine.
Test recognition and validation of GitHub, GitLab, and Bitbucket repository-file URLs.
Provide recorded GitHub, GitLab, and Bitbucket archives for deterministic tests.
Lock files and vendored codeUpdate the workspace lockfile for the new plugin package and dependency resolution.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #91 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 14 18 +4
Lines 1239 1552 +313
Branches 171 209 +38
==========================================
+ Hits 1239 1552 +313
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 abb1f47 #88 feat(wes/workflow): fetch workflows from Git repos · 8 of 8 met
|
There was a problem hiding this comment.
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
- 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]>
Summary
Adds the plugin
wes.workflow.git(requestphase, groupwes, subgroupworkflow), the sibling ofwes.workflow.trs(#89): WES clients pass the URL of a workflow's main file in a public Git repository asworkflow_url, and every WES backend gets a self-contained run with attached files.https://github.com/<owner>/<repo>/blob/<ref>/<path>,https://<gitlab host>/<namespace...>/<project>/-/blob/<ref>/<path>(gitlab.com, or other GitLab hosts inallowed_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.GETof the repository'star.gzarchive (codeload.github.com/.../tar.gz/<ref>, GitLab's-/archive/<ref>/archive.tar.gz, Bitbucket'sget/<ref>.tar.gz; all served without redirects) throughctx.http; nogitbinary.attach: directory, of the main file's directory;workflow_urlbecomes the main file's relative path.allowed_hosts(empty by default),attach,max_files,max_size,max_archive_size(decompressed archive); the step'stimeoutbounds the download, the gateway'smax_response_sizethe compressed archive. Private repositories are out of scope (404→422).max_archive_size); file sizes are checked againstmax_sizebefore 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'scheck_filename, conflicts throughcheck_attachments. GitLab's redirect to its sign-in page (missing or private projects) counts as422like404. 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'sValueError/OverflowErrormap toGitError. Nothing is written to disk. Onlytar.gzis read (no zip), as all three services offer it.attach.pyofwes.workflow.trsis 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), sotests/test_shared_modules.pychecks that the copies stay identical;docs/writing-plugins.mddescribes this. feat(wes/workflow/trs): fetch workflows from TRS #89's behaviour is unchanged.wes.workflow.trs, the plugin requiresfoca>=0.22.1.dev0,<0.24(WES run requests of the plugin API, FOCAdevonly), so CI's "Check FOCA version" step tests it with FOCA'sdevbranch only; moving to a FOCA release is build(wes/workflow/trs): require released FOCA #90.plugins/wes/README.md,plugins/README.md, root README status,docs/installing.md,docs/writing-plugins.md, rootpyproject.tomlcomments.Verification
plugins/wes/workflow/git/tests/data/): GitHub's real archive ofoctocat/Hello-Worldfromcodeload.github.com, and a small repository of our own CWL files archived withgit 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.pyincluded), 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 exceptactionlint, 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.wes.workflow.giton Python 3.11, 3.13 and 3.15 with FOCAdev(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
GitErrorinstead 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_endchecked 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:tarfilenever yields them (base-256 negatives raiseReadError; a negative paxsizeends the stream, which the end-of-archive check turns intoGitError), 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 makingtestsa package;wes.workflow.trsfollows the same per-module pattern.Quality: upper bounds for
max_size/max_archive_size. Declined: consistent withwes.workflow.trs; the README names the gateway limits that cap them.Quality: rename
_BoundedReader.remainingto private. Declined: the class itself is private, and tests read its attributes.Open questions
None.
Closes #88
🤖 Generated with Claude Code