Repository navigation
test: add app test harness and fix the tests - #236
Merged
Merged
Conversation
Mirror the package in `tests/` and replace the tests that could not be collected (`tests/unitTest`) and the integration tests against public TES instances (`tests/test_integration`): - conftest: real MongoDB via `MONGODB_TEST_URI` (databases dropped per test, refused if present), no network access except to it, no name resolution in the distance-based middleware - TES endpoints with fake backends: relay, fallback to the next backend, failures, Funnel, views, cancellation - task as received stored once and never changed (#142) - Celery task: states, polling, retries, failures (#149) - middleware handler and task distribution middlewares (#168) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Run all tests in CI (no ignored directories), on Python 3.10 and 3.12, and against MongoDB 7.0 (`MONGODB_TEST_URI`), with a stable "Run tests" check, as in cloud-registry. Replace the integration tests against public TES instances with a Compose smoke test: a Compose override and config overlay (`tests/smoke/`) relay tasks to a fake TES backend, and the job checks that a task is relayed to it and tracked by the Celery worker until it is complete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review fixes: the Compose smoke checks move from the workflow to `tests/smoke/check.sh`, which also runs locally; the network guard of the tests also covers `socket.connect_ex()`; the docs describe the test layout and the network guard, and require a standalone MongoDB for `MONGODB_TEST_URI`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe PR replaces legacy and externally dependent tests with an app-centered, deterministic harness, substantially broadens endpoint, middleware, and Celery coverage, and updates CI and documentation to validate both mongomock/MongoDB test runs and a local fake-TES Compose deployment. Sequence diagram for task relay and tracking smoke testsequenceDiagram
participant Check as Smoke check
participant App as proTES API
participant Queue as RabbitMQ
participant Worker as Celery worker
participant TES as Fake TES backend
Check->>App: POST /tasks
App->>TES: Create task
TES-->>App: Task response
App->>Queue: Submit tracking task
App-->>Check: Task ID
Queue->>Worker: Track task progress
Worker->>TES: Get task
TES-->>Worker: COMPLETE
Worker->>App: Store task state
Check->>App: GET /tasks/{id}
App-->>Check: COMPLETE task
Flow diagram for deterministic test harness database selectionflowchart TD
Start[Test execution] --> URI{MONGODB_TEST_URI set?}
URI -->|No| Mock[mongomock in-memory database]
URI -->|Yes| Mongo[Standalone MongoDB test database]
Mock --> Reset[Reset taskStore and protes before each test]
Mongo --> Reset
Reset --> Guard[Block network access except test database]
Guard --> Tests[Run app, endpoint, middleware, and Celery tests]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
The middlewares of the config are lists of alternatives; the Celery worker refused the flat list of the smoke test overlay. A test now validates the overlay with the app. Co-Authored-By: Claude Opus 5.5 <[email protected]>
uniqueg
marked this pull request as ready for review
October 22, 2026 21:31
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/conftest.py" line_range="39" />
<code_context>
+# Database set via environment variable `MONGO_DBNAME` in tests
+OTHER_DB = "protes"
+# Databases that the tests use, and drop
+DBS = (DB, OTHER_DB)
+# URI of a MongoDB to test against instead of mongomock (see above)
+MONGODB_TEST_URI = os.environ.get("MONGODB_TEST_URI", "")
</code_context>
<issue_to_address>
**Test database escapes cleanup**
When `MONGODB_TEST_URI` is set and `MONGO_DBNAME` names a database outside `taskStore` and `protes`, `_check_no_db` and the cleanup loops use only `DBS`, so the app can read or modify that database and tests leave its data mixed with existing data.
Include the configured `MONGO_DBNAME` in the database safety checks and cleanup.
</issue_to_address>
### Comment 2
<location path="tests/conftest.py" line_range="134-138" />
<code_context>
+
+
[email protected](autouse=True)
+def no_network(monkeypatch: pytest.MonkeyPatch) -> None:
+ """Block network access of all tests, except to the test database."""
+ monkeypatch.setattr(socket.socket, "connect", _no_network)
+ monkeypatch.setattr(socket.socket, "connect_ex", _no_network_ex)
+ monkeypatch.setattr(distance, "gethostbyname", _no_name_resolution)
+
+
</code_context>
<issue_to_address>
**Network traffic escapes test isolation**
When a test or dependency resolves an external hostname through the system resolver or sends UDP traffic, `no_network` patches TCP connection methods and the distance middleware’s resolver, but leaves system DNS resolution and UDP `sendto` unblocked, so DNS queries or datagrams reach external hosts despite the harness’s no-network guarantee.
Block system DNS resolution and UDP sends as well, and add tests that verify both paths are blocked.
Also at `tests/test_fixtures.py:79`.
</issue_to_address>
### Comment 3
<location path="tests/ga4gh/tes/test_server.py" line_range="17" />
<code_context>
+from pro_tes.ga4gh.tes.models import TesTask
+from pro_tes.tasks import track_task_progress
+from pro_tes.utils.misc import get_custom_config
+from tests.conftest import DB
+
+BASE_PATH = "/ga4gh/tes/v1"
</code_context>
<issue_to_address>
**Test imports resolve elsewhere**
When a regular top-level `tests` package appears earlier in import resolution, the local `tests` directory has no `__init__.py`, so `from tests.conftest import DB` resolves to the other package and pytest fails to collect the test.
Make the local `tests` package unambiguous, for example by adding `tests/__init__.py`.
Also at `tests/tasks/test_track_task_progress.py:18`, `tests/test_fixtures.py:15-16`.
</issue_to_address>
### Comment 4
<location path="docs/development.md" line_range="31-32" />
<code_context>
+
+```bash
+docker run -d --rm --name mongodb-test -p 127.0.0.1:27017:27017 mongo:7.0
+MONGODB_TEST_URI=mongodb://localhost:27017 pytest
+docker stop mongodb-test
+```
+
</code_context>
<issue_to_address>
**MongoDB example races startup**
When mongoDB takes longer than five seconds to become ready, `pytest` begins immediately after `docker run -d`, while the container can still be initializing. The `_mongodb` fixture’s five-second server-selection timeout then expires, so the documented local MongoDB test command fails on a slow startup.
Wait for MongoDB’s ping health check to succeed before invoking pytest.
</issue_to_address>Sourcery assessment
Approval pending. 4 findings to address first.
Blocking findings: tests/conftest.py:39, tests/conftest.py:138, tests/ga4gh/tes/test_server.py:17, docs/development.md:32
Apps created in tests would use the database named by `MONGO_DBNAME` of the environment, which the tests neither check nor drop. The docs wait for the local test MongoDB to be ready before running the tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rebuilds the test suite on an app test harness, as in cloud-registry (elixir-cloud-aai/cloud-registry#90, elixir-cloud-aai/cloud-registry#164), and replaces the CI integration tests against public TES instances with a Compose smoke test against a local fake TES backend (S14 of the migration plan).
tests/mirrorspro_tes/(ga4gh/tes/,tasks/,middleware/,plugins/…,utils/); the uncollectabletests/unitTest(fix: unit tests #168) andtests/test_integrationare removed, withpytest-orderingand the ruff/mypy excludes.tests/conftest.py): mongomock by default, a real MongoDB ifMONGODB_TEST_URIis set (databasestaskStoreandprotesdropped before each test, refused if present); network access blocked except to the test database (connect,connect_ex), and no name resolution in the distance-based middleware.tests/test_fixtures.pytests the harness.tests/ga4gh/tes/test_server.py) with fake backends: relay, fallback to the next backend (invalid URL, rejected task), no backend (500,SYSTEM_ERROR), backend that doesn't serve the task yet, Funnel, invalid tasks, views, not found, cancellation (also of finished tasks and of legacy nested forwards).MONGO_DBNAME), client URL and credentials, state changes and polling interval, retries, attempts exceeded, backend unavailable, missing logs, missing document.strip_auth,get_custom_config.test(Python 3.10, 3.12),test_mongodb(MongoDB 7.0 service) and the stable aggregate check "Run tests" (tests_passed), as in cloud-registry;smoke_testrunsdocker compose up --waitwithtests/smoke/compose.yaml(fake TES in the app image, config overlay with only that backend and random distribution) andtests/smoke/check.sh(task relayed, tracked by the Celery worker via RabbitMQ toCOMPLETE, listing, cancel, 404, the fake backend got it).publishnow needs these jobs. No test or CI job contacts external TES instances.docs/development.md(running the tests, against MongoDB, and the smoke test locally).App bugs found on the way are left to #208 (next in the stack) or listed below; the tests here avoid asserting the buggy behaviour.
Closes #207
Closes #142
Closes #149
Closes #168
How it was verified
pytest: 118 passed (mongomock, Python 3.12);MONGODB_TEST_URI=mongodb://127.0.0.1:27391 pytestagainst a local MongoDB 7.0: 117 passed (before the last test was added), onlyadmin/config/localleft afterwards.ruff format --check,ruff check,mypy,ast-grep scan,ast-grep test, semgrep (.semgrep), actionlint: clean.tests/smoke/fake_tes.pydriven with py-tes locally (service info, create, get, list, cancel). The Compose smoke test itself only runs in CI (docker runis not available locally);docker compose configwith the override checked.middlewareslist of the smoke overlay, which the Celery worker rejected; fixed, with a test that validates the overlay with the app).Declined review findings
fail_underand the Codecov upload in thetestjob (as in the template): that is test: enforce 100% coverage #159, next but one in the stack; tests of the error branches ofpro_tes/utils/db.pyandapp.pyare left to it too.conftest.py, as in the template.connect/connect_exandgethostbynamein the distance middleware cover the connections and lookups the tests make (reasons in the thread).tests/__init__.py: it exists already.Follow-ups (found while writing the tests)
GET /taskspaging (B2);name_prefixregex (S5); timestamps (B3);BASICview projects the wrong paths (task.system_logs,task.logs.stdout);storeLogs.execution_trace: Falsestores a metadata dict that cancellation can't read.UNKNOWNuntil the Celery worker updates it); the unique index oftasksis ontask_id/worker_id, but the field istask.id, so duplicate generated task IDs are never detected.🤖 Generated with Claude Code