Repository navigation
refactor(tests/profile): extract embedded python glob to discover_profile_tests.py (#3129 A12) - #3198
Conversation
…file_tests.py tests/profile/meson.build had an inline `python -c '...glob.glob(...)'` discovering the 21 profile .cpp files at configure time. The agents build-system rule (agents/docs/build-system.md) prohibits embedded python scripts in meson.build because: - Not greppable / lintable / testable - Hard to evolve (e.g. add a metadata cache later) - Pays the configure-time tax with no caching Replaces the embedded snippet with a standalone discover script that produces the same semicolon-separated output. Output verified against the original on a local checkout: 21 .cpp files, identical sort order. Followup (not in this PR): mirror tests/test_metadata_cache.py to short-circuit the script when no profile .cpp files have changed between configures. Part of #3129 (Section A12). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughA new Python script ChangesProfile Test Discovery Refactor
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/profile/meson.build (1)
16-17: Usepython_exevariable instead of hardcoded'python'.This repository resolves the Python interpreter once in
tests/meson.buildviapython_exe = find_program('python')(line 164) and makes it available to this subdirectory via Meson'ssubdir()inclusion. Replace the hardcoded'python'string withpython_exefor consistency and to avoid redundant interpreter lookups.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/profile/meson.build` around lines 16 - 17, Replace the hardcoded 'python' string on line 16 with the python_exe variable. The python_exe variable is already resolved in the parent tests/meson.build file and made available to this subdirectory via Meson's subdir() inclusion, so use it directly instead of hardcoding the Python interpreter name to maintain consistency and avoid redundant lookups.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/profile/discover_profile_tests.py`:
- Around line 40-42: The main() function silently falls back to "." when the
source_dir argument is missing, which can mask configuration errors. Replace the
conditional fallback logic with explicit validation that requires exactly one
argument to be provided. Before calling discover(source_dir), add a check to
ensure the argument exists and validate that the directory path is valid,
exiting with a descriptive error message if either validation fails.
In `@tests/profile/meson.build`:
- Around line 15-20: The run_command call executing the
discover_profile_tests.py script has check: false, which silently allows script
errors to be misinterpreted as "no profile tests found" instead of failing fast.
Change the check: false parameter to check: true in the run_command call for the
profile test discovery, so that any interpreter or script errors will cause the
configuration to fail immediately with a descriptive error rather than
continuing silently.
---
Nitpick comments:
In `@tests/profile/meson.build`:
- Around line 16-17: Replace the hardcoded 'python' string on line 16 with the
python_exe variable. The python_exe variable is already resolved in the parent
tests/meson.build file and made available to this subdirectory via Meson's
subdir() inclusion, so use it directly instead of hardcoding the Python
interpreter name to maintain consistency and avoid redundant lookups.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 945cc156-0ee0-4344-b12f-f53167d364e7
📒 Files selected for processing (2)
tests/profile/discover_profile_tests.pytests/profile/meson.build
… python_exe CodeRabbit on PR #3198 flagged three improvements; all addressed: 1. tests/profile/discover_profile_tests.py: fail fast on missing or invalid source_root. Previously the script silently fell back to "." which could mask wiring mistakes. - require exactly one positional argument - validate the directory exists - exit 2 with a usage / error message to stderr otherwise 2. tests/profile/meson.build: change check: false -> check: true. With check: false a script error was indistinguishable from "no profile tests found". Failing fast at configure time is the right behaviour now that the discovery script reports its own errors. 3. tests/profile/meson.build: use python_exe instead of the hardcoded string 'python'. python_exe is defined once in tests/meson.build:164 via find_program('python') and is inherited via subdir(). Verified locally: - python tests/profile/discover_profile_tests.py -> exit 2 - python tests/profile/discover_profile_tests.py /no/such -> exit 2 - python tests/profile/discover_profile_tests.py . -> exit 0, 825 bytes of semicolon-separated paths (same 21 .cpp files as before). Part of #3129 (Section A12). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
`tests/profile/meson.build` had an inline `python -c '...glob.glob(...)'` snippet that discovers the 21 profile `.cpp` files at configure time. The project rule in `agents/docs/build-system.md` prohibits embedded Python scripts in `meson.build` because they are:
What changes
2 files changed, 53 insertions(+), 14 deletions(-) — the net is a +39 line drift but the script is mostly docstring and the function is small.
Validation
Followup (not in this PR)
The audit mentioned mirroring `tests/test_metadata_cache.py` to short-circuit the script when no profile `.cpp` files have changed between configures. That belongs in a separate PR scoped to the metadata cache pattern.
Part of #3129 (Section A12).
🤖 Generated with Claude Code
Summary by CodeRabbit