Files
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

203 lines
5.6 KiB
Python

"""Tests for the AZ-407 age-injector.
Covers AC-3 (capture_date shifted, pixels bit-identical) and AC-7
(provenance docs present).
"""
from __future__ import annotations
import csv
import datetime as _dt
import hashlib
import json
import os
import subprocess
import sys
from pathlib import Path
import pytest
REPO_ROOT = Path(__file__).resolve().parents[3]
INPUT_DIR = REPO_ROOT / "_docs" / "00_problem" / "input_data"
BUILDER_PY = REPO_ROOT / "e2e" / "fixtures" / "tile-cache-builder" / "builder.py"
INJECTOR_PY = REPO_ROOT / "e2e" / "fixtures" / "age-injector" / "age_injector.py"
INJECTOR_DIR = REPO_ROOT / "e2e" / "fixtures" / "age-injector"
def _run(cmd: list[str]) -> str:
"""Run a subprocess, return stdout (raises on failure)."""
env = dict(os.environ, PYTHONHASHSEED="0")
result = subprocess.run(cmd, check=True, capture_output=True, text=True, env=env)
return result.stdout
def _build_source_cache(out_dir: Path) -> Path:
"""Run the tile-cache builder; return the populated dir."""
_run(
[
sys.executable,
str(BUILDER_PY),
"--input-dir",
str(INPUT_DIR),
"--output-dir",
str(out_dir),
"--quiet",
]
)
return out_dir
def _file_hashes(root: Path, suffix: str) -> dict[str, str]:
return {
p.relative_to(root).as_posix(): hashlib.sha256(p.read_bytes()).hexdigest()
for p in sorted(root.rglob(f"*{suffix}"))
}
@pytest.fixture(scope="module")
def source_cache(tmp_path_factory: pytest.TempPathFactory) -> Path:
"""One-shot module-scoped tile-cache build (~1s)."""
return _build_source_cache(tmp_path_factory.mktemp("source-cache"))
@pytest.mark.parametrize("age_months,threshold_days", [(7, 6 * 30), (13, 12 * 30)])
def test_age_injector_shifts_capture_date(
tmp_path: Path,
source_cache: Path,
age_months: int,
threshold_days: int,
) -> None:
"""AC-3: every manifest row's capture_date is now - age_months ±1 day."""
# Arrange
out = tmp_path / f"out-{age_months}mo"
today = _dt.datetime.now(tz=_dt.timezone.utc).date()
# Act
_run(
[
sys.executable,
str(INJECTOR_PY),
"--source-dir",
str(source_cache),
"--output-dir",
str(out),
"--age-months",
str(age_months),
]
)
# Assert
with (out / "manifest.csv").open() as fp:
rows = list(csv.DictReader(fp))
assert rows, "aged manifest is empty"
for r in rows:
shifted = _dt.date.fromisoformat(r["capture_date"])
delta_days = (today - shifted).days
target_days = int(round(age_months * 30.44))
assert abs(delta_days - target_days) <= 1, (
f"row {r['tile_x']},{r['tile_y']}: capture_date offset is "
f"{delta_days} days, expected {target_days} ±1"
)
assert delta_days > threshold_days, (
f"aged capture_date {r['capture_date']} did not exceed the "
f"{threshold_days}-day threshold"
)
def test_age_injector_preserves_tile_bytes(tmp_path: Path, source_cache: Path) -> None:
"""AC-3: tile JPEG bodies copy bit-identical."""
# Arrange
out = tmp_path / "out-7mo"
# Act
_run(
[
sys.executable,
str(INJECTOR_PY),
"--source-dir",
str(source_cache),
"--output-dir",
str(out),
"--age-months",
"7",
]
)
# Assert
src_hashes = _file_hashes(source_cache / "tiles", ".jpg")
out_hashes = _file_hashes(out / "tiles", ".jpg")
assert src_hashes == out_hashes, "tile JPEG bytes drifted across age injection"
def test_age_injector_updates_sidecar_dates(tmp_path: Path, source_cache: Path) -> None:
"""AC-3: per-tile sidecar JSON also reflects the aged date."""
# Arrange
out = tmp_path / "out-13mo"
# Act
_run(
[
sys.executable,
str(INJECTOR_PY),
"--source-dir",
str(source_cache),
"--output-dir",
str(out),
"--age-months",
"13",
]
)
# Assert
today = _dt.datetime.now(tz=_dt.timezone.utc).date()
target_days = int(round(13 * 30.44))
for sidecar in sorted((out / "tiles").rglob("*.json")):
data = json.loads(sidecar.read_text())
shifted = _dt.date.fromisoformat(data["capture_date"])
delta = (today - shifted).days
assert abs(delta - target_days) <= 1, (
f"sidecar {sidecar}: capture_date offset {delta}d, expected {target_days}d ±1"
)
def test_age_injector_rejects_non_positive_months(tmp_path: Path, source_cache: Path) -> None:
"""Defensive: zero or negative age_months must error out, not silently no-op."""
# Arrange
out = tmp_path / "rejected"
# Act + Assert
with pytest.raises(subprocess.CalledProcessError) as excinfo:
_run(
[
sys.executable,
str(INJECTOR_PY),
"--source-dir",
str(source_cache),
"--output-dir",
str(out),
"--age-months",
"0",
]
)
assert "must be positive" in (excinfo.value.stderr or "")
def test_age_injector_provenance_readme_exists() -> None:
"""AC-7: README documents the injector."""
# Arrange / Act
readme = INJECTOR_DIR / "README.md"
# Assert
assert readme.exists()
content = readme.read_text()
assert "Provenance" in content
assert "Reproducibility" in content