Skip to content

Include explicit test roots and recipe-plan targets in CLI source policy - #645

Merged
trissim merged 1 commit into
mainfrom
fix/cli-include-explicit-test-roots-and-plan-execution
Nov 28, 2026
Merged

trissim merged 1 commit into
mainfrom
fix/cli-include-explicit-test-roots-and-plan-execution

Conversation

@trissim

@trissim trissim commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Why

Running --codemod-plan plan.json --codemod-simulate src tests on Toad (0add3cb79) rewrote 58 files in src/ and 0 files in tests/, leaving 9 test files with ImportError on symbols moved by cut_hidden_cycle.

Root cause at nominal_refactor_advisor/cli.py:4632:
source_policy = PythonSourcePathPolicy(include_tests=args.include_tests) defaulted include_tests=False unconditionally, so parse_python_module_roots((src, tests), source_policy=PythonSourcePathPolicy(include_tests=False)) returned src=540, tests=0, silently dropping every file under an explicitly passed tests root.

Fix

  • Move CLI source_policy construction to CliArguments.source_policy (nominal_refactor_advisor/cli.py:2390), enabling include_tests=True when:
    1. --include-tests is passed, OR
    2. any explicit positional path or --context-root is a test path (PythonSourcePathPolicy.is_test_path), OR
    3. the invocation is executing an explicit recipe plan without finding analysis or architecture guards (CodemodExecutionMode.exact_recipe_execution).
  • Production-only scans (nra src, nra .) and --codemod-project-findings scans keep include_tests=False, and programmatic parse_python_module_roots(..., source_policy=PythonSourcePathPolicy(include_tests=False)) is untouched.

Proof

  • Added tests/test_hidden_import_cuts.py::test_cli_codemod_plan_execution_rewrites_test_imports_without_include_tests_flag covering plain src vs src tests policy, --codemod-simulate src tests, --codemod-apply <repo_root>, and in-place retargeting of local test imports without gratuitous hoisting.
  • REL_IMPORTS=0.

@trissim
trissim merged commit 8adf413 into main Nov 28, 2026
2 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant