Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion mempalace/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ def normalize_wing_name(name: str) -> str:
The same rule is applied by ``init`` when persisting `topics_by_wing`
and when writing `mempalace.yaml`, so the miner's lookup matches at
mine time regardless of the source dirname.

Leading/trailing separators are stripped so a path-encoded dirname like
``-home-user-proj`` yields ``home_user_proj`` rather than a leading-
underscore slug that ``sanitize_name`` (and thus the MCP write tools)
would reject.
"""
return name.lower().replace(" ", "_").replace("-", "_")
return name.lower().replace(" ", "_").replace("-", "_").strip("_")


def sanitize_name(value: str, field_name: str = "name") -> str:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ def test_normalize_wing_name_mixed():
assert normalize_wing_name("My-Cool App") == "my_cool_app"


def test_normalize_wing_name_strips_leading_separator():
# Claude Code path-encoded project dirs begin with a separator; the slug
# must not start with "_" or sanitize_name / MCP writes would reject it.
assert normalize_wing_name("-home-user-linux-book") == "home_user_linux_book"


def test_normalize_wing_name_strips_trailing_separator():
assert normalize_wing_name("project-") == "project"


# --- sanitize_name ---


Expand Down
8 changes: 7 additions & 1 deletion tests/test_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest
import yaml

from mempalace.config import normalize_wing_name
from mempalace.miner import detect_room, load_config, mine, scan_project, status
from mempalace.palace import NORMALIZE_VERSION, file_already_mined, prefetch_mined_set

Expand Down Expand Up @@ -257,7 +258,12 @@ def test_load_config_uses_defaults_when_yaml_missing():
assert isinstance(config, dict)
assert "wing" in config
assert "rooms" in config
assert config["wing"] == project_root.name
# The default wing is the normalized dirname, not the raw name: temp
# dir names can contain leading/trailing '_' (tempfile's alphabet
# includes it), which normalize_wing_name strips. Comparing to the raw
# name was flaky across platforms (it only passed when the random name
# had no separators).
assert config["wing"] == normalize_wing_name(project_root.name)
finally:
shutil.rmtree(tmpdir)

Expand Down