From 40f6e0c6f72c35001e1b11fa09c7396d88a87d1e Mon Sep 17 00:00:00 2001 From: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Date: Sat, 15 Aug 2026 23:31:45 +0100 Subject: [PATCH] Cover fail-closed timestamp validation --- .../test_time_validity_invalid_timestamps.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/services/infonet/tests/test_time_validity_invalid_timestamps.py b/backend/services/infonet/tests/test_time_validity_invalid_timestamps.py index 253cf07..065e65d 100644 --- a/backend/services/infonet/tests/test_time_validity_invalid_timestamps.py +++ b/backend/services/infonet/tests/test_time_validity_invalid_timestamps.py @@ -1,13 +1,15 @@ """Regression coverage for malformed chain timestamps.""" +from typing import Any + from services.infonet.time_validity import chain_majority_time, is_event_too_future -def _event(node_id: str, timestamp): +def _event(node_id: str, timestamp: Any) -> dict[str, Any]: return {"node_id": node_id, "timestamp": timestamp} -def test_chain_majority_time_ignores_malformed_and_nonfinite_timestamps(): +def test_chain_majority_time_ignores_malformed_and_nonfinite_timestamps() -> None: chain = [ _event("valid-a", 10.0), _event("bad-text", "not-a-timestamp"), @@ -19,12 +21,18 @@ def test_chain_majority_time_ignores_malformed_and_nonfinite_timestamps(): assert chain_majority_time(chain) == 15.0 -def test_chain_majority_time_accepts_finite_numeric_strings(): +def test_chain_majority_time_accepts_finite_numeric_strings() -> None: chain = [_event("a", "10.5"), _event("b", "20.5")] assert chain_majority_time(chain) == 15.5 -def test_future_check_does_not_treat_nonfinite_timestamp_as_valid(): - assert not is_event_too_future(_event("a", float("nan")), chain_time=100.0) - assert not is_event_too_future(_event("a", float("inf")), chain_time=100.0) +def test_future_check_fails_closed_for_invalid_timestamps() -> None: + assert is_event_too_future(_event("bad-text", "not-a-timestamp"), chain_time=100.0) + assert is_event_too_future(_event("bad-nan", float("nan")), chain_time=100.0) + assert is_event_too_future(_event("bad-inf", float("inf")), chain_time=100.0) + + +def test_future_check_preserves_valid_timestamp_behavior() -> None: + assert not is_event_too_future(_event("near", 110.0), chain_time=100.0) + assert is_event_too_future(_event("far", 10_000.0), chain_time=100.0)