Skip to content

feat(filer): upload wildcard output matches - #134

Merged
uniqueg merged 4 commits into
devfrom
feat/wildcard-outputs
Nov 10, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/wildcard-outputs

Conversation

@anuragxxd

@anuragxxd anuragxxd commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Summary

Part of elixir-cloud-aai/TESK#276 (TES 1.1 wildcard outputs); tesk-api's part is elixir-cloud-aai/tesk-api#133.

  • Filer (upload_matches): an output whose path has wildcards (*, ?, [; POSIX pattern matching, as TES 1.1 specifies) and a path_prefix is expanded for every scheme, not only file: URLs.
    • Each match is uploaded to url, a directory, plus its path below path_prefix: /data/s1/out.txt for path /data/*/out.txt and path_prefix /data goes to url/s1/out.txt.
    • Matched directories are uploaded with their contents.
    • * skips dot-files and .command.* matches them, as in the shell.
    • A pattern that matches nothing uploads nothing and succeeds, so a single-file class such as out.tx[*t] makes an optional output.
  • Safety: matches that aren't below path_prefix, or that are or contain symbolic links, fail the output before anything is uploaded, in keeping with fix(filer): don't follow symlinks in outputs #124.
  • HTTP(S) URLs: each path component is escaped as in http_join, keeping the query (url_join).
  • Taskmaster (dirname): an output with wildcards is mounted at the pattern's deepest directory without wildcards (/data for /data/*/out.txt). Before, it was mounted at /data/*, a directory the executor never writes to. The helpers hasWildcards and wildcardRoot are in path.py.
  • Unchanged: outputs without path_prefix (TES 1.0) behave as before, including file: globs.
  • Docs: "Outputs with wildcards" in docs/filer.md.

Verification

Locally (Python 3.10, rebased on dev at 3035e26):

  • ruff check, ruff format --check: pass
  • mypy: no issues in 43 source files
  • pytest tests/unit: 634 passed, 26 of them new in tests/unit/test_filer_wildcards.py (S3 via moto: plain, directory-level and hidden-file patterns, matched directories, no match, single-file classes, outside-prefix and symlink refusals, the TES 1.0 path; url_join; mounts)
  • mkdocs build --strict: pass

On a cluster

Filer and taskmaster images built from this branch, with tesk-api from the companion PR, installed with the TESK dev chart (Talos, Kubernetes 1.33, local-path PVCs). Outputs went to presigned S3 URLs over HTTP through a TES gateway. nf-core/sarek 3.8.1 (test, Strelka) ran with every task sent to TESK:

  • 23 of 23 tasks COMPLETE;
  • the results match an all-local run: the same 170 files, and identical VCF records. Only the MultiQC reports differ, which embed run details.

On images without this change, none of these 23 tasks could run on TESK: each declares wildcard outputs.

Open questions

  • The tesk-api docs refer to this change for the version of tesk-core that path_prefix needs. Which release should they name?

Summary by Sourcery

Enable safe TES 1.1 wildcard output handling across filer uploads and taskmaster mounts.

New Features:

  • Support uploading TES 1.1 wildcard output matches for all URL schemes, preserving paths relative to path_prefix and including matched directories.
  • Mount wildcard outputs at the deepest non-wildcard directory so executors can produce their matches.

Bug Fixes:

  • Reject wildcard matches outside path_prefix, symbolic-link matches, and URL-incompatible names before uploading any files.

Enhancements:

  • Preserve TES 1.0 output behavior when path_prefix is absent and apply shell-compatible hidden-file matching and URL path escaping for wildcard outputs.

Documentation:

  • Document wildcard output handling, safety constraints, URL behavior, and mounting requirements.

Tests:

  • Add comprehensive unit coverage for wildcard matching, uploads, mounts, URL joining, optional outputs, safety checks, and legacy behavior.

@anuragxxd
anuragxxd requested a review from uniqueg as a code owner November 9, 2026 05:56
@sourcery-ai

sourcery-ai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Define wildcard detection and the deepest non-wildcard directory used as the mount root.

  • src/tesk_core/path.py L98-136

Uses of the API

Use the wildcard root for TES 1.1 outputs while preserving existing mounts for inputs and outputs without a path prefix, and reject patterns that would require mounting at the filesystem root.

  • src/tesk_core/taskmaster.py L32, L227-255, L280

Implementation

Expand prefixed wildcard outputs, validate every match before uploading, map matches beneath the destination URL, and copy file-scheme matches as concrete paths.

  • src/tesk_core/filer.py L33-39, L1132-1258, L1284-1292

Documentation

Explain TES 1.1 wildcard-output expansion, matching and safety behavior, mount requirements, and unchanged TES 1.0 behavior.

  • docs/filer.md L54-78, L85-86, L99

Tests

Cover wildcard recognition, mount-root selection, URL joining, uploads across schemes, optional and directory matches, safety failures, and legacy behavior.

  • tests/unit/test_filer_wildcards.py L1-383

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 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2a4f0ba) to head (3e2b7bb).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #134   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           10        10           
  Lines         1484      1556   +72     
=========================================
+ Hits          1484      1556   +72     

☔ 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.

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

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

## Individual Comments

### Comment 1
<location path="src/tesk_core/path.py" line_range="134" />
<code_context>
+        if hasWildcards(part):
+            break
+        root.append(part)
+    return "/" + "/".join(root) if root else ""
+
+
</code_context>
<issue_to_address>
**Root-level wildcard tasks cannot start**

When an output pattern has a wildcard in its first path component, such as `/*.txt`, `wildcardRoot` returns an empty path, which `dirname` passes to `append_mount` as a Kubernetes `mountPath`; Kubernetes rejects the mount and the task cannot start.

Make root-level patterns use a valid, nonempty mount root before `dirname` passes it to `append_mount`.

Also at `src/tesk_core/taskmaster.py:219`.
</issue_to_address>

### Comment 2
<location path="src/tesk_core/taskmaster.py" line_range="218-219" />
<code_context>
     """
-    if iodata["type"] == "FILE":
+    dirname: str
+    if hasWildcards(iodata["path"]):
+        dirname = wildcardRoot(iodata["path"])
+        logger.debug("dirname of pattern %s is: %s", iodata["path"], dirname)
+    elif iodata["type"] == "FILE":
</code_context>
<issue_to_address>
**Literal input paths mis-mount**

When an input filename or directory component contains `*`, `?`, or `[` as a literal character, `generate_mounts` also calls `dirname` for inputs, so an input path with a literal `*`, `?`, or `[` is treated as an output pattern and `wildcardRoot` mounts an ancestor instead of the input’s containing directory. The input is then attached at the wrong task path and is unavailable to the executor.

Apply wildcard-root mounting only to outputs; keep the existing directory calculation for inputs.
</issue_to_address>

### Comment 3
<location path="src/tesk_core/filer.py" line_range="1149" />
<code_context>
+        for part in relative.split("/"):
+            url = http_join(url, part)
+        return url
+    return url.rstrip("/") + "/" + relative
+
+
</code_context>
<issue_to_address>
**Matched files use wrong destination names**

When a wildcard matches a file or directory whose relative name contains `?` or `#`, and the destination uses a non-HTTP scheme, `url_join` appends the relative name raw, so `Transput` parses `?` as a query delimiter and `#` as a fragment; the transfer uses a truncated destination path and stores the output under the wrong name.

Percent-encode each relative path component before joining it to a non-HTTP destination URL.
</issue_to_address>

### Comment 4
<location path="src/tesk_core/filer.py" line_range="1193" />
<code_context>
+        relative = os.path.relpath(match, prefix).replace(os.sep, "/")
+        ftype = Type.Directory if os.path.isdir(match) else Type.File
+        try:
+            with trans(match, url_join(filedata["url"], relative), ftype) as transfer:
+                if transfer.upload(check_links=False):
+                    return 1
</code_context>
<issue_to_address>
**Nested file outputs fail to copy**

When a wildcard match has a nested relative path and its corresponding parent directory under the file URL does not exist, `FileTransput.upload_file` calls `copyFile` and `shutil.copy` without creating the destination parent directories, so the copy raises `FileNotFoundError` and the output fails.

Create the destination parent directories before copying a file to its joined URL path.
</issue_to_address>

### Comment 5
<location path="src/tesk_core/filer.py" line_range="1195" />
<code_context>
+                match,
+                filedata["path_prefix"],
+            )
+            return 1
+        if output_has_symlink(match, recursive=True):
+            return 1
</code_context>
<issue_to_address>
**Failed outputs leave partial uploads**

When a match upload fails after one or more earlier matches have succeeded, a later match’s transfer can fail after earlier matches have already been uploaded, and `upload_matches` returns failure without removing those objects. The output therefore remains partially visible at its destination even though the filer job failed.

Stage or track the uploaded destinations and remove them on failure, or otherwise ensure failed output sets are not exposed as complete.
</issue_to_address>

### Comment 6
<location path="src/tesk_core/filer.py" line_range="1172" />
<code_context>
+    pattern = filerPath(filedata["path"])
+    prefix = filerPath(filedata["path_prefix"])
+    parsed_url = urlparse(filedata["url"])
+    trans = newTransput(parsed_url.scheme or "file", parsed_url.netloc)
+    matches = sorted(glob(pattern))
+    if not matches:
</code_context>
<issue_to_address>
**Empty optional outputs fail**

When a `file:` wildcard output has no matches while the file protocol is disabled, `upload_matches` calls `newTransput` before checking the glob results, so `FileProtocolDisabled` is raised instead of taking the empty-match success path.

Check for matches before calling `newTransput`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 6 findings to address first, and if wildcard or prefix handling selects unintended files, the filer can send their contents to the output URL; those remote copies may remain after the change is reverted.

Blocking findings: src/tesk_core/path.py:134, src/tesk_core/taskmaster.py:219, src/tesk_core/filer.py:1149, src/tesk_core/filer.py:1193, src/tesk_core/filer.py:1195, and 1 more


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

Comment thread src/tesk_core/path.py Resolved
Comment thread src/tesk_core/taskmaster.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
@anuragxxd anuragxxd changed the title feat(filer): upload the matches of outputs with wildcards feat(filer): upload wildcard output matches Nov 9, 2026
Outputs whose path has wildcards (*, ?, [) and a path_prefix, as in TES
1.1, are expanded in the filer for every scheme, not only file: URLs.
Each match goes to the output's URL plus its path below path_prefix; a
pattern that matches nothing uploads nothing and succeeds. Matches that
are or contain symbolic links, or that aren't below path_prefix, fail
the output before anything is uploaded.

The taskmaster mounts such an output at the pattern's deepest directory
without wildcards, instead of at a path with wildcards in it.
@anuragxxd
anuragxxd force-pushed the feat/wildcard-outputs branch from 113f570 to ab22e84 Compare November 9, 2026 06:47
Comment thread src/tesk_core/path.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/filer.py Resolved
Comment thread src/tesk_core/taskmaster.py Resolved

@uniqueg uniqueg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, Anurag, this is a nice piece of work, and the sarek run is convincing. Checking every match before uploading anything, and the realpath check against path_prefix, are exactly right.

Two things I'd like fixed before merging, both small:

  1. Patterns with a wildcard in the first component (/*.txt) get an empty mount path (Sourcery's thread on path.py), so the job is rejected by Kubernetes rather than with a clear message. I'd refuse those, in tesk-api with a 400 or here with a clear error.
  2. file: URLs with path_prefix go through FileTransput.upload_file → copyFile, which doesn't create the destination's parent directory (nested matches raise FileNotFoundError), and which globs the matched path again (a match named out[1].txt copies nothing, but still returns 0). A plain copy with makedirs for matches would fix both. A file: test would cover it, as the current tests are S3 only.

Smaller points inline. Could you reply to the Sourcery threads too? Some of them are fine to decline with a reason (partial uploads, file protocol disabled).

- Refuse patterns with wildcards in their first component (/*.txt): they
  would need a mount at /, and got an empty mountPath, which Kubernetes
  rejects.
- Only outputs with path_prefix get the pattern's root as their mount;
  inputs and TES 1.0 outputs are mounted as before, so a literal [ in
  their names keeps its meaning.
- file: matches are copied as concrete paths, creating the directories
  below the URL: nested matches no longer raise FileNotFoundError, and a
  match whose name has [ is no longer globbed again (and skipped).
- A match whose name has # or ? fails the output for non-HTTP URLs, whose
  paths the transfers read as they are, instead of being stored under a
  shorter name.
- A pattern that matches nothing succeeds before a transfer is created,
  also when file: is disabled.
@anuragxxd

Copy link
Copy Markdown
Member Author

Thanks for the review, @uniqueg. Both requested changes are in 3e2b7bb, as are your optional points, and every thread has a reply:

  1. Root-level patterns (/*.txt) are refused with a clear error in the taskmaster before anything is created. tesk-api#133 now rejects them with a 400 as well.
  2. file: matches are copied as concrete paths, and the directories below the URL are created. New file: tests cover nested matches, names with [, and matched directories.
  3. Optional points:
    • wildcard-root mounts apply only to outputs with path_prefix;
    • a pattern with no matches succeeds before any transfer is created;
    • names with # or ? fail the output for non-HTTP URLs. I didn't percent-encode them: those transfers don't unquote, so the reason is in the thread.
  4. Partial uploads: I declined the Sourcery suggestion, with the reason in its thread.

Checks: 702 tests pass with 100% coverage, and ruff, mypy and the strict docs build are clean.

@anuragxxd
anuragxxd requested a review from uniqueg November 10, 2026 15:49
@uniqueg
uniqueg merged commit ddacc96 into dev Nov 10, 2026
33 checks passed
@uniqueg
uniqueg deleted the feat/wildcard-outputs branch November 10, 2026 19:07
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.

2 participants