Pandago/graphstrike-model-training
0
1#!/usr/bin/env python32"""End-to-end test for Round 2 implementation.3 4Tests:51. Platform-specific episode loading62. New tool actions (GET_POLICY, REVERSE_IMAGE_SEARCH, ANALYZE_BIO, CHECK_IP)73. Platform-adaptive scoring84. Hidden signals revelation9"""10 11from pathlib import Path12import sys13 14sys.path.insert(0, str(Path(__file__).parent))15 16from server.environment import FakeGangEnvironment17from models import FakeGangAction, ActionType18 19 20def test_round2():21 """Run comprehensive Round 2 test."""22 23 print("=" * 70)24 print("ROUND 2 END-TO-END TEST")25 print("=" * 70)26 27 env = FakeGangEnvironment()28 29 # Test 1: Instagram episode (even seed)30 print("\n[Test 1] Instagram Episode (seed=0)")31 print("-" * 70)32 obs = env.reset(task="easy", seed=0)33 print(f"✓ Platform: {obs.platform}")34 assert obs.platform == "Instagram", f"Expected Instagram, got {obs.platform}"35 print(f"✓ Steps remaining: {obs.steps_remaining}")36 print(f"✓ Starting visible: {len(obs.visible_account_ids)} accounts")37 38 # Test 2: GET_POLICY action39 print("\n[Test 2] GET_POLICY Action")40 print("-" * 70)41 action = FakeGangAction(action_type=ActionType.GET_POLICY)42 obs = env.step(action)43 print(f"✓ Message: {obs.message[:200]}")44 assert "Instagram" in obs.message or "threshold" in obs.message.lower(), "Policy not returned"45 assert obs.steps_remaining == 30, "GET_POLICY should not consume steps"46 47 # Test 3: INSPECT to find accounts48 print("\n[Test 3] INSPECT Action")49 print("-" * 70)50 acc_id = obs.visible_account_ids[0]51 action = FakeGangAction(action_type=ActionType.INSPECT, account_id=acc_id)52 obs = env.step(action)53 print(f"✓ Inspected: {acc_id}")54 print(f"✓ Steps remaining: {obs.steps_remaining}")55 assert obs.steps_remaining == 29, "INSPECT should consume 1 step"56 57 # Check that profile exists58 profile = next((p for p in obs.visible_accounts if p.account_id == acc_id), None)59 assert profile is not None, f"Profile for {acc_id} not found"60 print(f"✓ Profile created: fake_risk={profile.fake_risk_score:.3f}")61 62 # Test 4: REVERSE_IMAGE_SEARCH (hidden signal revelation)63 print("\n[Test 4] REVERSE_IMAGE_SEARCH Action")64 print("-" * 70)65 photo_before = profile.photo_reuse_score66 print(f" Before: photo_reuse_score = {photo_before:.3f}")67 68 action = FakeGangAction(action_type=ActionType.REVERSE_IMAGE_SEARCH, account_id=acc_id)69 obs = env.step(action)70 print(f"✓ Steps remaining: {obs.steps_remaining}")71 assert obs.steps_remaining == 28, "REVERSE_IMAGE_SEARCH should consume 1 step"72 73 profile = next((p for p in obs.visible_accounts if p.account_id == acc_id), None)74 photo_after = profile.photo_reuse_score75 print(f" After: photo_reuse_score = {photo_after:.3f}")76 print(f"✓ Signal revealed (changed: {photo_before != photo_after})")77 78 # Test 5: ANALYZE_BIO79 print("\n[Test 5] ANALYZE_BIO Action")80 print("-" * 70)81 bio_before = profile.bio_template_score82 print(f" Before: bio_template_score = {bio_before:.3f}")83 84 action = FakeGangAction(action_type=ActionType.ANALYZE_BIO, account_id=acc_id)85 obs = env.step(action)86 assert obs.steps_remaining == 27, "ANALYZE_BIO should consume 1 step"87 88 profile = next((p for p in obs.visible_accounts if p.account_id == acc_id), None)89 bio_after = profile.bio_template_score90 print(f" After: bio_template_score = {bio_after:.3f}")91 print(f"✓ Signal revealed (changed: {bio_before != bio_after})")92 93 # Test 6: CHECK_IP (expensive action)94 print("\n[Test 6] CHECK_IP Action")95 print("-" * 70)96 steps_before = obs.steps_remaining97 action = FakeGangAction(action_type=ActionType.CHECK_IP, account_id=acc_id)98 obs = env.step(action)99 print(f"✓ Steps consumed: {steps_before - obs.steps_remaining}")100 assert steps_before - obs.steps_remaining == 2, "CHECK_IP should consume 2 steps"101 print(f"✓ Message: {obs.message[:150]}")102 103 # Test 7: Snapchat episode (odd seed)104 print("\n[Test 7] Snapchat Episode (seed=1)")105 print("-" * 70)106 obs = env.reset(task="easy", seed=1)107 print(f"✓ Platform: {obs.platform}")108 assert obs.platform == "Snapchat", f"Expected Snapchat, got {obs.platform}"109 110 action = FakeGangAction(action_type=ActionType.GET_POLICY)111 obs = env.step(action)112 print(f"✓ Message: {obs.message[:200]}")113 assert "Snapchat" in obs.message or "threshold" in obs.message.lower()114 115 # Test 8: Platform-adaptive scoring116 print("\n[Test 8] Platform-Adaptive Scoring")117 print("-" * 70)118 119 # Reset to Instagram120 obs = env.reset(task="easy", seed=0)121 action = FakeGangAction(action_type=ActionType.GET_POLICY)122 obs = env.step(action)123 124 # Inspect and flag an account125 acc_id = obs.visible_account_ids[0]126 action = FakeGangAction(action_type=ActionType.INSPECT, account_id=acc_id)127 obs = env.step(action)128 129 profile = next((p for p in obs.visible_accounts if p.account_id == acc_id), None)130 print(f" Account: {acc_id}")131 print(f" fake_risk_score: {profile.fake_risk_score:.3f}")132 print(f" status: {profile.status}")133 print(f"✓ Risk computed with platform-adaptive weights")134 135 # Test 9: SUBMIT with platform-specific rewards136 print("\n[Test 9] SUBMIT with Platform Rewards")137 print("-" * 70)138 139 # Flag gang members if we can identify them140 obs = env.reset(task="easy", seed=2)141 142 # Inspect a few accounts143 for acc_id in obs.visible_account_ids[:5]:144 action = FakeGangAction(action_type=ActionType.INSPECT, account_id=acc_id)145 obs = env.step(action)146 147 # Flag high-risk accounts148 flagged_count = 0149 for profile in obs.visible_accounts:150 if profile.fake_risk_score > 0.6 and flagged_count < 5:151 action = FakeGangAction(action_type=ActionType.FLAG, account_id=profile.account_id)152 obs = env.step(action)153 flagged_count += 1154 155 print(f" Flagged: {len(obs.flagged_ids)} accounts")156 157 action = FakeGangAction(action_type=ActionType.SUBMIT)158 obs = env.step(action)159 print(f"✓ Episode complete: done={obs.done}")160 print(f"✓ Final reward: {obs.reward:.3f}")161 print(f"✓ Message: {obs.message[:200]}")162 163 print("\n" + "=" * 70)164 print("ALL TESTS PASSED ✓")165 print("=" * 70)166 print("\nRound 2 implementation verified:")167 print(" ✓ Platform-specific episodes (Instagram/Snapchat)")168 print(" ✓ GET_POLICY action (0 steps)")169 print(" ✓ REVERSE_IMAGE_SEARCH (1 step)")170 print(" ✓ ANALYZE_BIO (1 step)")171 print(" ✓ CHECK_IP (2 steps)")172 print(" ✓ Hidden signals revelation")173 print(" ✓ Platform-adaptive scoring")174 print(" ✓ Complete episode flow")175 176 177if __name__ == "__main__":178 test_round2()179 