Repository navigation
test: cover move MCP wiring #2079
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
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
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,65 @@ | ||
| """`move(qn, target_module)`: edit-algebra operation 3 (issue #1534). | ||
|
|
||
| Moving a symbol out of a shared dumping ground into the one package that | ||
| uses it is the refactor that shrinks affected sets, and by hand it is | ||
| tedious: the definition, its own imports, every importer, re-exports. The | ||
| graph knows the definition's span, the imports its module binds, and every | ||
| importer's statement (issue #1522), so the whole move is one transaction: | ||
|
|
||
| - cut the definition (decorators, docstring, adjacent comments included) | ||
| and paste it into the target with the imports it needs; | ||
| - rewrite every importer through the import rewriter; | ||
| - give the old module an import of the moved name when it still uses it, | ||
| and optionally a deprecation re-export (`keep_alias=True`); | ||
| - refuse before touching a file when the move would create an import | ||
| cycle, naming the cycle. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Callable | ||
| from pathlib import Path | ||
|
|
||
| from ..graph_query import QueryFn | ||
| from .contract import Reingest | ||
| from .move_scope import _module_bound | ||
| from .move_types import MoveRefused, MoveReport | ||
| from .transaction import StagedTree, VerificationResult | ||
|
|
||
|
|
||
| def __getattr__(name: str): | ||
| if name == "Mover": | ||
| from .move_operation import Mover | ||
|
|
||
| return Mover | ||
| raise AttributeError(name) | ||
|
|
||
|
|
||
| def move( | ||
| repo_root: Path, | ||
| fetch_all: QueryFn, | ||
| project_name: str, | ||
| qualified_name: str, | ||
| target_module: str, | ||
| keep_alias: bool = False, | ||
| dry_run: bool = False, | ||
| verify: Callable[[StagedTree], VerificationResult | bool | None] | None = None, | ||
| reingest: Reingest | None = None, | ||
| ) -> MoveReport: | ||
| """The op: plan (refusing on a cycle) or plan and apply.""" | ||
| from .move_operation import move as _move | ||
|
|
||
| return _move( | ||
| repo_root, | ||
| fetch_all, | ||
| project_name, | ||
| qualified_name, | ||
| target_module, | ||
| keep_alias=keep_alias, | ||
| dry_run=dry_run, | ||
| verify=verify, | ||
| reingest=reingest, | ||
| ) | ||
|
|
||
|
|
||
| __all__ = ["MoveRefused", "MoveReport", "move", "_module_bound"] |
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,44 @@ | ||
| """Import-cycle refusal for move planning.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from .. import constants as cs | ||
| from ..graph_query import QueryFn | ||
| from ..structural_delta import import_cycles, snapshot | ||
| from .move_types import MoveRefused | ||
|
|
||
|
|
||
| class _MoveCycleMixin: | ||
| fetch_all: QueryFn | ||
| project: str | ||
|
|
||
| def _refuse_cycles( | ||
| self, | ||
| old_module: str, | ||
| new_module: str, | ||
| copied_targets: list[str], | ||
| needs_old: bool, | ||
| old_needs_new: bool, | ||
| old_path: str, | ||
| new_path: str, | ||
| ) -> None: | ||
| graph = { | ||
| qn: set(targets) | ||
| for qn, targets in snapshot( | ||
| self.fetch_all, self.project, [old_path, new_path] | ||
| ).imports.items() | ||
| } | ||
| before = import_cycles({qn: frozenset(t) for qn, t in graph.items()}) | ||
| graph.setdefault(new_module, set()).update(t for t in copied_targets if t) | ||
| if needs_old: | ||
| graph.setdefault(new_module, set()).add(old_module) | ||
| if old_needs_new: | ||
| graph.setdefault(old_module, set()).add(new_module) | ||
| for importer, targets in graph.items(): | ||
| if old_module in targets and importer not in (old_module, new_module): | ||
| targets.add(new_module) | ||
| after = import_cycles({qn: frozenset(t) for qn, t in graph.items()}) | ||
| fresh = [c for c in after - before if new_module in c or old_module in c] | ||
| if fresh: | ||
| cycle = tuple(sorted(fresh[0])) | ||
| raise MoveRefused(cs.MOVE_CYCLE.format(cycle=" -> ".join(cycle)), cycle) | ||
Oops, something went wrong.
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.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
Model only importer edges that the move rewrites.
This loop adds
importer -> new_modulefor every module that imports anything fromold_module._retarget_importersrewrites only imports whoseimported_nameequals the moved symbol. The cycle check can therefore refuse a safe move because an unrelated import creates a simulated cycle. It also retains an old edge that the actual rewrite can remove.Build the after-graph from the symbol-specific import sites that the plan will change.
🤖 Prompt for AI Agents