mirror of
https://github.com/azaion/gps-denied-onboard.git
synced 2026-06-22 17:41:13 +00:00
[AZ-240] [AZ-241] [AZ-242] Add native retrieval remediation
Implement the product remediation paths required before greenfield code testability revision: native VIO backend selection, local VPR descriptor index retrieval, and computed anchor matching gates. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from satellite_service import (
|
||||
LocalVprIndexPackage,
|
||||
LocalVprRetriever,
|
||||
@@ -33,6 +36,46 @@ def test_valid_local_index_load_reports_ready_status() -> None:
|
||||
assert readiness.ready is True
|
||||
assert readiness.engine == "cpu_faiss"
|
||||
assert readiness.loaded_records == 1
|
||||
assert readiness.package_id == "index-1"
|
||||
assert readiness.descriptor_model == "dinov2_vlad"
|
||||
|
||||
|
||||
def test_local_descriptor_index_package_loads_from_cache_file(tmp_path: Path) -> None:
|
||||
# Arrange
|
||||
package_path = tmp_path / "vpr-index.json"
|
||||
package_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"package_id": "index-file-1",
|
||||
"engine": "cpu_faiss",
|
||||
"descriptor_model": "dinov2_vlad",
|
||||
"records": [
|
||||
{
|
||||
"chunk_id": "chunk-file",
|
||||
"tile_id": "tile-file",
|
||||
"descriptor": [1.0, 0.0],
|
||||
"footprint": {
|
||||
"min_lat": 49.0,
|
||||
"max_lat": 49.1,
|
||||
"min_lon": 36.0,
|
||||
"max_lon": 36.1,
|
||||
},
|
||||
"freshness_status": "fresh",
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
retriever = LocalVprRetriever()
|
||||
|
||||
# Act
|
||||
readiness = retriever.load_index_from_path(package_path)
|
||||
|
||||
# Assert
|
||||
assert readiness.ready is True
|
||||
assert readiness.package_id == "index-file-1"
|
||||
assert readiness.loaded_records == 1
|
||||
|
||||
|
||||
def test_loaded_index_returns_bounded_candidates_with_freshness() -> None:
|
||||
@@ -65,12 +108,35 @@ def test_loaded_index_returns_bounded_candidates_with_freshness() -> None:
|
||||
|
||||
# Assert
|
||||
assert result.degraded is False
|
||||
assert result.retrieval_path == "local_descriptor_index"
|
||||
assert result.latency_ms is not None
|
||||
assert len(result.candidates) == 1
|
||||
assert result.candidates[0].chunk_id == "chunk-best"
|
||||
assert result.candidates[0].tile_id == "tile-best"
|
||||
assert result.candidates[0].freshness_status == "fresh"
|
||||
|
||||
|
||||
def test_loaded_index_requires_query_descriptor() -> None:
|
||||
# Arrange
|
||||
retriever = LocalVprRetriever()
|
||||
retriever.load_index(LocalVprIndexPackage(package_id="index-1", records=(_record(),)))
|
||||
request = RelocalizationRequest(
|
||||
frame_id="frame-1",
|
||||
image_ref="replay/frame-1.jpg",
|
||||
trigger_reason="covariance_growth",
|
||||
top_k=1,
|
||||
)
|
||||
|
||||
# Act
|
||||
result = retriever.retrieve(request)
|
||||
|
||||
# Assert
|
||||
assert result.ready is True
|
||||
assert result.degraded is True
|
||||
assert result.error is not None
|
||||
assert result.error.cause == "query_descriptor_missing"
|
||||
|
||||
|
||||
def test_missing_index_degrades_with_explicit_no_candidate_result() -> None:
|
||||
# Arrange
|
||||
retriever = LocalVprRetriever()
|
||||
@@ -92,6 +158,34 @@ def test_missing_index_degrades_with_explicit_no_candidate_result() -> None:
|
||||
assert result.error.cause == "index_not_loaded"
|
||||
|
||||
|
||||
def test_invalid_index_package_degrades_with_explicit_error(tmp_path: Path) -> None:
|
||||
# Arrange
|
||||
package_path = tmp_path / "invalid-index.json"
|
||||
package_path.write_text("{not-json", encoding="utf-8")
|
||||
retriever = LocalVprRetriever()
|
||||
|
||||
# Act
|
||||
readiness = retriever.load_index_from_path(package_path)
|
||||
result = retriever.retrieve(
|
||||
RelocalizationRequest(
|
||||
frame_id="frame-1",
|
||||
image_ref="replay/frame-1.jpg",
|
||||
trigger_reason="cold_start",
|
||||
top_k=3,
|
||||
query_descriptor=(1.0, 0.0),
|
||||
)
|
||||
)
|
||||
|
||||
# Assert
|
||||
assert readiness.ready is False
|
||||
assert readiness.error is not None
|
||||
assert readiness.error.cause == "index_package_invalid"
|
||||
assert result.ready is False
|
||||
assert result.degraded is True
|
||||
assert result.error is not None
|
||||
assert result.error.cause == "index_package_invalid"
|
||||
|
||||
|
||||
def test_descriptor_fidelity_gate_rejects_large_optimized_delta() -> None:
|
||||
# Arrange
|
||||
retriever = LocalVprRetriever()
|
||||
|
||||
Reference in New Issue
Block a user