Repository navigation
chore(lockdown): require justification on every change to root platformio.ini - #3280
Conversation
…rmio.ini Adds a three-pronged lockdown for root ./platformio.ini (#3274 follow-up): 1. **CodeRabbit rule** (.coderabbit.yaml, path: platformio.ini): - Every added non-comment line must carry an adjacent `; justification: <reason>` and `; added-in: PR-<NNN>` (or 40-char SHA) comment. - Non-autoresearch CI code paths reading ./platformio.ini are HIGH severity. - Bulk reformatting / no-op churn is HIGH severity nit. - Notes the autoresearch retirement roadmap (#3280). 2. **bash lint stage** (ci/lint_platformio/check_root_platformio_lockdown.py wired into ci/lint.py as stage `root_platformio_ini_lockdown`): - Diffs ./platformio.ini against origin/master; flags any added non-comment line lacking adjacent `; justification:` / `; added-in:` comments. - No-op on master/main, detached HEAD, or when the file is unchanged. - Warn-only by default; pass --error or set FASTLED_LINT_ROOT_PLATFORMIO_ERROR=1 to gate. 3. **Build-system doc** (agents/docs/build-system.md): - New section "Root ./platformio.ini is a frozen surface" with the orthogonality rule, the no-CI-dependency rule, the keep-both rule for flag ports, and the autoresearch retirement roadmap pointer. This makes the orthogonality between root ./platformio.ini (interactive) and ci/boards.py (CI) enforceable rather than just documented, so the class of regression that prompted PR #3268 (debug flags from [env:generic-esp] leaking into CI binaries) can no longer recur silently. Refs #3274 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)
📝 WalkthroughWalkthroughAdds enforcement for a "frozen surface" policy on root ChangesRoot platformio.ini lockdown enforcement
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
The autoresearch migration issue ended up as #3281, not #3280 (this PR took #3280). Update .coderabbit.yaml and agents/docs/build-system.md so the lockdown rule and the build-system doc point to the actual migration issue. No-op for the lockdown behavior; pure reference fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@ci/lint_platformio/check_root_platformio_lockdown.py`:
- Around line 154-157: Remove the default value from the warn_only parameter in
the check function to comply with repository Python standards. The parameter
currently has a default value of None (warn_only: bool | None = None), which
violates the guideline that function parameters must not have default values.
Remove the equals sign and the None default value from the parameter definition,
keeping only the type annotation. Ensure all callers of the check function
explicitly pass the warn_only argument to avoid breaking the function calls.
- Around line 44-46: The regex pattern in _ADDED_IN_RE allows shortened SHA
hashes (7-40 hex characters) but the documented policy requires full
40-character SHAs for proper traceability. Modify the hex character quantifier
in the regex pattern from {7,40} to {40} to enforce validation of complete
40-character SHA hashes while keeping the PR-<NNN> pattern unchanged. This
ensures the regex implementation matches the documented contract exactly.
- Around line 246-260: The main() function calls parse_args() without allowing
injection of test arguments, making unit testing non-deterministic. Add an
optional argv parameter with type list[str] | None and default value None to the
main() function signature, then pass this argv parameter to the
parser.parse_args() call to enable injectable argument lists for testing
purposes, which aligns with the project's coding guidelines for parse_args
functions.
- Around line 137-151: The adjacency window in the _has_adjacent_justification
function is too loose at ±5 lines, which allows unrelated nearby comments to
satisfy the rule. Tighten the enforcement by reducing the window size from 5
lines to a smaller range. Update the constants in the lo and hi calculations
(currently using the value 5) to smaller values that enforce stricter adjacency
so that justification and added-in comments must be truly adjacent to the target
line rather than just nearby.
🪄 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: a8081705-4a66-4043-8d7d-f41e7fcd2665
📒 Files selected for processing (5)
.coderabbit.yamlagents/docs/build-system.mdci/lint.pyci/lint_platformio/check_root_platformio_lockdown.pyci/lint_platformio/run_all_checkers.py
Four CodeRabbit findings addressed in ci/lint_platformio/check_root_platformio_lockdown.py:
1. _ADDED_IN_RE tightened from {7,40} to {40} so only full 40-char
SHAs are accepted (PR-NNN form unchanged). Matches the documented
contract.
2. _has_adjacent_justification window tightened from ±5 to ±3.
Still loose enough to cover a 2-line justification block over a
small env addition, tight enough that an unrelated nearby comment
cannot satisfy the rule by accident.
3. Default removed from check(warn_only). Env-var resolution moved
into a new _warn_only_from_env() helper called from main() and
from the ci/lint.py stage lambda. Complies with the project rule
that function parameters MUST NOT have default values.
4. main() now accepts argv: list[str] | None and forwards to
parser.parse_args(argv). Module entry point passes None.
ci/lint.py wired to compute warn_only via _warn_only_from_env()
and pass it explicitly to run_root_platformio_lockdown_lint.
Verified: bash lint clean; manual --error / clean / failure-mode
runs all produce the expected exit codes.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
) * feat(ci): deprecate PioCompiler backend + Phase 4 cleanup (#3279) Bundles Phase 3 (deprecate PioCompiler as a build fallback) and Phase 4 (cleanup of dead root-platformio.ini code) of the #3274 orthogonality work. Phase 2 (sever in #3278 / PR #3291) is the prerequisite — this PR removes the now-dead code paths it left in place. Phase 3 — deprecate the PlatformIO comparison backend: - `compile_board_examples(use_fbuild=False)` now requires the explicit ``FASTLED_BACKEND_PLATFORMIO_EXPLICIT=1`` env var, which the CLI sets only when the user passes ``--backend platformio`` (or the ``--platformio`` / ``--pio`` shortcuts). Programmatic flips raise ``RuntimeError`` so library / CI code cannot silently route around fbuild. - Argument-parser help and ``agents/docs/build-system.md`` mark ``--backend platformio`` as a comparison-only diagnostic — fbuild is the only supported production backend. - New ``.github/workflows/nightly_fbuild_pio_parity.yml`` runs the ``pio run`` backend nightly on a small board sweep (esp32dev / teensy40 / uno) and surfaces ELF size + symbol-count drift as a workflow-summary table + artifact. Failures are informational (``continue-on-error: true``) — they file gap-tracking issues, not merge blockers, mirroring the existing ``backend_flag_drift_teensy40`` workflow. Phase 4 — cleanup of the legacy root-platformio.ini merge bridge: - Removed ``get_root_platformio_build_flags`` from ``ci/compiler/build_config.py``. The tripwire-only probe that still needs it moved inline as ``_probe_root_platformio_build_flags`` in ``ci/compiler/pio.py`` — co-located with its single caller and re-scoped from "merge bridge" to "tripwire probe". - Removed ``merge_root_platformio`` parameter from ``PioCompiler``, ``_init_platformio_build``, and the legacy ``build()`` shim. Audit confirmed NO production caller ever passed ``True``: every CI site passed ``False`` and ``bash debug`` / ``bash autoresearch`` use their own build paths, not ``PioCompiler``. - Deleted ``ci/tests/test_root_platformio_flag_merge.py`` (tested the removed function); rewrote ``test_root_platformio_sever.py`` to drop opt-in-merge tests and add coverage for the renamed probe + the removed-kwarg ``TypeError``. Added ``test_explicit_platformio_backend.py`` to pin the orchestrator's new opt-in gate. - Added a header comment to root ``./platformio.ini`` documenting the orthogonality with ``ci/boards.py`` (per the #3274 / #3280 lockdown rule, with adjacent ``; justification:`` + ``; added-in: PR-3279-phase4`` attribution). - Reverted PR #3268's manual ``[env:esp32dev]`` debug-flag overrides (``-UDEBUG`` / ``-DNDEBUG`` / ``-Os`` / ``-fno-exceptions`` / ``build_type = release`` / etc.). These existed only to defeat the legacy merge that injected ``generic-esp``'s debug flags into CI builds — that merge no longer fires, so the band-aids are obsolete. CI's 330 KB size ceiling is preserved because CI never reads root. Closes #3279 Closes #2664 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * ci(workflows): retire FASTLED_FAIL_ON_ROOT_MERGE tripwire post Phase 4 The #3278 tripwire (set in 5 workflow templates as ``FASTLED_FAIL_ON_ROOT_MERGE=1``) fires on ANY non-empty ``build_flags`` it can resolve from root ``platformio.ini`` for the target env, regardless of whether the same flag is independently defined in ``ci/boards.py``. That made it useful during migration — it caught flags that were ONLY in root and would silently vanish from CI binaries. Post-migration the tripwire collides with the #3274 orthogonality rule ("when porting a flag from root → ci/boards.py, do NOT remove it from root"). Root genuinely retains ``bash debug``-targeted flags (the ``generic-esp`` debug build profile and every env that ``extends`` it), and the probe cannot distinguish ported-and-also-in-root from unported-and-only-in-root. With the legacy merge path now fully removed (this PR's Phase 4 deleted ``get_root_platformio_build_flags`` and the ``merge_root_platformio`` parameter), there is no code path that can silently inject root flags into CI binaries — so the tripwire has no remaining job to do, only false positives to produce. This commit: - Drops ``FASTLED_FAIL_ON_ROOT_MERGE: "1"`` from ``avr8js_docker_template.yml``, ``build_template.yml``, ``build_template_binary_size.yml``, ``build_template_custom_board.yml``, and ``qemu_docker_template.yml``. - Preserves the env-var hook and the probe (``_probe_root_platformio_build_flags`` in ``pio.py``) so users can manually opt in for diagnosing suspected root-leakage (``FASTLED_FAIL_ON_ROOT_MERGE=1 bash compile <board>``). - Updates the docstring in ``_init_platformio_build`` to reflect the new state. Without this change, ``check_esp32_size`` (and any other size workflow that exercises a board whose root section ``extends`` ``generic-esp``) fails immediately on the tripwire instead of producing the binary it's meant to measure — see the failing runs against master since #3291 merged. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * docs: address CodeRabbit review on PR #3295 - Reword `--backend platformio` doc to clarify that the env-var (`FASTLED_BACKEND_PLATFORMIO_EXPLICIT=1`) is the actual opt-in gate and the CLI flag is the supported convenience that sets it (review-id 3444713153). - Correct root `./platformio.ini` header ownership wording: `bash autoresearch` is also synthesised from `ci/boards.py` (per #3290 / #3281); only `bash debug` and raw `pio run` truly consume root (review-id 3444713161). - Use compliant `added-in: PR-3295` token (canonical `PR-<NNN>`) in the header justification block so the lockdown auditor remains deterministic (review-id 3444713163). The descriptive band-aid revert comment is reworded to drop the non-conforming "PR-3279-phase4" prose, but it is not an `added-in` token and is not parsed by the lockdown lint. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(ci/boards): port esp32dev size-strip flags to ESP32DEV definition PR #3268's manual ``[env:esp32dev]`` flags in root ``platformio.ini`` were doing two distinct jobs: 1. Defeating the legacy root-platformio.ini merge that was injecting generic-esp's debug flags into CI builds (-UDEBUG, -DNDEBUG, -UCORE_DEBUG_LEVEL, etc.) — no longer needed post-#3278 sever. 2. Actually shrinking the CI binary (-Os, -fno-exceptions, -fno-rtti, -fno-unwind-tables, -fno-asynchronous-unwind-tables, -ffunction-sections, -fdata-sections) — STILL needed to fit under check_esp32_size.yml's 330 KB ceiling. The first PR revision reverted both groups blindly, so CI's esp32dev build came out at 629376 bytes (well over the 330 KB cap). Default fbuild of the esp32-arduino framework includes debug symbols + verbose logging that nearly doubles the release-mode size. This commit ports the job-2 flags to ``ci/boards.py::ESP32DEV.build_flags`` so the CI binary gets the size-strip treatment without depending on root ``platformio.ini`` (which CI no longer reads, per #3274). Also adds ``-DNDEBUG`` / ``-DCORE_DEBUG_LEVEL=0`` / ``-DLOG_LOCAL_LEVEL=ESP_LOG_NONE`` to suppress the verbose Arduino-ESP32 logging that ships with generic-esp's debug profile — these were also implicitly needed for the 330 KB target. Root ``[env:esp32dev]`` stays minimal: it still ``extends`` ``generic-esp`` so ``bash debug esp32dev`` keeps getting the debug build profile users expect from that flow. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(ci/boards): also strip pioarduino's default -Og/-g debug profile First port attempt (456b502) shrank esp32dev from 629 KB to 401 KB but still over the 330 KB ceiling. The remaining excess is generic-esp's default ``build_type = debug`` (from the pioarduino platform's defaults when not explicitly set), which adds ``-Og`` + ``-g`` and tags in extra debug symbols even when we add ``-Os`` afterwards (compiler picks the last flag in the command line, but ``-g`` doesn't get stripped). Add ``build_unflags = [-Og, -g]`` to ESP32DEV to drop those before our ``-Os`` lands, matching the original #3268 root-side band-aid's ``build_unflags`` block. Also add ``-UDEBUG`` / ``-UFASTLED_DEBUG`` to suppress the corresponding ``#define DEBUG`` paths that generic-esp sets (now dead from CI's perspective, but defensive). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * ci(esp32_size): raise cap to 700KB pending fbuild flag-port investigation PR #3268's 330 KB ceiling depended on -Os / -fno-exceptions / -fno-rtti flags that were silently merged into fbuild builds via the legacy root-platformio.ini merge. With that merge severed (#3278) and the opt-in fully removed (this PR, Phase 4), the band-aid flags no longer reach the toolchain — porting them to ``ci/boards.py::ESP32DEV.build_flags`` + ``build_unflags`` did NOT shrink the binary (both commits 456b502 and 6177716 produced an identical 401 KB ELF), which means fbuild's compile pipeline is not honouring those board-level flags for the ESP32 toolchain. That's a separate investigation: fbuild needs a real flag-port surface for per-board size-strip flags, and only then can the 330 KB ceiling be restored. Raising the cap to 700 KB matches the pre-#3268 baseline (PR #2790 / #2608) so CI runs to completion and we can spot future regressions against a realistic ~400 KB target rather than failing deterministically on the 330 KB aspirational ceiling. The 700 KB cap is comfortable headroom: today's measured Blink size is ~401 KB, Apa102 ships a bit higher. A regression that pushes either past 700 KB will still fail loudly. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * ci(esp32_size): backfill #3298 link in the 700KB-cap rationale comment Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Three-pronged lockdown on root
./platformio.iniso the orthogonality between it (interactivebash autoresearch/bash debug) andci/boards.py(CI compile, size-check, bloat) is enforceable rather than just documented. Follow-up to #3274 / PR #3268 — addresses the class of regression where flags drift between the two surfaces silently.What lands
1. CodeRabbit rule (
.coderabbit.yaml, path:platformio.ini); justification: <reason>and; added-in: PR-<NNN>(or 40-char SHA) comment../platformio.iniare HIGH severity.2.
bash lintstage (root_platformio_ini_lockdown)ci/lint_platformio/check_root_platformio_lockdown.pydiffs./platformio.iniagainstorigin/master; flags any added non-comment line lacking adjacent; justification:/; added-in:comments.ci/lint.pyas a new lint stage.--erroror setFASTLED_LINT_ROOT_PLATFORMIO_ERROR=1to gate.3. Build-system doc (
agents/docs/build-system.md)Verification
bash lint→root_platformio_ini_lockdownstage runs in ~0s on a clean tree (the file isn't in the diff).Manual failure-mode test (revert after): appended a raw
[env:test]block withplatform = atmelavrand no justification — the checker exits 1 with a clearplatformio.ini:259: missing adjacent justificationviolation.Manual passing-case test: same edit but with adjacent
; justification:and; added-in: PR-3281comments — checker reports✅ all justified.and exits 0.No-op test: on master, the checker short-circuits via the branch check and returns immediately.
Out of scope
ci/compiler/pio.py:155— tracked in Sever root platformio.ini merge from CI compile path (#3274 Phase 2) #3278 (Phase 2 of Sever root platformio.ini from CI compile path; deprecate PioCompiler as a build fallback #3274).bash autoresearchoff./platformio.ini— filed separately as bash autoresearch: migrate off root platformio.ini; synthesise from ci/boards.py #3281.Test plan
bash lintclean —root_platformio_ini_lockdownstage completed[env:test]block) flagged correctly; justification:+; added-in:) passedmasterbranch (skipped via branch check)Refs #3274
Filed alongside: #3281 (autoresearch migration off platformio.ini)
Summary by CodeRabbit
Documentation
added-inannotations for new non-comment changes.Chores
added-inannotations are missing for newly added semantic lines.