Spaces:
Running
Running
| import sqlite3, json | |
| from app.relation import RelationStore | |
| def _db(tmp_path): | |
| p = str(tmp_path / "soul.db"); sqlite3.connect(p).close(); return p | |
| def test_affinity_updates_toward_reads(tmp_path): | |
| r = RelationStore(_db(tmp_path)) | |
| assert r.affinity("nope") is None # unknown -> None | |
| r.observe("uid1", [20, 200, 90, 40, 150, 30, 180]) # harsh | |
| aff = r.affinity("uid1") | |
| assert len(aff) == 7 and aff[0] < 128 # skews negative | |
| r.observe("uid1", [30, 190, 85, 50, 150, 35, 175]) # harsh again | |
| assert r.affinity("uid1")[0] < 128 # stays negative | |
| def test_flashbulb_is_most_intense_and_textless(tmp_path): | |
| r = RelationStore(_db(tmp_path)) | |
| r.observe("uid1", [120, 130, 128, 60, 130, 120, 130], mood_word="calm") # mild | |
| r.observe("uid1", [10, 215, 80, 70, 165, 18, 195], mood_word="furious") # intense | |
| fb = r.flashbulb("uid1") | |
| assert fb["mood_word"] == "furious" and len(fb["read"]) == 7 and "ts" in fb | |
| assert "text" not in fb and "message" not in fb and "words" not in fb # NO raw text | |
| # schema has no text/username columns | |
| cols = [c[1] for c in sqlite3.connect(_db(tmp_path)).execute("pragma table_info(relation)").fetchall()] | |
| assert not any(x in cols for x in ("text", "message", "words", "username", "name")) | |
| def test_known(tmp_path): | |
| r = RelationStore(_db(tmp_path)) | |
| assert r.known("uid1") is False | |
| r.observe("uid1", [128]*7) | |
| assert r.known("uid1") is True | |