Skip to content

refactor(tests/profile): extract embedded python glob to discover_profile_tests.py (#3129 A12) - #3198

Merged
zackees merged 2 commits into
masterfrom
refactor/3129-a12-profile-cache
Jun 16, 2026
Merged

zackees merged 2 commits into
masterfrom
refactor/3129-a12-profile-cache

Conversation

@zackees

@zackees zackees commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

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:

  • Not greppable / lintable / testable.
  • Hard to evolve (e.g. add a metadata cache later).
  • Configure-time tax with no caching.

What changes

File Change
`tests/profile/discover_profile_tests.py` New — equivalent of the inline snippet as a proper script
`tests/profile/meson.build` Replace the `python -c '...'` block with a `run_command` that calls the new script

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

  • ✅ Output verified against the original on a local checkout: 21 `.cpp` files, identical sort order, same semicolon-joined format.
  • ✅ `bash lint` clean (no new warnings).

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

  • Chores
    • Improved test discovery for profile benchmarks by replacing inline globbing with a dedicated discovery script that returns a sorted list of matches.
    • Updated benchmark discovery in the build process to treat discovery failures as errors, preventing silent skips.

…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]>
@coderabbitai

coderabbitai Bot commented Jun 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: daf0634e-b032-47a8-87e7-889fff08b480

📥 Commits

Reviewing files that changed from the base of the PR and between 52431bd and 2c767f7.

📒 Files selected for processing (2)
  • tests/profile/discover_profile_tests.py
  • tests/profile/meson.build
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/profile/meson.build
  • tests/profile/discover_profile_tests.py

📝 Walkthrough

Walkthrough

A new Python script tests/profile/discover_profile_tests.py is added to discover profile benchmark .cpp files via glob patterns and print them as a semicolon-separated list. The tests/profile/meson.build file is updated to invoke this external script via run_command instead of an inline python -c block.

Changes

Profile Test Discovery Refactor

Layer / File(s) Summary
Profile test discovery script
tests/profile/discover_profile_tests.py
Implements discover(source_dir) to glob tests/profile/*.cpp and tests/profile/**/*.cpp, returning a sorted list. main() parses CLI arguments, validates the source root is a directory, prints matches semicolon-separated, and returns 0 on success or 2 on invalid input.
Meson.build integration
tests/profile/meson.build
Replaces the 14-line inline python -c glob block with a 4-line run_command(python_exe, <script_path>, source_root) call. Changes check: false to check: true, so failed discovery now fails Meson configuration rather than being tolerated.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

🐇 Hop hop, I tidied the build today,
Pulled the glob logic out of the way!
A script of its own, so neat and so clean,
No more inline Python code to be seen.
With semicolons sorted and exits at zero,
This little refactor makes CI a hero! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: extracting an embedded Python glob command from meson.build into a dedicated script (discover_profile_tests.py).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/3129-a12-profile-cache

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/profile/meson.build (1)

16-17: Use python_exe variable instead of hardcoded 'python'.

This repository resolves the Python interpreter once in tests/meson.build via python_exe = find_program('python') (line 164) and makes it available to this subdirectory via Meson's subdir() inclusion. Replace the hardcoded 'python' string with python_exe for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0da5097 and 52431bd.

📒 Files selected for processing (2)
  • tests/profile/discover_profile_tests.py
  • tests/profile/meson.build

Comment thread tests/profile/discover_profile_tests.py Resolved
Comment thread tests/profile/meson.build Resolved
… 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]>
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 16, 2026
@zackees
zackees merged commit 1b29f5b into master Jun 16, 2026
12 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 16, 2026
@zackees
zackees deleted the refactor/3129-a12-profile-cache branch August 21, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant