Skip to content
63 changes: 57 additions & 6 deletions integration_tests/regression/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
"""Shared fixtures for ``integration_tests/regression/``.

This directory hosts two orthogonal regression tiers:

This directory hosts three orthogonal regression tiers:

* **Message store + event bus routing** (issue #2640) — exercises the
load-bearing seams between the orchestrator's Flask blueprints, the
inter-agent message store (in-memory + Redis Streams), and the
in-process ``EventBus``. Real ``Flask`` blueprint and real
``EventBus`` so the routing path under test is the same one
production runs. Dual-backend parametrization mirrors the AC pattern
from ``orchestrator/tests/test_pipelines_status_wait_route.py``:
every test that touches the message store runs against both
``MessageStore`` (in-memory) and ``RedisMessageStore`` backed by
``fakeredis.FakeRedis`` so a regression in either backend surfaces.
* **BRC consensus** (issue #2635): exercises ``PeerConsensusTracker``
and the timeout-handler entry points in-process. These tests do
NOT require k3s — they drive the orchestrator's Python API at the
Expand All @@ -13,9 +23,12 @@
invariants we've regressed historically (slice spawn env threading
from #2428, slice restart branch ref from the #2410/#2428 follow-ups).

Both tiers are marked ``integration`` and run under
All three tiers are marked ``integration`` (via module-level
``pytestmark`` in each test file) and run under
``make test-integration``. The k3s fixtures only fire when a test
takes the ``spawner`` / ``egg_stack`` fixtures; the BRC fixtures are
takes the ``spawner`` / ``egg_stack`` fixtures; the message-bus tests
use ``fakeredis`` and ``unittest.mock.patch`` for the pipeline
state-store and the inner context-PR hook; the BRC fixtures are
either autouse (tracker registry) or opt-in.

The k3s fixtures intentionally pick spawn parameters that do NOT
Expand Down Expand Up @@ -43,8 +56,10 @@
from pathlib import Path
from typing import Any

# Make sibling ``_helpers.py`` and the orchestrator/shared trees
# importable before any conftest-level imports below land.
# sys.path setup: include _REGRESSION_DIR so ``_helpers`` is importable,
# plus orchestrator + shared + project root so test modules can import
# the orchestrator's internal modules (events, message_store,
# redis_message_store, routes.pipelines, peer_consensus, review_graph).
_REGRESSION_DIR = Path(__file__).resolve().parent
_PROJECT_ROOT = _REGRESSION_DIR.parent.parent
for _p in (
Expand All @@ -63,6 +78,42 @@
from peer_consensus import _trackers_lock as _global_trackers_lock # noqa: E402
from review_graph import ReviewCriticality, ReviewEdge, ReviewGraph # noqa: E402

# ---------------------------------------------------------------------------
# Message-bus routing fixtures (#2640)
# ---------------------------------------------------------------------------

# Lifecycle-secret-gated routes (PATCH /pipelines/<id>, DELETE
# /pipelines/<id>, signals, etc.) require ``EGG_LIFECYCLE_SECRET`` to be
# set + ``Authorization: Bearer <secret>`` on the request. The
# orchestrator's own test suite sets this session-wide via
# ``orchestrator/tests/conftest.py`` with a different secret value
# (``test-lifecycle-secret-egg1769``). A session-scoped autouse fixture
# here would race that one in a mixed-tree pytest session: whichever
# fired second would overwrite the env, and the FlaskClient.open
# monkey-patch in the other tree would then inject a header that no
# longer matches the env-read secret on the server side. Function-scoped
# (via ``monkeypatch``) keeps the override strictly local to each
# regression test and restores cleanly, so the orchestrator's
# session-scoped value (if also in the session) is what other trees see.
_TEST_LIFECYCLE_SECRET = "test-lifecycle-secret-regression"


@pytest.fixture(autouse=True)
def _set_lifecycle_secret_env(monkeypatch):
"""Set ``EGG_LIFECYCLE_SECRET`` per regression test (function-scoped).

See the module-level comment for why this is function-scoped rather
than session-scoped.
"""
monkeypatch.setenv("EGG_LIFECYCLE_SECRET", _TEST_LIFECYCLE_SECRET)


@pytest.fixture
def lifecycle_auth_headers() -> dict[str, str]:
"""Valid ``Authorization`` header for lifecycle-control endpoints."""
return {"Authorization": f"Bearer {_TEST_LIFECYCLE_SECRET}"}


# ---------------------------------------------------------------------------
# k3s slice-spawn helpers (#2632)
# ---------------------------------------------------------------------------
Expand Down
Loading
Loading