|
| 1 | +import os |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from agentscore import AgentScore |
| 6 | + |
| 7 | +API_KEY = os.environ.get("AGENTSCORE_API_KEY") |
| 8 | +BASE_URL = os.environ.get("AGENTSCORE_BASE_URL", "http://api.dev.agentscore.internal") |
| 9 | +TEST_ADDRESS = "0x339559a2d1cd15059365fc7bd36b3047bba480e0" |
| 10 | + |
| 11 | +pytestmark = pytest.mark.skipif(not API_KEY, reason="AGENTSCORE_API_KEY not set") |
| 12 | + |
| 13 | + |
| 14 | +def test_get_reputation_shape(): |
| 15 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 16 | + rep = client.get_reputation(TEST_ADDRESS) |
| 17 | + |
| 18 | + assert "chains" in rep["subject"] |
| 19 | + assert isinstance(rep["subject"]["chains"], list) |
| 20 | + assert len(rep["subject"]["chains"]) > 0 |
| 21 | + |
| 22 | + assert "value" in rep["score"] |
| 23 | + assert "grade" in rep["score"] |
| 24 | + assert "scored_at" in rep["score"] |
| 25 | + assert "status" in rep["score"] |
| 26 | + assert "version" in rep["score"] |
| 27 | + assert "confidence" not in rep["score"] |
| 28 | + assert "dimensions" not in rep["score"] |
| 29 | + |
| 30 | + assert "chains" in rep |
| 31 | + assert isinstance(rep["chains"], list) |
| 32 | + assert len(rep["chains"]) > 0 |
| 33 | + |
| 34 | + chain = rep["chains"][0] |
| 35 | + assert "chain" in chain |
| 36 | + assert "score" in chain |
| 37 | + assert "classification" in chain |
| 38 | + assert "identity" in chain |
| 39 | + assert "activity" in chain |
| 40 | + assert "evidence_summary" in chain |
| 41 | + |
| 42 | + assert "agents" in rep |
| 43 | + assert isinstance(rep["agents"], list) |
| 44 | + |
| 45 | + |
| 46 | +def test_get_reputation_chain_filter(): |
| 47 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 48 | + rep = client.get_reputation(TEST_ADDRESS, chain="base") |
| 49 | + |
| 50 | + assert rep["subject"]["chains"] == ["base"] |
| 51 | + assert len(rep["chains"]) == 1 |
| 52 | + assert rep["chains"][0]["chain"] == "base" |
| 53 | + |
| 54 | + |
| 55 | +def test_get_reputation_chain_entry_full_fields(): |
| 56 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 57 | + rep = client.get_reputation(TEST_ADDRESS) |
| 58 | + chain = rep["chains"][0] |
| 59 | + |
| 60 | + assert "confidence" in chain["score"] |
| 61 | + assert "dimensions" in chain["score"] |
| 62 | + assert "as_verified_payer" in chain["activity"] |
| 63 | + assert "active_days" in chain["activity"] |
| 64 | + assert "first_candidate_tx_at" in chain["activity"] |
| 65 | + |
| 66 | + |
| 67 | +def test_get_reputation_metadata_fields(): |
| 68 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 69 | + rep = client.get_reputation(TEST_ADDRESS) |
| 70 | + |
| 71 | + assert "caveats" in rep |
| 72 | + assert "data_semantics" in rep |
| 73 | + assert "updated_at" in rep |
| 74 | + |
| 75 | + |
| 76 | +def test_assess_operator_level(): |
| 77 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 78 | + result = client.assess(TEST_ADDRESS) |
| 79 | + |
| 80 | + assert "decision" in result |
| 81 | + assert isinstance(result["decision_reasons"], list) |
| 82 | + assert isinstance(result["chains"], list) |
| 83 | + assert isinstance(result["agents"], list) |
| 84 | + assert "classification" not in result |
| 85 | + |
| 86 | + |
| 87 | +def test_assess_policy_deny(): |
| 88 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 89 | + result = client.assess(TEST_ADDRESS, policy={"min_score": 999}) |
| 90 | + |
| 91 | + assert result["decision"] == "deny" |
| 92 | + assert len(result["decision_reasons"]) > 0 |
| 93 | + |
| 94 | + |
| 95 | +def test_get_reputation_operator_score(): |
| 96 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 97 | + rep = client.get_reputation(TEST_ADDRESS) |
| 98 | + |
| 99 | + if "operator_score" in rep and rep["operator_score"]: |
| 100 | + op = rep["operator_score"] |
| 101 | + assert isinstance(op["score"], int) |
| 102 | + assert isinstance(op["grade"], str) |
| 103 | + assert isinstance(op["agent_count"], int) |
| 104 | + assert isinstance(op["chains_active"], list) |
| 105 | + |
| 106 | + |
| 107 | +def test_get_reputation_reputation_field(): |
| 108 | + client = AgentScore(api_key=API_KEY, base_url=BASE_URL) |
| 109 | + rep = client.get_reputation(TEST_ADDRESS) |
| 110 | + |
| 111 | + if "reputation" in rep and rep["reputation"]: |
| 112 | + r = rep["reputation"] |
| 113 | + assert isinstance(r["feedback_count"], int) |
| 114 | + assert isinstance(r["client_count"], int) |
0 commit comments