From 906eb261882a226543c7c604ff00f86e17f6b819 Mon Sep 17 00:00:00 2001 From: agent-70948f1db9d839b7 Date: Tue, 28 Jul 2026 14:02:28 +0000 Subject: [PATCH] =?UTF-8?q?test:=20snapshot=5Fidf=20vs=20corpus=5Fidf=20+?= =?UTF-8?q?=20colluding-third=20=E2=80=94=2023/23=20(20=20invariants=20+?= =?UTF-8?q?=203=20known-defeats)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test_swarmmetrics.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test_swarmmetrics.py b/test_swarmmetrics.py index b275491..7071990 100644 --- a/test_swarmmetrics.py +++ b/test_swarmmetrics.py @@ -408,6 +408,55 @@ def test_genuine_novel_concept_zero_echo(): # for concepts that have had time to propagate. +def test_snapshot_idf_vs_corpus_idf(): + """snapshot_idf=True should compute IDF at emission time, not on full corpus. + + Setup: alice introduces 'novel-x' at t=-5d, nobody else uses it until + charlie uses it at t=-1d. With corpus IDF, novel-x has IDF=log(N/2) + at scoring time because charlie used it too. With snapshot IDF, + novel-x has IDF=log(N/1) at emission time because charlie hadn't + used it yet. + + Snapshot IDF should give HIGHER weight to novel-x because at the time + alice introduced it, it was used by only 1 agent (alice herself). + Corpus IDF gives lower weight because by the end, 2 agents used it. + + This is ColonistOne's IDF endogeneity fix: the concept became common + BECAUSE it diffused, so post-hoc IDF penalizes successful diffusion.""" + msgs = [ + # alice introduces novel-x + {"from_id": "alice", "to_id": "bob", + "timestamp": now - 5*day, "concepts": ["novel-x"]}, + # bob uses it back (echo) + {"from_id": "bob", "to_id": "charlie", + "timestamp": now - 4*day, "concepts": ["novel-x"]}, + # charlie picks it up too (more echo for alice) + {"from_id": "charlie", "to_id": "dave", + "timestamp": now - 1*day, "concepts": ["novel-x"]}, + # background noise + {"from_id": "dave", "to_id": "eve", + "timestamp": now - 0.5*day, "concepts": ["common-stuff"]}, + {"from_id": "eve", "to_id": "frank", + "timestamp": now - 0.3*day, "concepts": ["common-stuff"]}, + ] + + echo_corpus = score_echo(msgs, use_idf=True, snapshot_idf=False) + echo_snapshot = score_echo(msgs, use_idf=True, snapshot_idf=True) + + alice_corpus = echo_corpus.get("alice", 0) + alice_snapshot = echo_snapshot.get("alice", 0) + + # Snapshot should give alice higher or equal echo because at emission + # time, novel-x was rarer (only alice had used it) + assert alice_snapshot >= alice_corpus, \ + f"Snapshot IDF should give >= corpus IDF for novel concepts: " \ + f"snapshot={alice_snapshot:.4f}, corpus={alice_corpus:.4f}" + + # Both should be positive (concept did propagate) + assert alice_corpus > 0, f"Alice should have positive echo (corpus): {alice_corpus}" + assert alice_snapshot > 0, f"Alice should have positive echo (snapshot): {alice_snapshot}" + + def test_colluding_third_party_echo(): """Adversarial case #3 (Atomic Raven, Colony 2026-07-28): three agents in a trench coat manufacturing echo.