from pathlib import Path from trends_mcp.aliases import normalize_entity from trends_mcp import ledger def test_normalize_entity_maps_bitcoin_to_btc(): assert normalize_entity("bitcoin") == "BTC" def test_store_snapshot_persists_payload(tmp_path, monkeypatch): monkeypatch.setattr(ledger, "DB_PATH", tmp_path / "trends_history.db") ledger.store_snapshot( tool="resolve_entity", keyword="bitcoin", normalized_keyword="BTC", mid="/m/05p0rrx", canonical_label="Bitcoin", payload={"keyword": "bitcoin", "canonical_label": "Bitcoin"}, ) rows = ledger.read_recent(10) assert rows[0]["tool"] == "resolve_entity" assert rows[0]["payload"]["canonical_label"] == "Bitcoin" def test_entity_history_matches_keyword(tmp_path, monkeypatch): monkeypatch.setattr(ledger, "DB_PATH", tmp_path / "trends_history.db") ledger.store_snapshot(tool="resolve_entity", keyword="bitcoin", normalized_keyword="BTC", mid="/m/05p0rrx", canonical_label="Bitcoin", payload={"keyword": "bitcoin"}) ledger.store_snapshot(tool="get_related_queries", keyword="bitcoin", normalized_keyword="BTC", mid=None, canonical_label=None, payload={"keyword": "bitcoin"}) history = ledger.entity_history("BTC") assert history["count"] == 2