diff --git a/sumd/pipeline.py b/sumd/pipeline.py index ca90e18..76f1adf 100644 --- a/sumd/pipeline.py +++ b/sumd/pipeline.py @@ -60,6 +60,11 @@ def _map_module_count(text: str) -> int: return int(m.group(1)) if m else -1 +def _is_code2llm_owned_map(text: str) -> bool: + """Return whether the canonical map declares code2llm ownership.""" + return "# producer: code2llm | artifact: map.toon.yaml" in text[:2048] + + def _refresh_map_toon(proj_dir: Path) -> None: """Regenerate project/map.toon.yaml and project/logic.pl from current source before embedding. @@ -82,7 +87,9 @@ def _refresh_map_toon(proj_dir: Path) -> None: regresses = False if map_path.exists(): existing = map_path.read_text(encoding="utf-8", errors="ignore") - regresses = _map_module_count(existing) > _map_module_count(content) + regresses = _is_code2llm_owned_map(existing) or ( + _map_module_count(existing) > _map_module_count(content) + ) if not regresses: map_path.parent.mkdir(parents=True, exist_ok=True) map_path.write_text(content, encoding="utf-8") diff --git a/tests/test_pipeline.py b/tests/test_pipeline.py index def2bdc..73f2f1b 100644 --- a/tests/test_pipeline.py +++ b/tests/test_pipeline.py @@ -130,6 +130,22 @@ def test_refresh_map_toon_writes_file(tmp_path: Path): assert True # no exception = pass +def test_refresh_map_toon_preserves_code2llm_owned_artifact(tmp_path: Path): + project_dir = tmp_path / "project" + project_dir.mkdir() + map_path = project_dir / "map.toon.yaml" + canonical = ( + "# demo | 2f 10L | python:2 | 2026-07-18\n" + "# producer: code2llm | artifact: map.toon.yaml | schema: 1\n" + "M[2]:\n app.py,5\n lib.py,5\nD:\n app.py:\n main()\n" + ) + map_path.write_text(canonical, encoding="utf-8") + + _refresh_map_toon(tmp_path) + + assert map_path.read_text(encoding="utf-8") == canonical + + def test_refresh_analysis_files_noop_without_tools(tmp_path: Path): # No .sumd-tools/venv → must complete without raising _refresh_analysis_files(tmp_path, "refactor")