From efca5119dc0b1f73add9ac9767abd11f4630429c Mon Sep 17 00:00:00 2001 From: agent-70948f1db9d839b7 Date: Tue, 28 Jul 2026 17:08:30 +0000 Subject: [PATCH] test: add monotonic window-size invariant (38/38) Smaller window = less IDF contamination = more echo credit. Fixed previous inconclusive test: old fixture had only 2 agents, so IDF couldn't differentiate. New fixture uses 6 agents + silence gap. --- test_swarmmetrics.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test_swarmmetrics.py b/test_swarmmetrics.py index 3defd9c..debba5f 100644 --- a/test_swarmmetrics.py +++ b/test_swarmmetrics.py @@ -891,3 +891,34 @@ def test_windowed_idf_prevents_semantic_hysteresis(): # (windowed delta should be closer to zero than global delta) assert mean_windowed_delta >= mean_global_delta, \ f"Windowed IDF should reduce suppression: windowed Δ={mean_windowed_delta:.3f} vs global Δ={mean_global_delta:.3f}" + + +def test_windowed_idf_monotonic_with_window_size(): + """Wider window = more contamination = less echo credit. Strictly monotonic.""" + messages = [] + # originator introduces alpha + messages.append({"from_id": "originator", "to_id": "_all", + "timestamp": 0.0, "concepts": ["alpha"]}) + # 4 agents echo alpha heavily in phase 1 (t=50-850) + for i in range(20): + for j, agent in enumerate(["flood1", "flood2", "flood3", "flood4"]): + messages.append({ + "from_id": agent, "to_id": "_all", + "timestamp": float(50 + i * 40 + j * 10), + "concepts": ["alpha"] + }) + # Phase 2 (t=2000): fresh agent echoes alpha after long silence + messages.append({"from_id": "fresh", "to_id": "_all", + "timestamp": 2000.0, "concepts": ["alpha"]}) + + global_score = score_echo(messages, snapshot_idf=True)["originator"] + + windows = [100, 300, 500, 1000, 2000] + prev = float("inf") + for w in windows: + s = score_echo(messages, snapshot_idf=True, idf_window_seconds=w)["originator"] + assert s >= global_score - 0.001, \ + f"w={w}: windowed {s:.4f} < global {global_score:.4f}" + assert s <= prev + 0.001, \ + f"w={w}: score {s:.4f} increased from previous {prev:.4f} (should decrease)" + prev = s