Repository navigation
test(tes/data/crypt4gh): add an end-to-end test - #76
Conversation
Run tes.data.crypt4gh end to end against a real TES backend: e2e/check.sh starts proTES 0.6.0 (its release image, with the plugin's wheel built from the checkout) and Funnel 0.11.14 in Docker Compose, and sends tasks whose Crypt4GH file and secret key are served over HTTP. It checks that a task completes with the decrypted content and an empty volume after the teardown, that a failing decryption fails the task without decrypted files, that a failing executor stops the task before the teardown by default, and that the teardown runs after it with teardown_on_error. CI runs it in the new job e2e (End-to-end test) when the plugin is affected; the gate allows the skip otherwise. Dependabot covers the test's images. The plugin README, the contributing guide and the changelog describe it; the README now says that Funnel 0.11.14 ends such tasks with EXECUTOR_ERROR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
From the review of the end-to-end test: - Name the Compose project after E2E_PORT and remove only the task containers with mounts in this run's work directory, so that runs with different ports and work directories don't interfere. - Refuse a work directory that the test didn't create (marker file), and paths such as // or /.; empty it with find in a container. - Keep the cleanup going after errors (set +e in the EXIT trap). - Exit with status 2 before starting anything if a tool is missing. - Fail if the volume can't be listed, instead of counting it as empty. - Accept COMPLETE as well as EXECUTOR_ERROR with teardown_on_error, as the final state is the backend's; assert the decryption executor's arguments for the failing decryption. - Share one helper for requests in the Compose network. - Docs: point to the pinned versions instead of naming them, re-wrap the README, describe the new behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
From the second review round: - Strip trailing slashes from E2E_WORK_DIR and refuse paths with ':', symbolic links and directories of other users. - Match task containers by mount sources that start with the work directory, from captured output (no grep -q with pipefail). - Docs: runs side by side only from the same checkout, as the image tags are shared; status 2 also for a bad work directory; which images Dependabot updates. Drop the changelog entry that documented unreleased behaviour. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Reviewer's GuideConfigurationConfigure dependency updates for the e2e images and add the CI job and gate logic that runs the test when the Crypt4GH plugin is affected.
Define the Compose stack, pinned service images, Funnel settings, proTES overlays, and Docker build contexts used by the e2e test.
DocumentationDocument how to run and configure the e2e test, its behavior and backend limitations, and clarify Funnel’s teardown-on-error task state.
TestsImplement the end-to-end test that builds inputs, drives tasks through proTES and Funnel, checks outcomes and cleanup, and provides the test identity and file services.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Documentation build overview
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #76 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 10 10
Lines 886 886
Branches 125 125
=========================================
Hits 886 886
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 5fdc19e #68 test(tes/data/crypt4gh): run end to end with TES · 2 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="plugins/tes/data/crypt4gh/e2e/compose.yaml" line_range="91" />
<code_context>
+ volumes:
+ - ./funnel.yaml:/etc/funnel.yaml:ro
+ - ${E2E_WORK_DIR:?}/funnel:${E2E_WORK_DIR:?}/funnel
+ - /var/run/docker.sock:/var/run/docker.sock
+ healthcheck:
+ test: ["CMD", "/app/funnel", "task", "list", "--server", "http://localhost:8000"]
</code_context>
<issue_to_address>
**Unauthenticated users can submit tasks**
When an unprivileged process on a Linux host can reach the Compose bridge address while the test stack is running, a caller can bypass proTES authentication and submit arbitrary TES tasks directly to Funnel's HTTP API; Funnel runs task executors as root with access to the Docker socket, giving that caller control over workloads in the test stack.
Require authentication for Funnel's HTTP API or isolate and firewall the stack so untrusted host processes cannot reach it.
Also at `plugins/tes/data/crypt4gh/e2e/funnel.yaml:16`.
</issue_to_address>
### Comment 2
<location path="plugins/tes/data/crypt4gh/e2e/check.sh" line_range="74" />
<code_context>
+ echo "E2E_WORK_DIR must not contain ':', not ${E2E_WORK_DIR}" >&2
+ exit 2
+ ;;
+ /*[!/.]*) ;;
+ *)
+ echo "E2E_WORK_DIR must be an absolute path below /, not ${E2E_WORK_DIR}" >&2
</code_context>
<issue_to_address>
**Unrelated `/tmp` contents are erased**
When `E2E_WORK_DIR` is set to a path such as `/tmp/not-yet-created/..`, the path glob accepts this spelling, and the existing-path guard skips it because the leading component is missing. `mkdir -p` then creates that component and resolves the work directory to `/tmp`; cleanup mounts `/tmp` and `find /work -mindepth 1 -delete` erases its contents.
Canonicalize the work-directory path and reject paths containing `..` components or resolving to an unsafe ancestor before creating anything.
</issue_to_address>
### Comment 3
<location path="plugins/tes/data/crypt4gh/e2e/check.sh" line_range="111-112" />
<code_context>
+remove_work_dir() {
+ if [[ -f "${marker}" ]]; then
+ docker run --rm -v "${E2E_WORK_DIR}:/work" "${image}" \
+ find /work -mindepth 1 -delete || true
+ rm -rf "${E2E_WORK_DIR}" || true
+ fi
+}
</code_context>
<issue_to_address>
**Nested runs delete each other**
When two runs use different ports but one run’s `E2E_WORK_DIR` is nested inside the other’s, the outer run’s `remove_work_dir` recursively empties and removes its work directory, including a nested run’s directory; its `task_containers` prefix match also selects the nested run’s containers. The inner run loses its files and containers and fails.
Canonicalize work-directory paths and refuse overlapping paths, or isolate cleanup and container selection with a per-run identity.
Also at `plugins/tes/data/crypt4gh/e2e/check.sh:124`.
</issue_to_address>
### Comment 4
<location path="plugins/tes/data/crypt4gh/e2e/compose.yaml" line_range="55" />
<code_context>
+ condition: service_healthy
+ rabbitmq:
+ condition: service_healthy
+ services:
+ condition: service_healthy
+
</code_context>
<issue_to_address>
**Use MinIO for inputs**
The issue asks for MinIO as the object storage in the end-to-end test. This change serves inputs through the `services` HTTP file server instead.
</issue_to_address>
### Comment 5
<location path="plugins/tes/data/crypt4gh/e2e/check.sh" line_range="137" />
<code_context>
+ if [[ "${status}" != 0 ]]; then
+ docker compose logs --no-color protes protes-worker funnel
+ fi
+ docker compose down --volumes --remove-orphans
+ task_containers | xargs -r docker rm -f
+ remove_work_dir
</code_context>
<issue_to_address>
**Cleanup failures still pass**
When a cleanup command fails after all test checks passed, `set +e` lets cleanup continue after `docker compose down` fails, and `remove_work_dir` suppresses its cleanup errors with `|| true`; the trap then exits with the original status 0, so the test reports success while resources remain.
Record and report cleanup failures, and return a failure status when the test passed but cleanup did not.
Also at `plugins/tes/data/crypt4gh/e2e/check.sh:112`.
</issue_to_address>Sourcery assessment
Approval pending. 5 findings to address first.
Blocking findings: plugins/tes/data/crypt4gh/e2e/compose.yaml:91, plugins/tes/data/crypt4gh/e2e/check.sh:74, plugins/tes/data/crypt4gh/e2e/check.sh:112, plugins/tes/data/crypt4gh/e2e/compose.yaml:55, plugins/tes/data/crypt4gh/e2e/check.sh:137
From Sourcery's review: - Put the services on an internal Compose network, so that the host can't reach Funnel's API, which has no authentication; only proTES is on a second network, for its published port. - Refuse work directories that aren't normalized paths (e.g. /tmp/x/..), and ones inside the work directory of another run. - Fail a passed test if its cleanup leaves something behind. - Contributing guide: describe the network and the work directory rules. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Adds an end-to-end test of
tes.data.crypt4ghagainst a real TES backend (plugins/tes/data/crypt4gh/e2e/).compose.yaml): proTES 0.6.0 (the release image by digest, with the plugin's wheel built from the checkout,Dockerfile.protes), its Celery worker, MongoDB, RabbitMQ, and Funnel 0.11.14 (Dockerfile.funnel,funnel.yaml). Funnel runs the executors as sibling containers through the Docker socket, as in proTES'sIntegrationjob. It keeps the work directories (LeaveWorkDir), so the test can look at the volume on the host.services.pyis a small OIDC identity provider for proTES (proTES needs tokens) and a file server for the task inputs.crypt4ghtools, so the repository holds no keys. They are served over HTTP, and Funnel downloads them by URL. The decryption image is built from the checkout asfoca-plugin-tes-data-crypt4gh-decrypt:e2e. Funnel's pull of it fails, and Funnel then runs the local image.check.sh):--clearteardown last, and the task's executor (cat /in/hello.txt.c4gh, rewritten to/vol/crypt4gh/hello.txt) prints the decrypted content. The volume is empty afterwards.EXECUTOR_ERRORafter the decryption executor, and the volume is empty.teardown_on_error), a failing task executor stops the task before the teardown, so the decrypted file stays in the volume. This is the documented limit.config-on-error.yaml(teardown_on_error: true). The failing executor getsignore_error: true, the teardown still runs (exit 0), and the volume is empty.e2e("End-to-end test"). It runs when the plugin is affected (jobchanges) and is in the gate'sneeds. The gate allows the skip only when the plugin isn't affected. It needs no credentials, so it runs the same for pull requests from forks: nothing has to be skipped.dockeranddocker-composeentries for the e2e directory. Major updates of the compose images are left out, as in proTES (MongoDB 8).E2E_PORT.:in its path. Paths such as//are refused.teardown_on_erroris the backend's, soEXECUTOR_ERRORandCOMPLETEboth pass. The executor logs and the volume decide the result.teardown_on_errornote. Funnel 0.11.14 ends such tasks withEXECUTOR_ERROReven though the teardown ran. The README saidCOMPLETE, which is what the current Funnel sources do.Scope notes
ignore_error: true(400), soteardown_on_erroris tested with Funnel only, and there is no TESK variant.Integrationjob, this job is a required part of the gate. It is the plugin's only test against a backend and runs only for changes that affect the plugin. If the public registries (Docker Hub, quay.io, ghcr.io) are down, those PRs wait.Closes #68
Verification
plugins/tes/data/crypt4gh/e2e/check.sh(locally, withE2E_WORK_DIRin the clone): passed 4 times, the last run after both review rounds, withE2E_PORT=18081and a trailing slash onE2E_WORK_DIR. Each time, the stack, the task containers and the work directory were removed afterwards.//,/.,/tmp/a:b, an existing directory without the marker, and a symbolic link.teardown: falseinconfig.yaml, and the executor check relaxed so the run reaches the volume check: failed as expected withThe teardown left files: hello.txt.pre-commit run --all-files(ruff, mypy, semgrep, gitleaks, actionlint, ast-grep, package conventions): passed.check.sh: clean (two intentional SC2016 disabled inline, with reasons).coverage run --source scripts,docs -m pytest tests: 142 passed, 100%. Plugin tests: 130 passed, 100%.mkdocs build --strict: OK.End-to-end test(1m51s on the hosted runner),Smoke testandCI passed. They passed again after the Sourcery fixes (5fdc19e): 96 of 96, includingSourcery review./tmp/not-yet-created/..,/tmp/a/./b,/tmp//aand a directory inside another run's work directory.Automated review
Sourcery opened 5 threads. All were answered and resolved:
..path could empty/tmp: only normalized paths are accepted now.Declined review findings
Two rounds each of adversarial and quality review. All high and medium findings, and the cheap low ones, were fixed. Declined:
buildblock of theservicesservice incompose.yaml(low): each service stays self-contained, so that it can be started on its own. Compose builds the shared tag once perup.catwould fail loudly, not pass vacuously.imagesetting in the proTES overlay, which isn't worth it for a test that CI runs on fresh runners./tmpis open to a symlink swap by another local user between check and use (low): symbolic links and directories of other users are now refused. The remaining race window only matters on shared multi-user hosts. CI runners are single-user, andE2E_WORK_DIRcan point elsewhere.Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV