test(integration): add real-NATS pytest fixture (#173)#519
Merged
Conversation
Adds a session-scoped pytest fixture that spins up a real `nats-server` process with JetStream enabled on an ephemeral port, plus one integration test that exercises `jetstream-consumer` end-to-end: publish synthetic hi.tasks.completed / hi.agents.created events, run subscribe_loop in a background thread, and assert that _render_metrics() reflects the consumed events and computed task latency. Mirrors ProjectScylla's tests/integration/nats/conftest.py shape and Charybdis's REQUIRES_NATS ctest gate: the module is skipped when either `nats-server` is not on PATH or `nats-py` is not installed, so existing CI (which lacks both) stays green and the test only fires on machines provisioned for integration runs. Registers `integration` and `requires_nats` pytest markers in pyproject.toml so `--strict-markers` accepts them. Closes #173 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
nats_urlpytest fixture that starts a realnats-serverprocess with JetStream on an ephemeral port (mirrors ProjectScylla'stests/integration/nats/conftest.py).test_subscribe_loop_records_published_eventsthat runs the jetstream-consumersubscribe_loopagainst the live server, publishes synthetichi.tasks.completed/hi.agents.createdevents, and asserts the rendered/metricsoutput reflects counts, the_connected=1gauge, and the computed task-latency value.integrationandrequires_natspytest markers inpyproject.tomlso--strict-markersaccepts them. Therequires_natsmarker mirrors Charybdis'sREQUIRES_NATSctest gate.nats-serveris not on PATH ornats-pyis not installed, so existing CI (which lacks both) stays green and the test only fires on machines provisioned for integration runs.Closes #173
Test plan
pytest tests/passes locally with 320 tests + 1 new integration test, exporter coverage 99.40%.env -i PATH=/usr/bin:/bin python3 -m pytest tests/integration/reports1 skippedwhennats-serveris removed from PATH.ruff check exporter/ tests/clean.Follow-up from #4.
Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com