|
| 1 | +"""tests/test_memory_surfaces.py — the memory faculty's corpus (PyAutoBrain#239). |
| 2 | +
|
| 3 | +First regression net for `agents/faculties/memory/_memory.py`. What matters: |
| 4 | +the root entry surfaces (index.md, reading-queue.md, bibliography/README.md, |
| 5 | +wiki/CLAUDE.md) are part of the corpus — they were invisible before #239 even |
| 6 | +though PyAutoMemory/AGENTS.md tells every agent to index them first; surface |
| 7 | +labels stay repo-name-first (digest()'s exit-4 logic splits on '/'); ranking |
| 8 | +and the no-hits path behave; and the conductors' printed PyAutoMemory pointers |
| 9 | +name paths that exist under the wiki/<domain>/ layout. |
| 10 | +""" |
| 11 | + |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import sys |
| 15 | +from pathlib import Path |
| 16 | + |
| 17 | +sys.path.insert(0, str(Path(__file__).resolve().parents[1] |
| 18 | + / "agents" / "faculties" / "memory")) |
| 19 | + |
| 20 | +import _memory # noqa: E402 |
| 21 | + |
| 22 | + |
| 23 | +def _memory_repo(tmp_path: Path) -> Path: |
| 24 | + m = tmp_path / "PyAutoMemory" |
| 25 | + (m / "wiki" / "demo" / "concepts").mkdir(parents=True) |
| 26 | + (m / "bibliography").mkdir() |
| 27 | + (m / "index.md").write_text("# Index\nthe entry surface mentions quasars\n") |
| 28 | + (m / "reading-queue.md").write_text("# Reading queue\n\nquasar paper one\n") |
| 29 | + (m / "bibliography" / "README.md").write_text("# Bib\nadding a quasar paper\n") |
| 30 | + (m / "wiki" / "CLAUDE.md").write_text("# Schema\nstatus flags\n") |
| 31 | + (m / "wiki" / "demo" / "concepts" / "quasars.md").write_text( |
| 32 | + "---\nstatus: drafted\n---\nquasars lens light\n") |
| 33 | + return m |
| 34 | + |
| 35 | + |
| 36 | +def test_root_entry_surfaces_are_in_the_corpus(tmp_path): |
| 37 | + m = _memory_repo(tmp_path) |
| 38 | + triples = list(_memory.surfaces(m, None, None)) |
| 39 | + root_files = {f.name for name, _, f in triples if name == "PyAutoMemory/root"} |
| 40 | + assert root_files == {"index.md", "reading-queue.md", "README.md", "CLAUDE.md"} |
| 41 | + # the wiki pages still arrive under their sub-wiki label |
| 42 | + assert any(name == "PyAutoMemory/demo" for name, _, _ in triples) |
| 43 | + |
| 44 | + |
| 45 | +def test_labels_stay_repo_name_first(tmp_path): |
| 46 | + m = _memory_repo(tmp_path) |
| 47 | + for name, _, _ in _memory.surfaces(m, None, None): |
| 48 | + assert name.split("/")[0] == "PyAutoMemory" |
| 49 | + |
| 50 | + |
| 51 | +def test_digest_ranks_and_cites_the_queue(tmp_path): |
| 52 | + m = _memory_repo(tmp_path) |
| 53 | + d = _memory.digest("quasar reading queue", m, None, None, limit=8) |
| 54 | + assert d["surfaces_present"] == ["PyAutoMemory"] |
| 55 | + pages = {p["page"] for p in d["pages"]} |
| 56 | + assert "reading-queue.md" in pages |
| 57 | + assert all(p["hits"] >= 1 and p["snippets"] for p in d["pages"]) |
| 58 | + |
| 59 | + |
| 60 | +def test_no_hits_yields_empty_pages(tmp_path): |
| 61 | + m = _memory_repo(tmp_path) |
| 62 | + d = _memory.digest("nonexistent-elephant-topic", m, None, None, limit=8) |
| 63 | + assert d["pages"] == [] and d["surfaces_present"] == ["PyAutoMemory"] |
| 64 | + |
| 65 | + |
| 66 | +def test_bib_file_itself_is_not_a_surface(tmp_path): |
| 67 | + m = _memory_repo(tmp_path) |
| 68 | + (m / "bibliography" / "demo.bib").write_text("@article{Quasar2020}\n") |
| 69 | + files = {f.name for _, _, f in _memory.surfaces(m, None, None)} |
| 70 | + assert "demo.bib" not in files # metadata, not digest text (by design) |
| 71 | + |
| 72 | + |
| 73 | +def test_conductor_pointers_name_real_layout_paths(tmp_path): |
| 74 | + """The feature/bug conductors print `PyAutoMemory/wiki/<d>/index.md` |
| 75 | + pointers built from the policy wiki names — those names must be the |
| 76 | + wiki/<domain>/ layout, and the printed shape must resolve in a real |
| 77 | + checkout when one is present.""" |
| 78 | + sys.path.insert(0, str(Path(__file__).resolve().parents[1] |
| 79 | + / "agents" / "faculties" / "sizing")) |
| 80 | + import _sizing |
| 81 | + live = Path(__file__).resolve().parents[2] / "PyAutoMemory" |
| 82 | + for wiki in _sizing.MEMORY_WIKIS: |
| 83 | + assert not wiki.endswith("_wiki") |
| 84 | + if live.is_dir(): |
| 85 | + assert (live / "wiki" / wiki / "index.md").is_file(), ( |
| 86 | + f"policy names sub-wiki '{wiki}' but " |
| 87 | + f"PyAutoMemory/wiki/{wiki}/index.md does not exist") |
0 commit comments