Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Remove tests of test

laurenspriem9911f1b2db88
diff --git a/infra/ml/pyproject.toml b/infra/ml/pyproject.toml
index 93ea690455..237a6b3f36 100644
--- a/infra/ml/pyproject.toml
+++ b/infra/ml/pyproject.toml
@@ -13,11 +13,3 @@ dependencies = [
"requests>=2.34.2",
"scikit-image>=0.26.0",
]
-
-[dependency-groups]
-dev = [
- "pytest>=9.1.1",
-]
-
-[tool.pytest.ini_options]
-pythonpath = ["test"]
diff --git a/infra/ml/test/README.md b/infra/ml/test/README.md
index dc2d986d0c..1f4140d53c 100644
--- a/infra/ml/test/README.md
+++ b/infra/ml/test/README.md
@@ -7,7 +7,6 @@ This directory contains the ML indexing parity framework for Android, iOS, deskt
- `ground_truth/`: schema, manifest, and ONNX-backed Python pipeline.
- `comparator/`: parity comparison engine and threshold checks.
- `tools/`: suite orchestration and CLI entrypoints.
-- `tests/`: pytest coverage for schema/comparator behavior.
- Runtime-only artifacts (gitignored): `test_data/`, `out/`, `.cache/`.
## Prerequisites
diff --git a/infra/ml/test/tests/test_comparator.py b/infra/ml/test/tests/test_comparator.py
deleted file mode 100644
index 940ecdba21..0000000000
--- a/infra/ml/test/tests/test_comparator.py
+++ /dev/null
@@ -1,926 +0,0 @@
-from __future__ import annotations
-
-import math
-
-import pytest
-
-from comparator.compare import (
- ThresholdConfig,
- compare_platform_matrix,
- compare_result_sets,
-)
-from ground_truth.schema import ClipResult, FaceResult, ParityResult, RunnerMetadata
-
-
-def _unit_vector(length: int, seed: int) -> tuple[float, ...]:
- values = [(((index + 5) * (seed + 13)) % 67) - 33 for index in range(length)]
- norm = math.sqrt(sum(value * value for value in values))
- return tuple(value / norm for value in values)
-
-
-def _jittered_vector(vector: tuple[float, ...], *, index: int, delta: float) -> tuple[float, ...]:
- mutable = list(vector)
- mutable[index] += delta
- norm = math.sqrt(sum(value * value for value in mutable))
- return tuple(value / norm for value in mutable)
-
-
-def _metadata(platform: str) -> RunnerMetadata:
- return RunnerMetadata(
- platform=platform,
- runtime="pytest",
- models={
- "clip": "clip-hash",
- "face_detection": "fd-hash",
- "face_embedding": "fe-hash",
- },
- code_revision="deadbee",
- )
-
-
-def _face(seed: int, *, x: float, y: float, score: float) -> FaceResult:
- return FaceResult(
- box=(x, y, 0.22, 0.24),
- landmarks=(
- (x + 0.06, y + 0.09),
- (x + 0.16, y + 0.09),
- (x + 0.11, y + 0.14),
- (x + 0.07, y + 0.20),
- (x + 0.15, y + 0.20),
- ),
- score=score,
- embedding=_unit_vector(192, seed=seed),
- )
-
-
-def _face_with_box(
- seed: int,
- *,
- x: float,
- y: float,
- width: float,
- height: float,
- score: float,
-) -> FaceResult:
- return FaceResult(
- box=(x, y, width, height),
- landmarks=(
- (x + width * 0.30, y + height * 0.35),
- (x + width * 0.70, y + height * 0.35),
- (x + width * 0.50, y + height * 0.55),
- (x + width * 0.35, y + height * 0.78),
- (x + width * 0.65, y + height * 0.78),
- ),
- score=score,
- embedding=_unit_vector(192, seed=seed),
- )
-
-
-def _result(
- *,
- file_id: str,
- platform: str,
- clip_seed: int,
- faces: tuple[FaceResult, ...],
-) -> ParityResult:
- return ParityResult(
- file_id=file_id,
- clip=ClipResult(embedding=_unit_vector(512, seed=clip_seed)),
- faces=faces,
- runner_metadata=_metadata(platform),
- )
-
-
-def _status_for_file(report: object, file_id: str):
- return next(status for status in report.file_statuses if status.file_id == file_id)
-
-
-def test_compare_result_sets_passes_when_within_thresholds() -> None:
- reference_faces = (_face(100, x=0.22, y=0.10, score=0.95),)
- reference = _result(
- file_id="man.jpeg",
- platform="python",
- clip_seed=10,
- faces=reference_faces,
- )
-
- candidate_face = FaceResult(
- box=(0.2205, 0.101, 0.22, 0.24),
- landmarks=(
- (0.279, 0.188),
- (0.381, 0.188),
- (0.331, 0.241),
- (0.292, 0.300),
- (0.367, 0.300),
- ),
- score=0.952,
- embedding=_jittered_vector(reference_faces[0].embedding, index=0, delta=0.001),
- )
- candidate = ParityResult(
- file_id="man.jpeg",
- clip=ClipResult(
- embedding=_jittered_vector(reference.clip.embedding, index=0, delta=0.001)
- ),
- faces=(candidate_face,),
- runner_metadata=_metadata("android"),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="android",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is True
- assert report.findings == ()
- assert report.aggregates["clip_cosine_distance"].count == 1
- assert report.total_reference_files == 1
- assert report.passing_files == ("man.jpeg",)
- assert report.failing_files == ()
- file_status = _status_for_file(report, "man.jpeg")
- assert file_status.passed is True
- metric_names = {metric.metric for metric in file_status.metrics}
- assert "clip_cosine_distance" in metric_names
- assert "face_count_delta" in metric_names
- clip_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "clip_cosine_distance"
- )
- assert clip_metric.passed is True
-
-
-def test_compare_result_sets_fails_on_clip_drift() -> None:
- reference = _result(
- file_id="people.jpeg",
- platform="python",
- clip_seed=1,
- faces=(_face(200, x=0.2, y=0.1, score=0.91),),
- )
- candidate = _result(
- file_id="people.jpeg",
- platform="ios",
- clip_seed=999,
- faces=(_face(200, x=0.2, y=0.1, score=0.91),),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="ios",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is False
- assert any(finding.metric == "clip_cosine_distance" for finding in report.findings)
-
-
-def test_compare_result_sets_marks_clip_warning_band() -> None:
- reference = _result(
- file_id="clip-warning.jpeg",
- platform="python",
- clip_seed=10,
- faces=(_face(910, x=0.2, y=0.1, score=0.91),),
- )
- candidate = ParityResult(
- file_id=reference.file_id,
- clip=ClipResult(
- embedding=_jittered_vector(reference.clip.embedding, index=0, delta=0.25)
- ),
- faces=reference.faces,
- runner_metadata=_metadata("ios"),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="ios",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.status == "warning"
- assert report.passed is True
- assert report.findings == ()
- assert report.warning_files == ("clip-warning.jpeg",)
- assert report.failing_files == ()
- assert any(
- warning.metric == "clip_cosine_distance"
- and warning.file_id == "clip-warning.jpeg"
- for warning in report.warnings
- )
- assert any(
- warning.metric == "clip_cosine_distance" and warning.file_id == "*aggregate*"
- for warning in report.warnings
- )
- aggregate_status = next(
- status for status in report.file_statuses if status.file_id == "*aggregate*"
- )
- assert aggregate_status.status == "warning"
-
- file_status = _status_for_file(report, "clip-warning.jpeg")
- assert file_status.status == "warning"
- assert file_status.passed is True
- assert file_status.failures == ()
- assert any(
- warning.metric == "clip_cosine_distance" for warning in file_status.warnings
- )
-
- clip_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "clip_cosine_distance"
- )
- assert clip_metric.status == "warning"
- assert clip_metric.passed is True
- assert clip_metric.value is not None
- assert 0.015 < clip_metric.value <= 0.035
-
-
-def test_compare_result_sets_passes_when_iou_above_single_loose_threshold() -> None:
- reference_face = _face_with_box(
- 310,
- x=0.20,
- y=0.20,
- width=0.20,
- height=0.20,
- score=0.92,
- )
- reference = _result(
- file_id="loose-iou-face.webp",
- platform="python",
- clip_seed=11,
- faces=(reference_face,),
- )
- candidate_face = _face_with_box(
- 310,
- x=0.21,
- y=0.21,
- width=0.20,
- height=0.20,
- score=0.92,
- )
- candidate = ParityResult(
- file_id=reference.file_id,
- clip=reference.clip,
- faces=(candidate_face,),
- runner_metadata=_metadata("android"),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="android",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is True
- assert not any(finding.metric == "face_box_iou" for finding in report.findings)
- file_status = _status_for_file(report, reference.file_id)
- iou_shortfall_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "face_box_iou_shortfall_max"
- )
- assert iou_shortfall_metric.passed is True
- assert iou_shortfall_metric.value == pytest.approx(0.0)
-
-
-def test_compare_result_sets_fails_when_iou_below_single_loose_threshold() -> None:
- reference_face = _face_with_box(
- 701,
- x=0.20,
- y=0.20,
- width=0.20,
- height=0.20,
- score=0.92,
- )
- reference = _result(
- file_id="loose-iou-fail-face.webp",
- platform="python",
- clip_seed=21,
- faces=(reference_face,),
- )
- candidate_face = _face_with_box(
- 999,
- x=0.23,
- y=0.23,
- width=0.20,
- height=0.20,
- score=0.92,
- )
- candidate = ParityResult(
- file_id=reference.file_id,
- clip=reference.clip,
- faces=(candidate_face,),
- runner_metadata=_metadata("android"),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="android",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is False
- iou_failures = [finding for finding in report.findings if finding.metric == "face_box_iou"]
- assert iou_failures
- assert iou_failures[0].threshold == pytest.approx(0.80)
-
- file_status = _status_for_file(report, reference.file_id)
- iou_shortfall_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "face_box_iou_shortfall_max"
- )
- assert iou_shortfall_metric.passed is False
- assert iou_shortfall_metric.value is not None
- assert iou_shortfall_metric.value > 0.0
-
-
-def test_compare_result_sets_fails_on_face_count_mismatch() -> None:
- reference = _result(
- file_id="people.jpeg",
- platform="python",
- clip_seed=4,
- faces=(
- _face(10, x=0.2, y=0.1, score=0.9),
- _face(11, x=0.5, y=0.2, score=0.87),
- ),
- )
- candidate = _result(
- file_id="people.jpeg",
- platform="desktop",
- clip_seed=4,
- faces=(_face(10, x=0.2, y=0.1, score=0.9),),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="desktop",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is False
- assert any(finding.metric == "face_count" for finding in report.findings)
- assert report.total_reference_files == 1
- assert report.passing_files == ()
- assert report.failing_files == ("people.jpeg",)
- file_status = _status_for_file(report, "people.jpeg")
- assert any(
- failure.metric == "face_count" for failure in file_status.failures
- )
- face_count_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "face_count_delta"
- )
- assert face_count_metric.passed is False
-
-
-def test_compare_result_sets_ignores_faces_below_min_score_threshold() -> None:
- reference = _result(
- file_id="score-filter.jpeg",
- platform="python",
- clip_seed=41,
- faces=(
- _face(510, x=0.18, y=0.14, score=0.95),
- _face(511, x=0.62, y=0.50, score=0.79),
- ),
- )
- candidate = _result(
- file_id="score-filter.jpeg",
- platform="android",
- clip_seed=41,
- faces=(
- _face(510, x=0.18, y=0.14, score=0.95),
- ),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="android",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.status == "pass"
- assert report.passed is True
- assert report.findings == ()
- assert report.warning_files == ()
- assert report.failing_files == ()
- assert report.passing_files == ("score-filter.jpeg",)
-
- file_status = _status_for_file(report, "score-filter.jpeg")
- assert file_status.status == "pass"
- assert file_status.passed is True
- assert file_status.failures == ()
- assert file_status.warnings == ()
-
- reference_count = next(
- metric for metric in file_status.metrics if metric.metric == "reference_face_count"
- )
- candidate_count = next(
- metric for metric in file_status.metrics if metric.metric == "candidate_face_count"
- )
- assert reference_count.value == pytest.approx(1.0)
- assert candidate_count.value == pytest.approx(1.0)
- assert not any(finding.metric == "face_count" for finding in report.findings)
-
-
-def test_compare_result_sets_includes_matched_face_when_either_score_crosses_threshold() -> None:
- reference_face = _face(520, x=0.34, y=0.18, score=0.79)
- candidate_face = _face(520, x=0.3405, y=0.1805, score=0.83)
- reference = _result(
- file_id="near-threshold-face.jpeg",
- platform="python",
- clip_seed=42,
- faces=(reference_face,),
- )
- candidate = _result(
- file_id="near-threshold-face.jpeg",
- platform="ios",
- clip_seed=42,
- faces=(candidate_face,),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="ios",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is True
- assert report.findings == ()
- file_status = _status_for_file(report, "near-threshold-face.jpeg")
- reference_count = next(
- metric for metric in file_status.metrics if metric.metric == "reference_face_count"
- )
- candidate_count = next(
- metric for metric in file_status.metrics if metric.metric == "candidate_face_count"
- )
- score_delta = next(
- metric for metric in file_status.metrics if metric.metric == "score_delta_max"
- )
- assert reference_count.value == pytest.approx(1.0)
- assert candidate_count.value == pytest.approx(1.0)
- assert score_delta.value == pytest.approx(0.04)
- assert score_delta.passed is True
-
-
-def test_compare_result_sets_dedupes_platform_faces_before_matching() -> None:
- reference_face = _face_with_box(
- 540,
- x=0.20,
- y=0.20,
- width=0.20,
- height=0.20,
- score=0.92,
- )
- low_score_duplicate = _face_with_box(
- 999,
- x=0.20,
- y=0.20,
- width=0.20,
- height=0.20,
- score=0.20,
- )
- valid_candidate_face = _face_with_box(
- 540,
- x=0.202,
- y=0.202,
- width=0.20,
- height=0.20,
- score=0.91,
- )
- reference = _result(
- file_id="duplicate-face.jpeg",
- platform="python",
- clip_seed=44,
- faces=(reference_face,),
- )
- candidate = _result(
- file_id="duplicate-face.jpeg",
- platform="ios",
- clip_seed=44,
- faces=(low_score_duplicate, valid_candidate_face),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="ios",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is True
- assert report.findings == ()
- file_status = _status_for_file(report, "duplicate-face.jpeg")
- candidate_count = next(
- metric for metric in file_status.metrics if metric.metric == "candidate_face_count"
- )
- matched_count = next(
- metric for metric in file_status.metrics if metric.metric == "matched_face_count"
- )
- score_delta = next(
- metric for metric in file_status.metrics if metric.metric == "score_delta_max"
- )
- assert candidate_count.value == pytest.approx(1.0)
- assert matched_count.value == pytest.approx(1.0)
- assert score_delta.value == pytest.approx(0.01)
-
-
-def test_compare_result_sets_fails_large_score_delta_for_matched_threshold_face() -> None:
- reference_face = _face(530, x=0.34, y=0.18, score=0.79)
- candidate_face = _face(530, x=0.3405, y=0.1805, score=0.86)
- reference = _result(
- file_id="score-delta-face.jpeg",
- platform="python",
- clip_seed=43,
- faces=(reference_face,),
- )
- candidate = _result(
- file_id="score-delta-face.jpeg",
- platform="ios",
- clip_seed=43,
- faces=(candidate_face,),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="ios",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is False
- assert any(finding.metric == "score_delta" for finding in report.findings)
- file_status = _status_for_file(report, "score-delta-face.jpeg")
- score_delta = next(
- metric for metric in file_status.metrics if metric.metric == "score_delta_max"
- )
- assert score_delta.value == pytest.approx(0.07)
- assert score_delta.threshold == pytest.approx(0.05)
- assert score_delta.passed is False
-
-
-def test_compare_result_sets_marks_face_embedding_warning_band() -> None:
- reference_face = _face(620, x=0.24, y=0.20, score=0.93)
- candidate_face = FaceResult(
- box=reference_face.box,
- landmarks=reference_face.landmarks,
- score=reference_face.score,
- embedding=_jittered_vector(reference_face.embedding, index=0, delta=0.2),
- )
- reference = _result(
- file_id="embedding-warning.jpeg",
- platform="python",
- clip_seed=17,
- faces=(reference_face,),
- )
- candidate = ParityResult(
- file_id=reference.file_id,
- clip=reference.clip,
- faces=(candidate_face,),
- runner_metadata=_metadata("ios"),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="ios",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.status == "warning"
- assert report.passed is True
- assert report.findings == ()
- assert report.failing_files == ()
- assert report.warning_files == ("embedding-warning.jpeg",)
- assert report.passing_files == ()
- assert any(
- warning.metric == "face_embedding_cosine_distance"
- and warning.file_id == "embedding-warning.jpeg"
- for warning in report.warnings
- )
- assert any(warning.file_id == "*aggregate*" for warning in report.warnings)
- aggregate_status = next(
- status for status in report.file_statuses if status.file_id == "*aggregate*"
- )
- assert aggregate_status.status == "warning"
-
- file_status = _status_for_file(report, "embedding-warning.jpeg")
- assert file_status.status == "warning"
- assert file_status.passed is True
- assert file_status.failures == ()
- assert any(
- warning.metric == "face_embedding_cosine_distance"
- for warning in file_status.warnings
- )
-
- embedding_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "face_embedding_cosine_distance_max"
- )
- assert embedding_metric.status == "warning"
- assert embedding_metric.passed is True
- assert embedding_metric.value is not None
- assert 0.015 < embedding_metric.value <= 0.035
-
-
-def test_compare_result_sets_fails_face_embedding_above_warning_band() -> None:
- reference_face = _face(721, x=0.16, y=0.21, score=0.91)
- candidate_face = FaceResult(
- box=reference_face.box,
- landmarks=reference_face.landmarks,
- score=reference_face.score,
- embedding=_jittered_vector(reference_face.embedding, index=0, delta=0.3),
- )
- reference = _result(
- file_id="embedding-fail.jpeg",
- platform="python",
- clip_seed=29,
- faces=(reference_face,),
- )
- candidate = ParityResult(
- file_id=reference.file_id,
- clip=reference.clip,
- faces=(candidate_face,),
- runner_metadata=_metadata("desktop"),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="desktop",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.status == "fail"
- assert report.passed is False
- assert report.failing_files == ("embedding-fail.jpeg",)
- assert report.warning_files == ()
- assert any(
- finding.metric == "face_embedding_cosine_distance" for finding in report.findings
- )
-
- file_status = _status_for_file(report, "embedding-fail.jpeg")
- assert file_status.status == "fail"
- assert file_status.passed is False
-
- embedding_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "face_embedding_cosine_distance_max"
- )
- assert embedding_metric.status == "fail"
- assert embedding_metric.passed is False
- assert embedding_metric.value is not None
- assert embedding_metric.value > 0.035
-
-
-def test_compare_result_sets_reports_unmatched_faces_after_iou_gating() -> None:
- reference = _result(
- file_id="offset-face.jpeg",
- platform="python",
- clip_seed=19,
- faces=(
- _face_with_box(
- 901,
- x=0.10,
- y=0.10,
- width=0.20,
- height=0.20,
- score=0.88,
- ),
- ),
- )
- candidate = _result(
- file_id="offset-face.jpeg",
- platform="desktop",
- clip_seed=19,
- faces=(
- _face_with_box(
- 902,
- x=0.70,
- y=0.70,
- width=0.20,
- height=0.20,
- score=0.88,
- ),
- ),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="desktop",
- reference_results={reference.file_id: reference},
- candidate_results={candidate.file_id: candidate},
- )
-
- assert report.passed is False
- assert any(
- finding.metric == "unmatched_reference_face_count" for finding in report.findings
- )
- assert any(
- finding.metric == "unmatched_candidate_face_count" for finding in report.findings
- )
- assert not any(finding.metric == "face_box_iou" for finding in report.findings)
-
- file_status = _status_for_file(report, "offset-face.jpeg")
- matched_metric = next(
- metric for metric in file_status.metrics if metric.metric == "matched_face_count"
- )
- assert matched_metric.value == pytest.approx(0.0)
- assert matched_metric.passed is False
-
- unmatched_reference_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "unmatched_reference_face_count"
- )
- unmatched_candidate_metric = next(
- metric
- for metric in file_status.metrics
- if metric.metric == "unmatched_candidate_face_count"
- )
- assert unmatched_reference_metric.value == pytest.approx(1.0)
- assert unmatched_candidate_metric.value == pytest.approx(1.0)
- assert unmatched_reference_metric.passed is False
- assert unmatched_candidate_metric.passed is False
-
-
-def test_aggregate_gate_failure_is_reported() -> None:
- reference_results = {}
- candidate_results = {}
- for index, delta in enumerate((0.0, 0.001, 0.04)):
- file_id = f"file-{index}.jpeg"
- reference = _result(
- file_id=file_id,
- platform="python",
- clip_seed=33 + index,
- faces=(_face(50 + index, x=0.2, y=0.2, score=0.95),),
- )
- if index == 2:
- candidate_clip = tuple(-value for value in reference.clip.embedding)
- else:
- candidate_clip = _jittered_vector(reference.clip.embedding, index=0, delta=delta)
- candidate = ParityResult(
- file_id=file_id,
- clip=ClipResult(embedding=candidate_clip),
- faces=reference.faces,
- runner_metadata=_metadata("android"),
- )
- reference_results[file_id] = reference
- candidate_results[file_id] = candidate
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="android",
- reference_results=reference_results,
- candidate_results=candidate_results,
- thresholds=ThresholdConfig(clip_cosine_distance=0.01),
- )
-
- assert report.passed is False
- assert any(finding.file_id == "*aggregate*" for finding in report.findings)
- assert report.failing_files == ("file-2.jpeg",)
- aggregate_status = next(
- status for status in report.file_statuses if status.file_id == "*aggregate*"
- )
- assert aggregate_status.status == "fail"
- assert any(metric.metric == "clip_cosine_distance" for metric in aggregate_status.metrics)
- assert report.to_dict()["file_summary"]["fail_count"] == 1
- assert report.to_dict()["file_summary"]["total_files"] == 3
-
-
-def test_extra_candidate_file_is_included_in_file_status_summary() -> None:
- extra_candidate = _result(
- file_id="unexpected.jpeg",
- platform="desktop",
- clip_seed=55,
- faces=(),
- )
-
- report = compare_result_sets(
- reference_platform="python",
- candidate_platform="desktop",
- reference_results={},
- candidate_results={extra_candidate.file_id: extra_candidate},
- )
-
- assert report.status == "fail"
- assert report.passed is False
- assert report.failing_files == ("unexpected.jpeg",)
- status = next(
- file_status
- for file_status in report.file_statuses
- if file_status.file_id == "unexpected.jpeg"
- )
- assert status.status == "fail"
- assert any(failure.metric == "file_presence" for failure in status.failures)
-
-
-def test_compare_platform_matrix_includes_pairwise_reports() -> None:
- reference = _result(
- file_id="man.jpeg",
- platform="python",
- clip_seed=6,
- faces=(_face(200, x=0.25, y=0.12, score=0.9),),
- )
- android = ParityResult(
- file_id=reference.file_id,
- clip=ClipResult(embedding=_jittered_vector(reference.clip.embedding, index=0, delta=0.001)),
- faces=reference.faces,
- runner_metadata=_metadata("android"),
- )
- ios = ParityResult(
- file_id=reference.file_id,
- clip=ClipResult(embedding=_jittered_vector(reference.clip.embedding, index=1, delta=0.001)),
- faces=reference.faces,
- runner_metadata=_metadata("ios"),
- )
- desktop = ParityResult(
- file_id=reference.file_id,
- clip=ClipResult(embedding=_jittered_vector(reference.clip.embedding, index=2, delta=0.001)),
- faces=reference.faces,
- runner_metadata=_metadata("desktop"),
- )
-
- reports = compare_platform_matrix(
- {
- "python": (reference,),
- "android": (android,),
- "ios": (ios,),
- "desktop": (desktop,),
- }
- )
-
- assert len(reports) == 6
- assert all(report.passed for report in reports)
-
-
-def test_compare_platform_matrix_rejects_duplicate_file_ids() -> None:
- reference = _result(
- file_id="man.jpeg",
- platform="python",
- clip_seed=6,
- faces=(_face(200, x=0.25, y=0.12, score=0.9),),
- )
- android_primary = _result(
- file_id="man.jpeg",
- platform="android",
- clip_seed=6,
- faces=(_face(200, x=0.25, y=0.12, score=0.9),),
- )
- android_duplicate = _result(
- file_id="man.jpeg",
- platform="android",
- clip_seed=7,
- faces=(_face(201, x=0.25, y=0.12, score=0.9),),
- )
-
- with pytest.raises(ValueError, match="platform 'android' emitted duplicate file_id values"):
- compare_platform_matrix(
- {
- "python": (reference,),
- "android": (android_primary, android_duplicate),
- }
- )
-
-
-def test_threshold_config_rejects_invalid_warning_threshold() -> None:
- with pytest.raises(
- ValueError,
- match="face_embedding_warning_cosine_distance must be >=",
- ):
- ThresholdConfig(
- face_embedding_cosine_distance=0.02,
- face_embedding_warning_cosine_distance=0.01,
- )
-
-
-def test_threshold_config_rejects_invalid_clip_warning_threshold() -> None:
- with pytest.raises(
- ValueError,
- match="clip_warning_cosine_distance must be >=",
- ):
- ThresholdConfig(
- clip_cosine_distance=0.02,
- clip_warning_cosine_distance=0.01,
- )
-
-
-def test_threshold_config_rejects_invalid_cross_platform_clip_warning_threshold() -> None:
- with pytest.raises(
- ValueError,
- match="cross_platform_clip_warning_cosine_distance must be >=",
- ):
- ThresholdConfig(
- cross_platform_clip_cosine_distance=0.02,
- cross_platform_clip_warning_cosine_distance=0.01,
- )
diff --git a/infra/ml/test/tests/test_runtime.py b/infra/ml/test/tests/test_runtime.py
deleted file mode 100644
index 2bb5642fb0..0000000000
--- a/infra/ml/test/tests/test_runtime.py
+++ /dev/null
@@ -1,73 +0,0 @@
-from __future__ import annotations
-
-import numpy as np
-from PIL import Image
-from pathlib import Path
-
-import ground_truth._runtime as runtime
-
-
-def _sample_image() -> Image.Image:
- # Width != height so orientation swaps are easy to assert.
- pixels = np.array(
- [
- [[255, 0, 0], [0, 255, 0], [0, 0, 255]],
- [[10, 20, 30], [40, 50, 60], [70, 80, 90]],
- ],
- dtype=np.uint8,
- )
- return Image.fromarray(pixels, mode="RGB")
-
-
-def test_correct_image_orientation_applies_standard_exif_orientation() -> None:
- image = _sample_image()
- exif = image.getexif()
- exif[274] = 6
- image.info["exif"] = exif.tobytes()
-
- corrected = runtime._correct_image_orientation(image)
-
- assert corrected.size == (2, 3)
-
-
-def test_correct_image_orientation_uses_original_orientation_when_exif_is_normalized() -> None:
- image = _sample_image()
- exif = image.getexif()
- exif[274] = 1
- image.info["exif"] = exif.tobytes()
- image.info["original_orientation"] = 6
-
- corrected = runtime._correct_image_orientation(image)
-
- assert corrected.size == (2, 3)
-
-
-def test_correct_image_orientation_leaves_image_unchanged_without_orientation_metadata() -> None:
- image = _sample_image()
-
- corrected = runtime._correct_image_orientation(image)
-
- assert corrected.size == image.size
-
-
-def test_correct_image_orientation_skips_original_orientation_for_heif_with_primary_transform(
- monkeypatch,
-) -> None:
- image = _sample_image()
- exif = image.getexif()
- exif[274] = 1
- image.info["exif"] = exif.tobytes()
- image.info["original_orientation"] = 6
-
- monkeypatch.setattr(
- runtime,
- "_heif_primary_item_has_orientation_transform",
- lambda _: True,
- )
-
- corrected = runtime._correct_image_orientation(
- image,
- source_path=Path("/tmp/example.HEIC"),
- )
-
- assert corrected.size == image.size
diff --git a/infra/ml/test/tests/test_schema.py b/infra/ml/test/tests/test_schema.py
deleted file mode 100644
index 1e57bab5bc..0000000000
--- a/infra/ml/test/tests/test_schema.py
+++ /dev/null
@@ -1,81 +0,0 @@
-from __future__ import annotations
-
-import math
-
-import pytest
-
-from ground_truth.schema import (
- CLIP_EMBEDDING_DIM,
- FACE_EMBEDDING_DIM,
- ClipResult,
- FaceResult,
- ParityResult,
- RunnerMetadata,
-)
-
-
-def _unit_vector(length: int, seed: int) -> tuple[float, ...]:
- values = [(((index + 3) * (seed + 7)) % 41) - 20 for index in range(length)]
- norm = math.sqrt(sum(value * value for value in values))
- return tuple(value / norm for value in values)
-
-
-def _runner_metadata() -> RunnerMetadata:
- return RunnerMetadata(
- platform="python",
- runtime="pytest",
- models={
- "clip": "clip-hash",
- "face_detection": "fd-hash",
- "face_embedding": "fe-hash",
- },
- code_revision="deadbee",
- )
-
-
-def _face(index: int, *, x: float, score: float) -> FaceResult:
- return FaceResult(
- box=(x, 0.1 + index * 0.05, 0.2, 0.25),
- landmarks=(
- (x + 0.05, 0.15),
- (x + 0.15, 0.15),
- (x + 0.10, 0.20),
- (x + 0.06, 0.28),
- (x + 0.14, 0.28),
- ),
- score=score,
- embedding=_unit_vector(FACE_EMBEDDING_DIM, seed=30 + index),
- )
-
-
-def test_parity_result_round_trip_and_canonical_face_sorting() -> None:
- unsorted_faces = (_face(0, x=0.4, score=0.91), _face(1, x=0.2, score=0.84))
- result = ParityResult(
- file_id="people.jpeg",
- clip=ClipResult(embedding=_unit_vector(CLIP_EMBEDDING_DIM, seed=11)),
- faces=unsorted_faces,
- runner_metadata=_runner_metadata(),
- )
-
- assert result.faces[0].box[0] == pytest.approx(0.2)
- assert result.faces[1].box[0] == pytest.approx(0.4)
-
- payload = result.to_json()
- round_tripped = ParityResult.from_json(payload)
- assert round_tripped == result
-
-
-def test_invalid_clip_dimension_is_rejected() -> None:
- with pytest.raises(ValueError, match="exactly 512"):
- ClipResult(embedding=_unit_vector(10, seed=5))
-
-
-def test_non_normalized_face_embedding_is_rejected() -> None:
- invalid_embedding = tuple(1.0 for _ in range(FACE_EMBEDDING_DIM))
- with pytest.raises(ValueError, match="L2 normalized"):
- FaceResult(
- box=(0.1, 0.2, 0.3, 0.3),
- landmarks=((0.2, 0.2),),
- score=0.9,
- embedding=invalid_embedding,
- )
diff --git a/infra/ml/uv.lock b/infra/ml/uv.lock
index 1eab6ed866..887cb088a9 100644
--- a/infra/ml/uv.lock
+++ b/infra/ml/uv.lock
@@ -43,15 +43,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/28/76/e6222113b83e3622caa4bb41032d0b1bf785250607392e1b778aca0b8a7d/charset_normalizer-3.3.2-py3-none-any.whl", hash = "sha256:3e4d1f6587322d2788836a99c69062fbb091331ec940e02d12d179c1d53e25fc", size = 48543, upload-time = "2023-11-01T04:04:58.622Z" },
]
-[[package]]
-name = "colorama"
-version = "0.4.6"
-source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/d8/53/6f443c9a4a8358a93a6792e2acffb9d9d5cb0a5cfd8802644b7b1c9a02e4/colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44", size = 27697, upload-time = "2022-10-25T02:36:22.414Z" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/d1/d6/3965ed04c63042e047cb6a3e6ed1a63a35087b6a609aa3a15ed8ac56c221/colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6", size = 25335, upload-time = "2022-10-25T02:36:20.889Z" },
-]
-
[[package]]
name = "coloredlogs"
version = "15.0.1"
@@ -78,11 +69,6 @@ dependencies = [
{ name = "scikit-image" },
]
-[package.dev-dependencies]
-dev = [
- { name = "pytest" },
-]
-
[package.metadata]
requires-dist = [
{ name = "numpy", specifier = ">=2.1.2" },
@@ -94,9 +80,6 @@ requires-dist = [
{ name = "scikit-image", specifier = ">=0.26.0" },
]
-[package.metadata.requires-dev]
-dev = [{ name = "pytest", specifier = ">=9.1.1" }]
-
[[package]]
name = "flatbuffers"
version = "24.3.25"
@@ -140,15 +123,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/49/fa/391e437a34e55095173dca5f24070d89cbc233ff85bf1c29c93248c6588d/imageio-2.37.3-py3-none-any.whl", hash = "sha256:46f5bb8522cd421c0f5ae104d8268f569d856b29eb1a13b92829d1970f32c9f0", size = 317646, upload-time = "2026-03-09T11:31:10.771Z" },
]
-[[package]]
-name = "iniconfig"
-version = "2.3.0"
-source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/72/34/14ca021ce8e5dfedc35312d08ba8bf51fdd999c576889fc2c24cb97f4f10/iniconfig-2.3.0.tar.gz", hash = "sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730", size = 20503, upload-time = "2025-10-18T21:55:43.219Z" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/cb/b1/3846dd7f199d53cb17f49cba7e651e9ce294d8497c8c150530ed11865bb8/iniconfig-2.3.0-py3-none-any.whl", hash = "sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12", size = 7484, upload-time = "2025-10-18T21:55:41.639Z" },
-]
-
[[package]]
name = "lazy-loader"
version = "0.5"
@@ -357,15 +331,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/20/e3/bbd66a4f81a5e77e364effbedc8c5767ad1cc481f0a082093189e56d65e5/pillow_heif-0.22.0-cp313-cp313-win_amd64.whl", hash = "sha256:bac5e9a4d85ffc724180eb0fa3aef304aa9b67faea6f86c33e4c2e6a447db098", size = 8567192, upload-time = "2025-03-15T13:20:07.909Z" },
]
-[[package]]
-name = "pluggy"
-version = "1.6.0"
-source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/f9/e2/3e91f31a7d2b083fe6ef3fa267035b518369d9511ffab804f839851d2779/pluggy-1.6.0.tar.gz", hash = "sha256:7dcc130b76258d33b90f61b658791dede3486c3e6bfb003ee5c9bfb396dd22f3", size = 69412, upload-time = "2025-05-15T12:30:07.975Z" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl", hash = "sha256:e920276dd6813095e9377c0bc5566d94c932c33b27a3e3945d8389c374dd4746", size = 20538, upload-time = "2025-05-15T12:30:06.134Z" },
-]
-
[[package]]
name = "protobuf"
version = "7.35.1"
@@ -381,15 +346,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/19/c7/5f7c636ec43e0c545e28d1f1db71990108306f7bdcb89f069ba97e428e7f/protobuf-7.35.1-py3-none-any.whl", hash = "sha256:4bc97768d8fe4ad6743c8a19403e314511ed9f6d13205b687e52421c023ac1b9", size = 171659, upload-time = "2026-06-11T21:55:39.155Z" },
]
-[[package]]
-name = "pygments"
-version = "2.20.0"
-source = { registry = "https://pypi.org/simple" }
-sdist = { url = "https://files.pythonhosted.org/packages/c3/b2/bc9c9196916376152d655522fdcebac55e66de6603a76a02bca1b6414f6c/pygments-2.20.0.tar.gz", hash = "sha256:6757cd03768053ff99f3039c1a36d6c0aa0b263438fcab17520b30a303a82b5f", size = 4955991, upload-time = "2026-03-29T13:29:33.898Z" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
-]
-
[[package]]
name = "pyreadline3"
version = "3.5.4"
@@ -399,22 +355,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/5a/dc/491b7661614ab97483abf2056be1deee4dc2490ecbf7bff9ab5cdbac86e1/pyreadline3-3.5.4-py3-none-any.whl", hash = "sha256:eaf8e6cc3c49bcccf145fc6067ba8643d1df34d604a1ec0eccbf7a18e6d3fae6", size = 83178, upload-time = "2024-09-19T02:40:08.598Z" },
]
-[[package]]
-name = "pytest"
-version = "9.1.1"
-source = { registry = "https://pypi.org/simple" }
-dependencies = [
- { name = "colorama", marker = "sys_platform == 'win32'" },
- { name = "iniconfig" },
- { name = "packaging" },
- { name = "pluggy" },
- { name = "pygments" },
-]
-sdist = { url = "https://files.pythonhosted.org/packages/e4/47/b9efed96c114afcfa3c9d3fe98a76a1d14c74a9e266d397cf6eb64be5e01/pytest-9.1.1.tar.gz", hash = "sha256:1088fbde8f2b49d95a549a195707afa7a76a3ce9bcadc26b6d71f0ffda5fe313", size = 1636369, upload-time = "2026-06-19T10:58:32.857Z" }
-wheels = [
- { url = "https://files.pythonhosted.org/packages/24/25/1de2678b631f5a49215c6c96fff41ba892b0a34df68d6d80292b1b48aa7f/pytest-9.1.1-py3-none-any.whl", hash = "sha256:37a86b45efb9a47a61a36449063e8e18d0cab3161329fc099eb21783169c4f0c", size = 386536, upload-time = "2026-06-19T10:58:31.347Z" },
-]
-
[[package]]
name = "requests"
version = "2.34.2"