Fractus-Vorax v1.0.0 — the takeover: sealed CTE brain + ingestion organs + mechanical speech (199 tests, honest floors)
1da7ac7 verified | # tests/test_kn.py | |
| import gzip | |
| import json | |
| from pathlib import Path | |
| from fractus_vorax.compiler.kn import compile_kn, load_kn, source_sha256 | |
| def _csv(tmp_path): | |
| p = tmp_path / "cap.csv" | |
| p.write_text( | |
| "question,answer\nwhat is the capital of france,paris\nwho wrote hamlet,william shakespeare\n", | |
| encoding="utf-8", | |
| ) | |
| return p | |
| def test_compile_produces_kn_layout(tmp_path): | |
| kn = compile_kn(_csv(tmp_path), tmp_path / "cap.kn") | |
| assert (kn / "manifest.json").exists() | |
| assert (kn / "atoms.tsv.gz").exists() | |
| assert (kn / "signature.bin").exists() | |
| manifest = json.loads((kn / "manifest.json").read_text(encoding="utf-8")) | |
| assert manifest["n_atoms"] == 2 | |
| assert manifest["format_version"] == 1 | |
| assert "created" not in manifest # jamais de timestamp | |
| def test_load_kn_roundtrip(tmp_path): | |
| src = _csv(tmp_path) | |
| kn = compile_kn(src, tmp_path / "cap.kn") | |
| atoms = load_kn(kn) | |
| assert atoms[0].statement == "what is the capital of france" | |
| assert atoms[0].context == "paris" | |
| assert atoms[0].confidence == 1.0 | |
| def test_compile_is_bit_identical(tmp_path): | |
| src = _csv(tmp_path) | |
| k1 = compile_kn(src, tmp_path / "a.kn") | |
| k2 = compile_kn(src, tmp_path / "b.kn") | |
| for name in ("manifest.json", "atoms.tsv.gz", "signature.bin"): | |
| assert (k1 / name).read_bytes() == (k2 / name).read_bytes(), name | |
| def test_source_sha256_stable(tmp_path): | |
| src = _csv(tmp_path) | |
| assert source_sha256(src) == source_sha256(src) | |
| assert len(source_sha256(src)) == 64 | |
| def test_manifest_records_source_hash(tmp_path): | |
| src = _csv(tmp_path) | |
| kn = compile_kn(src, tmp_path / "cap.kn") | |
| manifest = json.loads((kn / "manifest.json").read_text(encoding="utf-8")) | |
| assert manifest["source_sha256"] == source_sha256(src) | |