fractus-vorax / tests /test_repl.py
thefinalboss's picture
Fractus-Vorax v1.0.0 — the takeover: sealed CTE brain + ingestion organs + mechanical speech (199 tests, honest floors)
1da7ac7 verified
Raw
History Blame Contribute Delete
2.09 kB
# tests/test_repl.py
from pathlib import Path
from fractus_vorax.agent.repl import Repl
CSV = ("question,answer\n"
"what is the capital of france,paris\n"
"what is the capital of spain,madrid\n"
"what is the capital of japan,tokyo\n"
"what is the capital of italy,rome\n"
"who wrote hamlet,william shakespeare\n")
def _repl(tmp_path):
csv = tmp_path / "cap.csv"
csv.write_text(CSV, encoding="utf-8")
r = Repl(tmp_path / "brain", D=2048)
return r, csv
def test_ingest_and_ask(tmp_path):
r, csv = _repl(tmp_path)
out = r.feed(f":ingest {csv}")
assert any("expert" in l for l in out)
out = r.feed("what is the capital of japan")
assert any("[CARTE]" in l and "tokyo" in l for l in out)
def test_conversation_feeds_brain(tmp_path):
r, csv = _repl(tmp_path)
r.feed(f":ingest {csv}")
n0 = len(r.brain)
r.feed("who wrote hamlet")
assert len(r.brain) == n0 + 1 # échange écrit O(1)
assert r.brain.atoms[-1].provenance == "session"
out = r.feed(":status")
assert any("atomes" in l for l in out)
def test_quit_and_unknown(tmp_path):
r, _ = _repl(tmp_path)
assert r.feed(":quit") == []
out = r.feed("zzz nothing here")
assert any("LACUNE" in l or "[CARTE]" in l for l in out)
def test_core_command_degrades_gracefully(tmp_path):
# Sans torch OU avec un checkpoint inexistant : jamais de traceback,
# toujours une ligne honnête "[NOYAU] indisponible: ...".
r, _ = _repl(tmp_path)
out = r.feed(f":core {tmp_path / 'nope.pt'}")
assert any("[NOYAU] indisponible" in l for l in out)
assert r.core is None
def test_core_uses_bpe_when_available(tmp_path, capsys):
from fractus_vorax.model.bpe_tokenizer import bpe_available
r, _ = _repl(tmp_path)
fake_ckpt = tmp_path / "nope.pt"
out = r.feed(f":core {fake_ckpt}")
# sans torch ou fichier absent : dégradation propre déjà testée en P3-T5 ;
# ici on vérifie juste qu'aucun crash tokenizer ne fuit
assert all(isinstance(l, str) for l in out)