161 lines
4.5 KiB
Python
161 lines
4.5 KiB
Python
"""
|
|
Tests for mempalace/validate_rooms.py — fleet room taxonomy validator.
|
|
|
|
Refs: #1082, #1075
|
|
"""
|
|
|
|
import json
|
|
import textwrap
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
from mempalace.validate_rooms import (
|
|
get_core_room_keys,
|
|
get_wizard_room_keys,
|
|
validate,
|
|
)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Helpers
|
|
# ---------------------------------------------------------------------------
|
|
|
|
STANDARD_YAML = textwrap.dedent("""\
|
|
version: "1"
|
|
core_rooms:
|
|
- key: forge
|
|
label: Forge
|
|
purpose: CI and builds
|
|
- key: hermes
|
|
label: Hermes
|
|
purpose: Agent platform
|
|
- key: nexus
|
|
label: Nexus
|
|
purpose: Reports and docs
|
|
- key: issues
|
|
label: Issues
|
|
purpose: Tickets and backlog
|
|
- key: experiments
|
|
label: Experiments
|
|
purpose: Prototypes and spikes
|
|
""")
|
|
|
|
|
|
def write_standard(tmp_path: Path) -> Path:
|
|
p = tmp_path / "rooms.yaml"
|
|
p.write_text(STANDARD_YAML)
|
|
return p
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# get_core_room_keys
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_get_core_room_keys_returns_all_keys(tmp_path):
|
|
standard_path = write_standard(tmp_path)
|
|
standard = yaml.safe_load(standard_path.read_text())
|
|
keys = get_core_room_keys(standard)
|
|
assert keys == ["forge", "hermes", "nexus", "issues", "experiments"]
|
|
|
|
|
|
def test_get_core_room_keys_empty_if_no_core_rooms():
|
|
keys = get_core_room_keys({})
|
|
assert keys == []
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# get_wizard_room_keys
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_get_wizard_room_keys_list_style():
|
|
config = {
|
|
"rooms": [
|
|
{"key": "forge"},
|
|
{"key": "hermes"},
|
|
]
|
|
}
|
|
assert get_wizard_room_keys(config) == ["forge", "hermes"]
|
|
|
|
|
|
def test_get_wizard_room_keys_dict_style():
|
|
config = {
|
|
"rooms": {
|
|
"forge": {"purpose": "builds"},
|
|
"nexus": {"purpose": "docs"},
|
|
}
|
|
}
|
|
keys = get_wizard_room_keys(config)
|
|
assert set(keys) == {"forge", "nexus"}
|
|
|
|
|
|
def test_get_wizard_room_keys_empty_config():
|
|
assert get_wizard_room_keys({}) == []
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# validate — happy path
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_validate_passes_with_all_core_rooms(tmp_path):
|
|
standard_path = write_standard(tmp_path)
|
|
wizard_config = tmp_path / "mempalace.yaml"
|
|
wizard_config.write_text(textwrap.dedent("""\
|
|
rooms:
|
|
- key: forge
|
|
- key: hermes
|
|
- key: nexus
|
|
- key: issues
|
|
- key: experiments
|
|
"""))
|
|
errors = validate(wizard_config, standard_path)
|
|
assert errors == []
|
|
|
|
|
|
def test_validate_passes_with_extra_rooms(tmp_path):
|
|
standard_path = write_standard(tmp_path)
|
|
wizard_config = tmp_path / "mempalace.yaml"
|
|
wizard_config.write_text(textwrap.dedent("""\
|
|
rooms:
|
|
- key: forge
|
|
- key: hermes
|
|
- key: nexus
|
|
- key: issues
|
|
- key: experiments
|
|
- key: evennia
|
|
- key: workspace
|
|
"""))
|
|
errors = validate(wizard_config, standard_path)
|
|
assert errors == []
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# validate — failure cases
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_validate_reports_missing_core_rooms(tmp_path):
|
|
standard_path = write_standard(tmp_path)
|
|
wizard_config = tmp_path / "mempalace.yaml"
|
|
wizard_config.write_text(textwrap.dedent("""\
|
|
rooms:
|
|
- key: forge
|
|
"""))
|
|
errors = validate(wizard_config, standard_path)
|
|
missing_keys = [e for e in errors if "hermes" in e or "nexus" in e or "issues" in e or "experiments" in e]
|
|
assert len(missing_keys) == 4
|
|
|
|
|
|
def test_validate_missing_wizard_config(tmp_path):
|
|
standard_path = write_standard(tmp_path)
|
|
missing = tmp_path / "nonexistent.yaml"
|
|
errors = validate(missing, standard_path)
|
|
assert any("not found" in e for e in errors)
|
|
|
|
|
|
def test_validate_missing_standard(tmp_path):
|
|
wizard_config = tmp_path / "mempalace.yaml"
|
|
wizard_config.write_text("rooms:\n - key: forge\n")
|
|
missing_standard = tmp_path / "no_such_rooms.yaml"
|
|
errors = validate(wizard_config, missing_standard)
|
|
assert any("not found" in e for e in errors)
|