from app.entities import ( fallback_profile, normalize_profile, parse_mint_response, signature_from_anomalies, ) def _anomaly(freq, mag): return {"source": "radio", "frequency": freq, "magnitude": mag} def test_signature_needs_enough_anomalies(): assert signature_from_anomalies([_anomaly(101.1, 5.0)]) is None assert signature_from_anomalies([]) is None def test_signature_is_deterministic_for_same_pattern(): anomalies = [_anomaly(101.1 + i, 5.0 + i) for i in range(6)] assert signature_from_anomalies(anomalies) == signature_from_anomalies(list(anomalies)) def test_parse_mint_response_extracts_json(): raw = 'Sure! Here you go:\n{"name": "Vesper Wren", "epithet": "the Static Widow"}\nHope that helps' profile = parse_mint_response(raw) assert profile is not None assert profile["name"] == "Vesper Wren" def test_parse_mint_response_rejects_garbage(): assert parse_mint_response("no json here at all") is None assert parse_mint_response('{"epithet": "nameless"}') is None def test_normalize_profile_fills_and_clamps(): profile = normalize_profile( { "name": " Hollow Briar ", "rarity": "legendary", # not a real tier -> common "voice": {"voice_id": "nonexistent", "pitch": 99, "noise": -5}, "visual": {"form": "dragon", "hue": 9999}, "quotes": ["one", 2, "three"], }, "abcdef0123456789", ) assert profile["name"] == "Hollow Briar" assert profile["rarity"] == "common" assert profile["voice"]["voice_id"] != "nonexistent" assert -6 <= profile["voice"]["pitch"] <= 6 assert 0.01 <= profile["voice"]["noise"] <= 0.08 assert profile["visual"]["form"] in ("wisp", "banshee", "fairy", "shade") assert 0 <= profile["visual"]["hue"] <= 360 assert profile["quotes"] == ["one", "three"] def test_fallback_profile_is_deterministic_and_valid(): one = fallback_profile("0123456789abcdef") two = fallback_profile("0123456789abcdef") assert one == two assert one["name"] assert one["rarity"] in ("common", "uncommon", "rare", "mythic") assert one["quotes"]