Repository navigation
fix(watch): keep placeholder nodes for never-scanned files on incremental rebuilds #4161
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
rohit-jsfreaky
wants to merge
2
commits into
Graphify-Labs:v8
from
rohit-jsfreaky:fix/incremental-keeps-missing-target-placeholders
Closed
Changes from 1 commit
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| """A changed-files rebuild must keep nodes minted for files that never existed. | ||
|
|
||
| An unresolved dynamic import (``import('./queue.js')``) or a project a ``.sln`` | ||
| lists but the checkout lacks makes the REFERRING file emit a node whose | ||
| ``source_file`` is the missing path. The corpus sweep of an incremental | ||
| rebuild read that missing path as a deleted source and evicted the node, so the | ||
| unchanged referrer's edge to it dangled and was dropped; a full rebuild of the | ||
| same tree keeps both. The previous scan (manifest.json) is the deletion | ||
| evidence (#1795): a path it never listed cannot have been deleted. | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
|
|
||
| from graphify.watch import _rebuild_code | ||
|
|
||
|
|
||
| def _graph(corpus: Path) -> dict: | ||
| return json.loads((corpus / "graphify-out" / "graph.json").read_text(encoding="utf-8")) | ||
|
|
||
|
|
||
| def _shape(graph: dict) -> tuple[set, set]: | ||
| drop = ("community", "community_name") | ||
| nodes = {json.dumps({k: v for k, v in n.items() if k not in drop}, sort_keys=True) for n in graph["nodes"]} | ||
| edges = {json.dumps({k: v for k, v in e.items() if k not in drop}, sort_keys=True) | ||
| for e in graph.get("links", graph.get("edges", []))} | ||
| return nodes, edges | ||
|
|
||
|
|
||
| def _corpus(tmp_path: Path) -> Path: | ||
| corpus = tmp_path / "corpus" | ||
| corpus.mkdir() | ||
| (corpus / "app.ts").write_text( | ||
| "export async function load() {\n return import('./queue.js');\n}\n", encoding="utf-8") | ||
| (corpus / "other.ts").write_text("export function other() {\n return 1;\n}\n", encoding="utf-8") | ||
| return corpus | ||
|
|
||
|
|
||
| def _rebuild(corpus: Path, changed: list[str] | None = None) -> None: | ||
| assert _rebuild_code( | ||
| corpus, | ||
| changed_paths=[Path(p) for p in changed] if changed is not None else None, | ||
| no_cluster=True, | ||
| acquire_lock=False, | ||
| force=True, | ||
| ) is True | ||
|
|
||
|
|
||
| def _placeholder_ids(graph: dict) -> set[str]: | ||
| return {n["id"] for n in graph["nodes"] if n.get("source_file", "").endswith("queue.js")} | ||
|
|
||
|
|
||
| def test_placeholder_for_a_missing_import_target_survives_an_unrelated_change(tmp_path): | ||
| corpus = _corpus(tmp_path) | ||
| _rebuild(corpus) | ||
| placeholder = _placeholder_ids(_graph(corpus)) | ||
| assert placeholder, "fixture no longer mints a placeholder for ./queue.js" | ||
|
|
||
| (corpus / "other.ts").write_text("export function other() {\n return 2;\n}\n", encoding="utf-8") | ||
| _rebuild(corpus, ["other.ts"]) | ||
| incremental = _graph(corpus) | ||
|
|
||
| assert _placeholder_ids(incremental) == placeholder | ||
| assert any(e["target"] in placeholder for e in incremental["links"]) | ||
|
|
||
| _rebuild(corpus) | ||
| assert _shape(incremental) == _shape(_graph(corpus)), "incremental graph differs from a full rebuild" | ||
|
|
||
|
|
||
| def test_a_scanned_file_that_was_deleted_is_still_evicted(tmp_path): | ||
| corpus = _corpus(tmp_path) | ||
| _rebuild(corpus) | ||
| assert any(n.get("source_file", "").endswith("other.ts") for n in _graph(corpus)["nodes"]) | ||
|
|
||
| (corpus / "other.ts").unlink() | ||
| _rebuild(corpus, ["other.ts"]) | ||
|
|
||
| assert not [n for n in _graph(corpus)["nodes"] if n.get("source_file", "").endswith("other.ts")] | ||
|
|
||
|
|
||
| def test_without_a_manifest_the_old_eviction_is_kept(tmp_path): | ||
| corpus = _corpus(tmp_path) | ||
| _rebuild(corpus) | ||
| (corpus / "graphify-out" / "manifest.json").unlink() | ||
|
|
||
| (corpus / "other.ts").write_text("export function other() {\n return 2;\n}\n", encoding="utf-8") | ||
| _rebuild(corpus, ["other.ts"]) | ||
|
|
||
| assert not _placeholder_ids(_graph(corpus)) |
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.
_reconcile_existing_graph()fans out to 9 callees (efferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.