fix: scope hallway reads and deletion to selected palace
This commit is contained in:
parent
f68cb8d682
commit
287d8f1b4d
|
|
@ -1005,7 +1005,15 @@ def cmd_hallways(args):
|
|||
"""List within-wing entity hallways (the auto-built associative graph)."""
|
||||
from .hallways import list_hallways
|
||||
|
||||
rows = list_hallways(getattr(args, "wing", None))
|
||||
palace_path = (
|
||||
os.path.expanduser(args.palace)
|
||||
if getattr(args, "palace", None)
|
||||
else MempalaceConfig().palace_path
|
||||
)
|
||||
rows = list_hallways(
|
||||
getattr(args, "wing", None),
|
||||
config=MempalaceConfig(palace_path=palace_path),
|
||||
)
|
||||
if not rows:
|
||||
print("No hallways yet — they are built from drawer entities when you mine.")
|
||||
return
|
||||
|
|
|
|||
|
|
@ -383,11 +383,11 @@ def list_hallways(wing: Optional[str] = None, config=None) -> list[dict]:
|
|||
return [h for h in all_hallways if h.get("wing") == wing]
|
||||
|
||||
|
||||
def delete_hallway(hallway_id: str) -> bool:
|
||||
def delete_hallway(hallway_id: str, config=None) -> bool:
|
||||
"""Remove one hallway record by id. Returns True if a record was removed."""
|
||||
hallways = _load_hallways()
|
||||
hallways = _load_hallways(config)
|
||||
filtered = [h for h in hallways if h.get("id") != hallway_id]
|
||||
if len(filtered) == len(hallways):
|
||||
return False
|
||||
_save_hallways(filtered)
|
||||
_save_hallways(filtered, config)
|
||||
return True
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ def test_lists_sorted_by_count(monkeypatch, capsys):
|
|||
"label": "A <-> B (x3)",
|
||||
},
|
||||
]
|
||||
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None: list(rows))
|
||||
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None, config=None: list(rows))
|
||||
cmd_hallways(Namespace(wing=None, limit=50))
|
||||
out = capsys.readouterr().out
|
||||
assert "2 hallway(s)" in out
|
||||
|
|
@ -37,7 +37,7 @@ def test_respects_limit(monkeypatch, capsys):
|
|||
{"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))
|
||||
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None, config=None: list(rows))
|
||||
cmd_hallways(Namespace(wing=None, limit=2))
|
||||
assert capsys.readouterr().out.count("<->") == 2
|
||||
|
||||
|
|
@ -47,13 +47,28 @@ def test_negative_limit_shows_nothing_not_tail(monkeypatch, capsys):
|
|||
{"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))
|
||||
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None, config=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: [])
|
||||
monkeypatch.setattr(hallways_mod, "list_hallways", lambda wing=None, config=None: [])
|
||||
cmd_hallways(Namespace(wing="x", limit=50))
|
||||
assert "No hallways yet" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_explicit_palace_scopes_hallway_listing(monkeypatch, tmp_path):
|
||||
calls = []
|
||||
|
||||
def fake_list(wing=None, config=None):
|
||||
calls.append((wing, config.palace_path))
|
||||
return []
|
||||
|
||||
selected = tmp_path / "selected" / "palace"
|
||||
monkeypatch.setattr(hallways_mod, "list_hallways", fake_list)
|
||||
|
||||
cmd_hallways(Namespace(wing="wing_aya", limit=50, palace=str(selected)))
|
||||
|
||||
assert calls == [("wing_aya", str(selected))]
|
||||
|
|
|
|||
|
|
@ -318,6 +318,19 @@ class TestHallwayQuery:
|
|||
hallways_mod._save_hallways([{"id": "h1", "wing": "wing_aya"}])
|
||||
assert hallways_mod.delete_hallway("nonexistent") is False
|
||||
|
||||
def test_delete_hallway_uses_selected_palace_config(self, tmp_path):
|
||||
from mempalace.config import MempalaceConfig
|
||||
|
||||
default_cfg = MempalaceConfig(palace_path=tmp_path / "default" / "palace")
|
||||
selected_cfg = MempalaceConfig(palace_path=tmp_path / "selected" / "palace")
|
||||
record = {"id": "h1", "wing": "wing_aya"}
|
||||
hallways_mod._save_hallways([record], default_cfg)
|
||||
hallways_mod._save_hallways([record], selected_cfg)
|
||||
|
||||
assert hallways_mod.delete_hallway("h1", config=selected_cfg) is True
|
||||
assert hallways_mod.list_hallways(config=selected_cfg) == []
|
||||
assert hallways_mod.list_hallways(config=default_cfg) == [record]
|
||||
|
||||
|
||||
# ─────────────────────────────────────────────────────────────────────────────
|
||||
# L7 dynamics integration — hallway records carry strength/stability/etc
|
||||
|
|
|
|||
Loading…
Reference in New Issue