Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Jan 10, 2026

also added --quick-import just like --quick-upgrade

Summary by CodeRabbit

  • Chores
    • Improved test infrastructure with a modernized test modification system using patches, streamlined test discovery and execution, and added a quick-import workflow for test file management.

✏️ Tip: You can customize this high-level summary in your review settings.

@youknowone youknowone added the skip:ci Skip running the ci label Jan 10, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 10, 2026

Warning

Rate limit exceeded

@youknowone has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 20 minutes and 2 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b71ad81 and f2d5594.

📒 Files selected for processing (1)
  • scripts/fix_test.py
📝 Walkthrough

Walkthrough

This PR refactors scripts/fix_test.py to replace its line-based test modification system with a patch-based system using lib_updater. It introduces a --quick-import option for importing CPython test files, removes legacy AST-based functions, and updates test execution flags.

Changes

Cohort / File(s) Summary
Patch-Based Test Modification System
scripts/fix_test.py
Replaced AST-based test location and line-based modification logic with lib_updater-based patch system via new build_patches function; added --quick-import workflow to optionally copy CPython test files before patching; refactored argument parsing with mutual exclusive --path/--quick-import options; removed find_test_lineno and apply_modifications functions; updated test execution to include -u all --slowest flags; changed imports from ast, itertools, platform to lib_updater utilities.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ShaharNaveh
  • arihant2math
  • reactive-firewall

Poem

🐰 From lines we seek to patches grand,
The test-fixer script now takes its stand,
With quick-import swift and patches clean,
The finest refactoring we've seen! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main objective of the pull request: integrating fix_test script with lib_updater using a patch-based system and quick-import functionality.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone marked this pull request as ready for review January 10, 2026 15:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @scripts/fix_test.py:
- Around line 152-161: The current check uses a hardcoded string "/Lib/" against
str(args.quick_import) which fails on Windows backslashes; instead convert
args.quick_import to a pathlib.Path, inspect Path.parts to find the "Lib"
component (e.g., p = Path(args.quick_import); find index = p.parts.index("Lib")
if present), error if "Lib" not in p.parts, and construct lib_path as
Path(*p.parts[index:]) (so it works cross-platform); update references to
src_str, lib_marker, and lib_path accordingly and remove the string-based
"/Lib/" check.
🧹 Nitpick comments (2)
scripts/fix_test.py (2)

43-46: Unused --force and --platform flags.

These flags are parsed but not referenced anywhere in the refactored code. If they're no longer needed after removing the legacy apply_modifications logic, consider removing them to avoid confusion. Otherwise, document their intended use.


61-68: Mutable class attribute tests = [] is shared across instances.

Class-level mutable defaults like tests = [] are shared across all instances. While this works in the current single-use context, it's a latent bug if the class is reused.

♻️ Suggested fix
 class TestResult:
     tests_result: str = ""
-    tests = []
+    tests: list
     stdout = ""
+
+    def __init__(self):
+        self.tests = []
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3909b18 and b71ad81.

📒 Files selected for processing (1)
  • scripts/fix_test.py
🧰 Additional context used
📓 Path-based instructions (2)
**/*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.py: In most cases, Python code should not be edited; bug fixes should be made through Rust code modifications only
Follow PEP 8 style for custom Python code
Use ruff for linting Python code

Files:

  • scripts/fix_test.py
**/*test*.py

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*test*.py: NEVER comment out or delete any test code lines except for removing @unittest.expectedFailure decorators and upper TODO comments
NEVER modify test assertions, test logic, or test data in test files
When a test cannot pass due to missing language features, keep it as expectedFailure and document the reason; do not comment it out
The only acceptable modifications to test files are: (1) Removing @unittest.expectedFailure decorators and the upper TODO comments when tests actually pass, and (2) Adding @unittest.expectedFailure decorators when tests cannot be fixed

Files:

  • scripts/fix_test.py
🧠 Learnings (7)
📓 Common learnings
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 6089
File: scripts/lib_updater.py:292-297
Timestamp: 2025-08-30T14:40:05.858Z
Learning: In scripts/lib_updater.py, the --inplace flag intentionally writes to orig_file (not remote_file) even though patches are applied to remote_file content. This workflow allows updating the original RustPython test file with patches applied to new upstream CPython content.
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 6089
File: scripts/lib_updater.py:198-202
Timestamp: 2025-09-07T05:38:31.690Z
Learning: In scripts/lib_updater.py, the iter_patches function intentionally does not handle SyntaxError from ast.parse(contents). The author confirmed this behavior is fine and intended - the tool should fail fast on unparseable files rather than silently skip processing.
📚 Learning: 2025-12-27T14:03:49.034Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-27T14:03:49.034Z
Learning: Applies to **/*test*.py : The only acceptable modifications to test files are: (1) Removing `unittest.expectedFailure` decorators and the upper TODO comments when tests actually pass, and (2) Adding `unittest.expectedFailure` decorators when tests cannot be fixed

Applied to files:

  • scripts/fix_test.py
📚 Learning: 2025-12-27T14:03:49.034Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-27T14:03:49.034Z
Learning: Applies to Lib/** : In the `Lib/` directory, when modifications are necessary, add a `# TODO: RUSTPYTHON` comment or use `unittest.skip('TODO: RustPython <reason>')` or `unittest.expectedFailure` with `# TODO: RUSTPYTHON <reason>` comment

Applied to files:

  • scripts/fix_test.py
📚 Learning: 2025-08-30T14:40:05.858Z
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 6089
File: scripts/lib_updater.py:292-297
Timestamp: 2025-08-30T14:40:05.858Z
Learning: In scripts/lib_updater.py, the --inplace flag intentionally writes to orig_file (not remote_file) even though patches are applied to remote_file content. This workflow allows updating the original RustPython test file with patches applied to new upstream CPython content.

Applied to files:

  • scripts/fix_test.py
📚 Learning: 2025-12-27T14:03:49.034Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-27T14:03:49.034Z
Learning: Applies to **/*test*.py : NEVER comment out or delete any test code lines except for removing `unittest.expectedFailure` decorators and upper TODO comments

Applied to files:

  • scripts/fix_test.py
📚 Learning: 2025-09-07T05:38:31.690Z
Learnt from: ShaharNaveh
Repo: RustPython/RustPython PR: 6089
File: scripts/lib_updater.py:198-202
Timestamp: 2025-09-07T05:38:31.690Z
Learning: In scripts/lib_updater.py, the iter_patches function intentionally does not handle SyntaxError from ast.parse(contents). The author confirmed this behavior is fine and intended - the tool should fail fast on unparseable files rather than silently skip processing.

Applied to files:

  • scripts/fix_test.py
📚 Learning: 2025-12-27T14:03:49.034Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-12-27T14:03:49.034Z
Learning: When testing Python code, always use RustPython instead of the standard `python` command; use `cargo run -- script.py` or `cargo run` for interactive REPL

Applied to files:

  • scripts/fix_test.py
🧬 Code graph analysis (1)
scripts/fix_test.py (1)
scripts/lib_updater.py (3)
  • apply_patches (273-283)
  • PatchSpec (81-122)
  • UtMethod (59-78)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check Rust code with clippy
🔇 Additional comments (5)
scripts/fix_test.py (5)

1-31: LGTM!

Clear documentation for the new --quick-import workflow, and imports are appropriate for the refactored patch-based approach using lib_updater.


70-117: LGTM!

The result parsing and path extraction logic correctly identifies failing tests and extracts class/method names.


120-129: LGTM!

Correctly builds the patch dictionary structure expected by apply_patches. Based on learnings, lib_updater handles adding the TODO comment via PatchSpec._reason.


140-145: LGTM!

Adding -u all --slowest flags provides more comprehensive test execution and timing information.


189-206: LGTM!

The deduplication using a set correctly handles subtests that may produce multiple failures for the same test method. The integration with apply_patches from lib_updater is correct.

Note: The check at line 192 is slightly redundant since parse_results already filters to only "fail" or "error" results (line 91-92), but it's harmless and adds defensive clarity.

Comment on lines 152 to 161
if args.quick_import is not None:
src_str = str(args.quick_import)
lib_marker = "/Lib/"

if lib_marker not in src_str:
print(f"Error: --quick-import path must contain '/Lib/' (got: {src_str})")
sys.exit(1)

idx = src_str.index(lib_marker)
lib_path = Path(src_str[idx + 1:]) # Lib/test/foo.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Cross-platform path separator issue.

The /Lib/ marker won't match on Windows where Path objects stringify with backslashes. Users passing cpython\Lib\test\test_foo.py would get the error despite having a valid path.

🔧 Suggested fix using platform-agnostic separator
     if args.quick_import is not None:
-        src_str = str(args.quick_import)
-        lib_marker = "/Lib/"
+        # Normalize to forward slashes for consistent parsing
+        src_str = str(args.quick_import).replace("\\", "/")
+        lib_marker = "/Lib/"
 
         if lib_marker not in src_str:
🤖 Prompt for AI Agents
In @scripts/fix_test.py around lines 152 - 161, The current check uses a
hardcoded string "/Lib/" against str(args.quick_import) which fails on Windows
backslashes; instead convert args.quick_import to a pathlib.Path, inspect
Path.parts to find the "Lib" component (e.g., p = Path(args.quick_import); find
index = p.parts.index("Lib") if present), error if "Lib" not in p.parts, and
construct lib_path as Path(*p.parts[index:]) (so it works cross-platform);
update references to src_str, lib_marker, and lib_path accordingly and remove
the string-based "/Lib/" check.

@youknowone youknowone merged commit 12f08d6 into RustPython:main Jan 11, 2026
9 checks passed
@youknowone youknowone deleted the quick-import branch January 11, 2026 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip:ci Skip running the ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant