File size: 2,087 Bytes
1da7ac7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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)