"""MARS-LVIG stress tier — featureless sequences, completion-rate gate."""

from pathlib import Path

import pytest

from gps_denied.testing.datasets.mars_lvig import MARSLVIGAdapter
from gps_denied.testing.harness import E2EHarness

# Stress tier does not gate on RMSE — featureless sequences legitimately cause
# tracking loss. The gate is whether the pipeline RUNS TO COMPLETION without
# crashing, and what fraction of frames produced any estimate at all.
MARS_COMPLETION_FLOOR = 0.0  # initial: any run-to-completion passes; tighten later


@pytest.mark.e2e
@pytest.mark.e2e_slow
@pytest.mark.needs_dataset
@pytest.mark.asyncio
async def test_mars_lvig_runs_to_completion(mars_lvig_root: Path):
    # Pick the first available sequence under mars_lvig_root
    seqs = sorted(p for p in mars_lvig_root.iterdir() if p.is_dir())
    if not seqs:
        pytest.skip(f"No MARS-LVIG sequences found under {mars_lvig_root}")
    adapter = MARSLVIGAdapter(seqs[0])
    harness = E2EHarness(adapter)
    result = await harness.run()
    assert result.num_frames_submitted > 0
    completion_rate = (
        result.num_estimates / result.num_frames_submitted
        if result.num_frames_submitted else 0.0
    )
    assert completion_rate >= MARS_COMPLETION_FLOOR, (
        f"Completion rate too low: {completion_rate:.2%}"
    )
