Skip to content

Commit 3d9021f

Browse files
fix(dm): key .dmf element ids on the window name, not its node id
extract_dmf minted each element id from its window's node id, which already embeds the file stem. The stem is absolute at extraction time and extract()'s id remap only rewrites the leading copy, so the nested copy kept the checkout path and the OS username inside every element id. Use the window name instead. Element ids no longer depend on where the repo is checked out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B8gwEpjajiWHVW3c9smuKf
1 parent 5c7b847 commit 3d9021f

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

‎graphify/extractors/dm.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ def extract_dmf(path: Path) -> dict:
449449
seen: set[str] = {file_nid}
450450

451451
current_window_nid: str | None = None
452+
current_window_name: str | None = None
452453
current_elem_nid: str | None = None
453454
current_elem_name: str | None = None
454455

@@ -465,13 +466,19 @@ def extract_dmf(path: Path) -> dict:
465466
"confidence": "EXTRACTED", "source_file": str_path,
466467
"source_location": f"L{line_idx}", "weight": 1.0})
467468
current_window_nid = nid
469+
current_window_name = name
468470
current_elem_nid = None
469471
current_elem_name = None
470472
continue
471473
m = _DMF_ELEM_RE.match(line)
472-
if m and current_window_nid is not None:
474+
if m and current_window_nid is not None and current_window_name is not None:
473475
name = m.group(1)
474-
nid = _make_id(stem, "elem", current_window_nid, name)
476+
# Key on the window NAME, not its node id: the id already embeds
477+
# `stem`, which is absolute at extraction time. extract()'s
478+
# id-remap only rewrites the leading stem, so the copy nested in
479+
# the middle kept the checkout path (and OS username) in every
480+
# element id.
481+
nid = _make_id(stem, "elem", current_window_name, name)
475482
if nid not in seen:
476483
seen.add(nid)
477484
nodes.append({"id": nid, "label": f'elem "{name}"', "file_type": "code",

‎tests/test_languages.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3913,6 +3913,25 @@ def test_dmf_no_dangling_edges():
39133913
assert e["source"] in node_ids
39143914
assert e["target"] in node_ids
39153915

3916+
def test_dmf_element_ids_do_not_depend_on_the_checkout_path(tmp_path):
3917+
"""An element id was minted from its window's node id, which embeds the
3918+
absolute stem; extract()'s id-remap only rewrites the leading stem, so the
3919+
checkout path (and OS username) survived inside every element id."""
3920+
import shutil
3921+
from graphify.extract import extract
3922+
3923+
def ids_for(checkout):
3924+
(checkout / "ui").mkdir(parents=True)
3925+
shutil.copy(FIXTURES / "sample.dmf", checkout / "ui" / "skin.dmf")
3926+
r = extract([checkout / "ui" / "skin.dmf"], root=checkout, cache_root=checkout)
3927+
return {n["id"] for n in r["nodes"]}
3928+
3929+
first = ids_for(tmp_path / "clone_one")
3930+
second = ids_for(tmp_path / "elsewhere" / "clone_two")
3931+
assert any("elem" in i for i in first)
3932+
assert first == second
3933+
assert not [i for i in first if "clone_one" in i or "elsewhere" in i]
3934+
39163935

39173936
# -- .NET project files (.sln, .csproj, .xaml, .razor) ------------------------
39183937

0 commit comments

Comments
 (0)