Files
gps-denied-onboard/e2e/runner/conftest.py
T
Oleksandr Bezdieniezhnykh 6599d828d2 [AZ-407] [AZ-444] [AZ-445] Batch 68: fixtures, Tier-2 harness, NFR reporter
Three blackbox-harness tasks landed together — all depend only on
AZ-406 and unblock the FT-* / NFT-* scenario tasks scheduled for
batches 69+.

AZ-407 — Static fixture builders (3pt):
  * tile-cache-builder/{builder.py, Dockerfile, build.sh} produces a
    deterministic tile-cache-fixture Docker volume from
    _docs/00_problem/input_data/. Reproducibility primitives: sorted
    iteration, frozen PIL JPEG settings, FAISS HNSW32 built single-
    threaded with seeded stub descriptors.
  * age-injector/{age_injector.py, inject.sh} clones the volume and
    shifts capture_date by N×30.44 days; tile JPEG bytes preserved
    bit-identical. Emits synth-age-7mo + synth-age-13mo volumes.
  * cold-boot/cold_boot_fixture.json: frozen FC pose snapshot at
    Derkachi sector centre, schema v1.
  * secrets/mavlink-test-passkey.txt: 64-hex with required
    `# TEST ONLY` header line per AC-5. Passkey-equality test now
    compares the secret line after stripping the header.
  * security/cve-2025-53644.jpg: synthetic 158-byte malformed JPEG
    (truncated SOS marker). OpenCV 4.11.x rejects gracefully with
    imdecode → None. AZ-439 will sharpen for ASan instrumentation.
  * Top-level Makefile with `make fixtures` / `make fixtures-*` /
    `make e2e-tier1*` / `make unit-tests` targets.

AZ-444 — Tier-2 Jetson harness wrapper (5pt):
  * run-tier2.sh rewritten as orchestrator. Detects local
    (aarch64 + TIER2_HOST=localhost) vs remote (ssh into TIER2_HOST).
    New flags: -k/--selector, --build-kind production|asan,
    --reflash (gated behind TIER2_REFLASH_ACK=1 two-key gate),
    --dry-run.
  * tier2-on-jetson.sh (new) — on-device delegate. Verifies
    gps-denied-onboard{,-asan}.service health; restarts with 5s
    tolerance; spawns tegrastats + jtop parallel samplers; tails
    ASan unit's journal in asan mode; drives docker compose with
    TIER=tier2-jetson; forwards SELECTOR to pytest -k.
  * docker/run-tier1.sh (new) — selector-parity sibling.
  * AC-1 (selector parity) and AC-6 (reflash gating) unit-tested via
    --dry-run output assertions. AC-2/AC-3/AC-4/AC-5 are hardware-
    loop ACs verified by the Tier-2 runtime smoke (no Jetson in the
    unit-test layer).

AZ-445 — CSV reporter + evidence bundler refinements (2pt):
  * reporting/nfr_recorder.py (new) — pytest plugin. Provides the
    `nfr_recorder` fixture with record_metric(name, value, ac_id)
    and partial(ac_id, reason). At session end emits:
      - per-nfr/<scenario_id>.json (AC-1)
      - traceability-status.json with every AC ID parsed from
        traceability-matrix.md, classified Covered/PARTIAL/NOT
        COVERED with source scenario IDs (AC-2)
      - regression-baseline.json with all numeric metrics (AC-3)
  * csv_reporter.py extended — `_outcome_to_result` consults the
    aggregator; rows flip PASS → PARTIAL when an AC was marked
    PARTIAL by nfr_recorder (AC-4). Graceful fallback when
    aggregator isn't registered (unit-test contexts).
  * conftest.py registers nfr_recorder in pytest_plugins.
  * New --traceability-matrix CLI flag seeds the NOT COVERED rows.

Build / config:
  * pyproject.toml dev extras: added Pillow>=10.4,<13.0 for the
    tile-cache-builder unit test (broad enough to keep torchvision's
    Pillow 12 pin happy; the production builder runs inside its own
    Docker image with its own pin).
  * Updated test_directory_layout.py to cover 10 new files + replaced
    the byte-equal passkey assertion with the header-stripping
    variant.

Test results:
  * 157 focused tests pass (was 97 in batch 67; +60 new across this
    batch). No regressions.

Module-layout / spec drift:
  * AZ-407 spec text says `tests/fixtures/...`; module-layout
    blackbox_tests entry (commit d7a17a8) authoritatively places the
    harness under `e2e/`. Implementation followed the layout entry.
  * AZ-444 spec mentions `e2e/tier2/run-tier2.sh`; AZ-406 placed it
    at `e2e/jetson/run-tier2.sh`. Kept at `e2e/jetson/` for
    consistency.
  * Cold-boot README ownership: corrected from AZ-419 to AZ-407 per
    AZ-419's own Dependencies field.

Specs archived to _docs/02_tasks/done/. Jira tickets transitioned to
In Testing on commit.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-16 17:18:01 +03:00

216 lines
8.4 KiB
Python

"""Top-level pytest conftest for the blackbox e2e harness.
Responsibilities:
1. Session-level parameterization over ``(fc_adapter, vio_strategy)``.
2. Skip-rule enforcement per the traceability matrix
(`_docs/02_document/tests/traceability-matrix.md`):
- AC-7.1, AC-7.2 → SKIP (deferred — no AI-camera fixture)
- RESTRICT-CAM-2 → SKIP (paired with AC-7.x)
- AC-NEW-5 chamber portion → SKIP unless --enable-chamber
- RESTRICT-HW-2 chamber portion → SKIP unless --enable-chamber
- Tier-2-only tests → SKIP on tier1-docker
- `vins_mono` parametrization → SKIP on production-build sessions
3. Wiring of the boundary-driving fixtures (`sitl_observer`,
`mavproxy_tlog`, `fdr_reader`, `mock_suite_sat_client`) consumed by
per-scenario tests.
The actual boundary-driving fixtures import helper modules from
``runner.helpers.*``. They are registered here but their implementations
live in the helpers package.
"""
from __future__ import annotations
import os
from collections.abc import Iterator
from pathlib import Path
import pytest
# ---------------------------------------------------------------------------
# Command-line options
# ---------------------------------------------------------------------------
def pytest_addoption(parser: pytest.Parser) -> None:
"""Harness-level options (not exposed to individual tests)."""
group = parser.getgroup("e2e-runner", "Blackbox e2e harness options")
group.addoption(
"--enable-chamber",
action="store_true",
default=False,
help="Enable thermal-chamber-gated tests (AC-NEW-5 hot-soak, RESTRICT-HW-2). "
"Requires the chamber-attached Jetson runner; default off.",
)
group.addoption(
"--build-kind",
action="store",
default=os.environ.get("BUILD_KIND", "production"),
choices=("production", "research"),
help="Selects which VIO strategies are valid: production excludes vins_mono.",
)
group.addoption(
"--evidence-out",
action="store",
default=os.environ.get("EVIDENCE_OUT", "/e2e-results/evidence"),
help="Directory the evidence bundler writes per-run artifacts to.",
)
group.addoption(
"--allow-no-skip-reason",
action="store_true",
default=False,
help="Allow @pytest.mark.deferred_ac without an explicit reason= kwarg. "
"Default off — every deferred AC must cite its traceability-matrix row.",
)
# ---------------------------------------------------------------------------
# Parameterization matrix
# ---------------------------------------------------------------------------
_FC_ADAPTERS = ("ardupilot", "inav")
_VIO_STRATEGIES = ("okvis2", "klt_ransac", "vins_mono")
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
"""Parametrize tests that request the ``fc_adapter`` / ``vio_strategy`` fixtures.
Tests opt in by listing the fixture name in their signature. Tests that
explicitly do not depend on the matrix simply do not request the fixture.
"""
if "fc_adapter" in metafunc.fixturenames:
env_default = os.environ.get("FC_ADAPTER")
if env_default:
metafunc.parametrize("fc_adapter", [env_default], ids=[env_default])
else:
metafunc.parametrize("fc_adapter", _FC_ADAPTERS, ids=_FC_ADAPTERS)
if "vio_strategy" in metafunc.fixturenames:
env_default = os.environ.get("VIO_STRATEGY")
if env_default:
metafunc.parametrize("vio_strategy", [env_default], ids=[env_default])
else:
metafunc.parametrize("vio_strategy", _VIO_STRATEGIES, ids=_VIO_STRATEGIES)
# ---------------------------------------------------------------------------
# Skip-rule enforcement (deterministic; runs at collection time)
# ---------------------------------------------------------------------------
def pytest_collection_modifyitems(
config: pytest.Config, items: list[pytest.Item]
) -> None:
"""Apply traceability-matrix-driven skips before any test executes.
The mapping between AC / RESTRICT IDs and the SKIP reason strings is the
one declared in `_docs/02_document/tests/traceability-matrix.md` §
Uncovered Items Analysis. Any change to that matrix MUST be mirrored
here (and vice-versa) — the unit tests in
`e2e/_unit_tests/test_traceability_skip_rules.py` catch drift.
"""
tier = os.environ.get("TIER", "tier1-docker")
chamber_enabled = config.getoption("--enable-chamber")
build_kind = config.getoption("--build-kind")
skip_tier2 = pytest.mark.skip(reason="Tier-2 only — Jetson hardware required")
skip_chamber = pytest.mark.skip(
reason="Chamber-gated — run with --enable-chamber on the chamber-attached Jetson runner"
)
skip_research = pytest.mark.skip(
reason="vins_mono is research-build-only per D-C1-1-SUB-A"
)
for item in items:
# ----- Tier-2 only -----
if "tier2_only" in item.keywords and tier != "tier2-jetson":
item.add_marker(skip_tier2)
continue
# ----- Chamber only -----
if "chamber_only" in item.keywords and not chamber_enabled:
item.add_marker(skip_chamber)
continue
# ----- Research-build vs production matrix -----
# Skip vins_mono on production-build runs (the marker is set on the
# parametrize id, not the test fn — we check the param id).
if build_kind == "production":
call_params = getattr(item, "callspec", None)
if call_params is not None and call_params.params.get("vio_strategy") == "vins_mono":
item.add_marker(skip_research)
continue
# ----- Deferred-AC traceability-matrix skips -----
deferred = item.get_closest_marker("deferred_ac")
if deferred is not None:
reason = deferred.kwargs.get("reason")
if reason is None and not config.getoption("--allow-no-skip-reason"):
# Hard failure at collection — every deferred_ac MUST cite its
# matrix row to prevent silent coverage erosion.
item.add_marker(
pytest.mark.skip(
reason=(
"deferred_ac marker without reason= kwarg; cite the "
"traceability-matrix row that justifies the deferral, "
"or run with --allow-no-skip-reason for local debugging."
)
)
)
continue
verdict = deferred.kwargs.get("verdict", "skip").lower()
if verdict == "xfail":
item.add_marker(pytest.mark.xfail(reason=reason or "deferred AC (xfail)", strict=False))
else:
item.add_marker(
pytest.mark.skip(
reason=(
reason
or "deferred AC — see _docs/02_document/tests/traceability-matrix.md"
)
)
)
# ---------------------------------------------------------------------------
# Fixtures
# ---------------------------------------------------------------------------
@pytest.fixture(scope="session")
def run_id() -> str:
return os.environ.get("RUN_ID", "local")
@pytest.fixture(scope="session")
def tier() -> str:
return os.environ.get("TIER", "tier1-docker")
@pytest.fixture(scope="session")
def evidence_dir(pytestconfig: pytest.Config, run_id: str) -> Path:
base = Path(pytestconfig.getoption("--evidence-out"))
target = base if base.name == "evidence" else base / "evidence"
target.mkdir(parents=True, exist_ok=True)
return target
@pytest.fixture(scope="session")
def mock_suite_sat_url() -> str:
return os.environ.get("MOCK_SUITE_SAT_URL", "http://mock-suite-sat-service:8080")
# ---------------------------------------------------------------------------
# Plugin registration
# ---------------------------------------------------------------------------
# The CSV reporter plugin is a separate module so the unit tests can exercise
# it directly without going through a real pytest run. It is registered via
# `pytest_plugins` so docker-compose's `--csv=...` flag binds to our column
# set rather than the upstream pytest-csv default.
pytest_plugins = [
"runner.reporting.csv_reporter",
"runner.reporting.evidence_bundler",
"runner.reporting.nfr_recorder",
]