* feat(graph): auto-populate the associative graph from mined sessions Conversation mining never set the `entities` drawer metadata that hallways consume, so mined sessions produced an empty associative graph (and starved the entity-navigation / tunnel-recommendation features built on top of it). Add a no-LLM structural entity extractor and wire it into the convos mine: - entities: structural-only extractor (author-quoted code spans, URLs, file paths, qualified identifiers, CamelCase / snake_case symbols). No wordlists, no NLP models, precision-biased so prose doesn't pollute the graph. - convo_miner: set `entities` per chunk, and compute hallways after a convos mine (mirroring the project-file path). Hallways run before the FTS5 validation, which opens a direct sqlite connection that can invalidate the live Chroma collection handle on some Chroma builds. - cli: `mempalace hallways` lists the associative graph (CLI parity with the list_hallways MCP tool). - tests: extractor precision/ranking, entities metadata at mine time, CLI. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * fix(graph): address review — semicolon safety, leading-underscore snake, negative limit - entities `_clean`: strip `;` out of tokens so a URL query string or backtick span can't split the `;`-joined entities metadata field - entities `_SNAKE`: optional leading/trailing `_?` so `_extract_authored_at` and similar are matched in plain text (previously only caught via backticks) - cli `hallways`: clamp `--limit` with max(0, ...) so a negative value shows nothing instead of slicing from the end - tests for all three Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Igor Lins e Silva <4753812+igorls@users.noreply.github.com>
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
"""Tests for the `hallways` CLI command."""
|
|
|
|
from argparse import Namespace
|
|
|
|
import mempalace.hallways as hallways_mod
|
|
from mempalace.cli import cmd_hallways
|
|
|
|
|
|
def test_lists_sorted_by_count(monkeypatch, capsys):
|
|
rows = [
|
|
{
|
|
"entity_a": "C",
|
|
"entity_b": "D",
|
|
"co_occurrence_count": 1,
|
|
"wing": "w",
|
|
"label": "C <-> D (x1)",
|
|
},
|
|
{
|
|
"entity_a": "A",
|
|
"entity_b": "B",
|
|
"co_occurrence_count": 3,
|
|
"wing": "w",
|
|
"label": "A <-> B (x3)",
|
|
},
|
|
]
|
|
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None: list(rows))
|
|
cmd_hallways(Namespace(wing=None, limit=50))
|
|
out = capsys.readouterr().out
|
|
assert "2 hallway(s)" in out
|
|
assert "A <-> B (x3)" in out
|
|
# Highest co-occurrence first.
|
|
assert out.index("A <-> B") < out.index("C <-> D")
|
|
|
|
|
|
def test_respects_limit(monkeypatch, capsys):
|
|
rows = [
|
|
{"entity_a": f"E{i}", "entity_b": "X", "co_occurrence_count": i, "label": f"E{i} <-> X"}
|
|
for i in range(5)
|
|
]
|
|
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None: list(rows))
|
|
cmd_hallways(Namespace(wing=None, limit=2))
|
|
assert capsys.readouterr().out.count("<->") == 2
|
|
|
|
|
|
def test_negative_limit_shows_nothing_not_tail(monkeypatch, capsys):
|
|
rows = [
|
|
{"entity_a": f"E{i}", "entity_b": "X", "co_occurrence_count": i, "label": f"E{i} <-> X"}
|
|
for i in range(5)
|
|
]
|
|
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None: list(rows))
|
|
cmd_hallways(Namespace(wing=None, limit=-2))
|
|
# A negative limit must not slice from the end (which would print all-but-2).
|
|
assert capsys.readouterr().out.count("<->") == 0
|
|
|
|
|
|
def test_empty_message(monkeypatch, capsys):
|
|
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None: [])
|
|
cmd_hallways(Namespace(wing="x", limit=50))
|
|
assert "No hallways yet" in capsys.readouterr().out
|