03e9b57108
Add 180+ new tests across 10 test files covering previously untested modules: - instructions_cli (0% → 100%), hooks_cli (73% → 96%), spellcheck (28% → 84%) - palace_graph (9% → 91%), general_extractor (0% → 92%), entity_detector (0% → 69%) - entity_registry (0% → 70%), room_detector_local (0% → 55%), layers (0% → 28%) - onboarding (0% → 36%) Also fixes Windows encoding bug in onboarding.py (write_text without encoding="utf-8"). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""Tests for mempalace.instructions_cli — instruction text output."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from mempalace.instructions_cli import AVAILABLE, INSTRUCTIONS_DIR, run_instructions
|
|
|
|
|
|
def test_run_instructions_valid_name(capsys):
|
|
"""Valid name prints the .md file content."""
|
|
name = "init"
|
|
expected = (INSTRUCTIONS_DIR / f"{name}.md").read_text()
|
|
run_instructions(name)
|
|
captured = capsys.readouterr()
|
|
assert captured.out.strip() == expected.strip()
|
|
|
|
|
|
def test_run_instructions_all_available(capsys):
|
|
"""Every name in AVAILABLE should succeed without error."""
|
|
for name in AVAILABLE:
|
|
run_instructions(name)
|
|
out = capsys.readouterr().out
|
|
assert len(out) > 0
|
|
|
|
|
|
def test_run_instructions_invalid_name(capsys):
|
|
"""Invalid name should sys.exit(1) and print error to stderr."""
|
|
with pytest.raises(SystemExit) as exc_info:
|
|
run_instructions("nonexistent")
|
|
assert exc_info.value.code == 1
|
|
captured = capsys.readouterr()
|
|
assert "Unknown instructions: nonexistent" in captured.err
|
|
assert "Available:" in captured.err
|
|
|
|
|
|
def test_run_instructions_missing_md_file(capsys, tmp_path):
|
|
"""If the .md file is missing on disk, should sys.exit(1)."""
|
|
with patch("mempalace.instructions_cli.INSTRUCTIONS_DIR", tmp_path):
|
|
with patch("mempalace.instructions_cli.AVAILABLE", ["fakecmd"]):
|
|
with pytest.raises(SystemExit) as exc_info:
|
|
run_instructions("fakecmd")
|
|
assert exc_info.value.code == 1
|
|
captured = capsys.readouterr()
|
|
assert "Instructions file not found" in captured.err
|