Skip to content

Commit ab716d0

Browse files
authored
Merge pull request #1675 from M8SON/fix/wing-normalize-strip-sep
fix(config): strip leading/trailing separators in normalize_wing_name
2 parents 708ef4a + ed772a0 commit ab716d0

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

mempalace/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ def normalize_wing_name(name: str) -> str:
3737
The same rule is applied by ``init`` when persisting `topics_by_wing`
3838
and when writing `mempalace.yaml`, so the miner's lookup matches at
3939
mine time regardless of the source dirname.
40+
41+
Leading/trailing separators are stripped so a path-encoded dirname like
42+
``-home-user-proj`` yields ``home_user_proj`` rather than a leading-
43+
underscore slug that ``sanitize_name`` (and thus the MCP write tools)
44+
would reject.
4045
"""
41-
return name.lower().replace(" ", "_").replace("-", "_")
46+
return name.lower().replace(" ", "_").replace("-", "_").strip("_")
4247

4348

4449
def sanitize_name(value: str, field_name: str = "name") -> str:

tests/test_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ def test_normalize_wing_name_mixed():
196196
assert normalize_wing_name("My-Cool App") == "my_cool_app"
197197

198198

199+
def test_normalize_wing_name_strips_leading_separator():
200+
# Claude Code path-encoded project dirs begin with a separator; the slug
201+
# must not start with "_" or sanitize_name / MCP writes would reject it.
202+
assert normalize_wing_name("-home-user-linux-book") == "home_user_linux_book"
203+
204+
205+
def test_normalize_wing_name_strips_trailing_separator():
206+
assert normalize_wing_name("project-") == "project"
207+
208+
199209
# --- sanitize_name ---
200210

201211

tests/test_miner.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pytest
1010
import yaml
1111

12+
from mempalace.config import normalize_wing_name
1213
from mempalace.miner import detect_room, load_config, mine, scan_project, status
1314
from mempalace.palace import NORMALIZE_VERSION, file_already_mined, prefetch_mined_set
1415

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

0 commit comments

Comments
 (0)