feat: spirit engine — seance WS, entity minting/Codex, Piper TTS voices, wire telemetry

- WS /ws/session: modes, summon, anomaly fragments, streaming direct contact,
  passive wire-ghost ambient loop, per-user rate limits, event transcript
- entities: anomaly-signature fingerprinting, LLM minting + procedural
  fallback, Codex matching with contact counts and sightings
- tts: 8 local Piper voices (EN/ES), per-entity voice profiles, numpy
  effects chain (pitch/rate/bitcrush/echo/static)
- llm: streaming client, submit_stream in bounded queue, SpiritService
  with offline fallbacks for every channel
- routes: public /api/codex, /api/codex/{id}, /api/stats; /audio static mount
- models: Entity, EntitySighting, Event, ContactSession(entity_id, language)
This commit is contained in:
Indiana
2026-07-20 20:13:28 +00:00
parent 52afad1ad5
commit b9110f45de
28 changed files with 1997 additions and 4 deletions

View File

@@ -0,0 +1,62 @@
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"]