Repository navigation
fix(build): honor disabled same-file semantic deduplication #4122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
xiehuanyi
wants to merge
1
commit into
Graphify-Labs:v8
from
xiehuanyi:fix/located-semantic-node-identity
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import json | ||
|
|
||
| import pytest | ||
|
|
||
| from graphify.build import build, build_from_json, build_merge | ||
|
|
||
|
|
||
| def _located_nodes(): | ||
| return [ | ||
| {"id": "pkg_name", "label": "name", "file_type": "code", | ||
| "source_file": "pkg/plugin.json", "source_location": "L2"}, | ||
| {"id": "pkg_author_name", "label": "name", "file_type": "code", | ||
| "source_file": "pkg/plugin.json", "source_location": "L5"}, | ||
| {"id": "doc_s1_notes", "label": "Notas", "file_type": "document", | ||
| "source_file": "docs/plan.md", "source_location": "L10"}, | ||
| {"id": "doc_s2_notes", "label": "Notas", "file_type": "document", | ||
| "source_file": "docs/plan.md", "source_location": "L80"}, | ||
| {"id": "other_name", "label": "name", "file_type": "code", | ||
| "source_file": "pkg/other.json", "source_location": "L2"}, | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("reverse", [False, True]) | ||
| def test_distinct_same_file_locations_preserve_ids_and_edges(reverse): | ||
| nodes = _located_nodes() | ||
| if reverse: | ||
| nodes.reverse() | ||
| graph = build_from_json({ | ||
| "nodes": nodes, | ||
| "edges": [ | ||
| {"source": "pkg_name", "target": "doc_s1_notes", "relation": "references"}, | ||
| {"source": "pkg_author_name", "target": "doc_s2_notes", "relation": "references"}, | ||
| ], | ||
| "hyperedges": [], | ||
| }, dedup=False) | ||
| assert set(graph.nodes) == {node["id"] for node in nodes} | ||
| assert graph.has_edge("pkg_name", "doc_s1_notes") | ||
| assert graph.has_edge("pkg_author_name", "doc_s2_notes") | ||
|
|
||
|
|
||
| def test_empty_no_dedup_merge_keeps_located_graph(tmp_path): | ||
| nodes = _located_nodes() | ||
| graph_path = tmp_path / "graph.json" | ||
| graph_path.write_text(json.dumps({"nodes": nodes, "edges": [], "hyperedges": []}), encoding="utf-8") | ||
| graph = build_merge([{"nodes": [], "edges": [], "hyperedges": []}], graph_path, dedup=False) | ||
| assert set(graph.nodes) == {node["id"] for node in nodes} | ||
|
|
||
|
|
||
| def test_disabled_dedup_keeps_distinct_semantic_ids_at_identical_locations(): | ||
| nodes = [ | ||
| {"id": name, "label": "Notes", "file_type": "document", "_origin": "semantic", | ||
| "source_file": "plan.md", "source_location": location} | ||
| for name, location in [("a_first", "L2"), ("b_second", "L5"), ("z_first", "L2"), ("z_second", "L5")] | ||
| ] | ||
| graph = build_from_json({ | ||
| "nodes": nodes, | ||
| "edges": [{"source": "z_first", "target": "z_second", "relation": "references"}], | ||
| "hyperedges": [], | ||
| }, dedup=False) | ||
| assert set(graph.nodes) == {node["id"] for node in nodes} | ||
| assert graph.has_edge("z_first", "z_second") | ||
|
|
||
|
|
||
| def test_ast_twin_remains_canonical_despite_semantic_location_drift(): | ||
| graph = build_from_json({ | ||
| "nodes": [ | ||
| {"id": "src_render", "label": "render", "file_type": "code", "_origin": "ast", | ||
| "source_file": "src/view.py", "source_location": "L2"}, | ||
| {"id": "view_render", "label": "render", "file_type": "code", "_origin": "semantic", | ||
| "source_file": "src/view.py", "source_location": "L5"}, | ||
| ], | ||
| "edges": [], "hyperedges": [], | ||
| }, dedup=False) | ||
| assert set(graph.nodes) == {"src_render"} | ||
|
|
||
|
|
||
| def test_full_build_honors_disabled_semantic_dedup(): | ||
| nodes = _located_nodes() | ||
| graph = build([{"nodes": nodes, "edges": [], "hyperedges": []}], dedup=False) | ||
| assert set(graph.nodes) == {node["id"] for node in nodes} | ||
|
|
||
|
|
||
| def test_fresh_merge_honors_disabled_semantic_dedup(tmp_path): | ||
| graph_path = tmp_path / "graph.json" | ||
| graph_path.write_text(json.dumps({"nodes": [], "edges": [], "hyperedges": []}), encoding="utf-8") | ||
| nodes = _located_nodes() | ||
| graph = build_merge([{"nodes": nodes, "edges": [], "hyperedges": []}], graph_path, dedup=False) | ||
| assert set(graph.nodes) == {node["id"] for node in nodes} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build_from_json()fans out to 20 callees (efferent coupling); 231 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.