Skip to content

feat(shrink): per-platform registry + green reporting one-liner (#498, part of #493) - #499

Merged
zackees merged 1 commit into
mainfrom
shrink/phase-1d-reporting
Jun 8, 2026
Merged

zackees merged 1 commit into
mainfrom
shrink/phase-1d-reporting

Conversation

@zackees

@zackees zackees commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Phase 1d of the --shrink design (#493). Lands the per-platform shrinker registry type and the green auto shrinking: … one-liner reporter — both with empty data so the user-facing behavior stays silent on every platform until subsequent phases populate the registry.

Closes #498.

Public API

  • fbuild_build::shrink::registry::AutoShrinkEntry { category, symbols } — a single shrinker the auto-resolver applies on a given platform. category is the short human-readable name used by the verbose plan; symbols is what the green one-liner enumerates.
  • fbuild_build::shrink::registry::registry_for(Platform) -> &'static [AutoShrinkEntry] — per-platform lookup. Returns &[] for every platform in Phase 1d; phases 4–6 populate per-platform as each shrinker (printf-thin, scanf-thin, stdio FILE strip, …) lands.
  • fbuild_build::shrink::reporting::print_auto_shrinking_line(out, entries) — writes the green one-liner to any io::Write. When entries is empty, writes nothing. Uses owo-colors (already a workspace dep) which auto-disables on non-tty and respects NO_COLOR.

Tests added

  • 2 unit tests in registry::tests — every platform empty, struct shape.
  • 5 unit tests in reporting::tests:
    • empty registry prints nothing
    • registry with empty symbols prints nothing
    • single entry lists its symbols (ANSI stripped)
    • multiple entries are concatenated
    • output contains ANSI green when color enabled

Dependencies

Test plan

  • cargo test -p fbuild-build --lib shrink:: — 12/12 pass (5 from Phase 1a + 7 new)
  • cargo clippy --workspace --all-targets -- -D warnings exits 0
  • CI green

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Implemented auto-shrinking status reporting capability with colored output formatting for build messages.
  • Documentation

    • Expanded module documentation with phased implementation details for the shrinking feature.

… part of #493)

Phase 1d of the --shrink design (#493). Lands the per-platform shrinker
registry type and the green `auto shrinking: ...` one-liner reporter, both
with empty data so the user-facing behavior stays silent on every platform
until subsequent phases populate the registry.

Public API:

- `fbuild_build::shrink::registry::AutoShrinkEntry { category, symbols }` —
  a single shrinker the auto-resolver applies on a given platform. `category`
  is the short human-readable name used by the verbose plan; `symbols` is
  what the green one-liner enumerates.
- `fbuild_build::shrink::registry::registry_for(Platform) -> &'static [AutoShrinkEntry]`
  — per-platform lookup. Returns `&[]` for every platform in Phase 1d;
  phases 4-6 populate per-platform as each shrinker (printf-thin,
  scanf-thin, stdio FILE strip, ...) lands.
- `fbuild_build::shrink::reporting::print_auto_shrinking_line(out, entries)`
  — writes the green one-liner to any `io::Write`. When `entries` is empty,
  writes nothing. Uses `owo-colors` (already a workspace dep) which
  auto-disables on non-tty and respects `NO_COLOR`.

Tests:

- 2 unit tests in `registry::tests` — every platform empty, struct shape.
- 5 unit tests in `reporting::tests`:
  - empty registry prints nothing
  - registry with empty symbols prints nothing
  - single entry lists its symbols (ANSI stripped)
  - multiple entries are concatenated
  - output contains ANSI green when color enabled

owo-colors added to fbuild-build's dependencies (was already in the
workspace deps from #495).

All `cargo test -p fbuild-build --lib shrink::` pass (12/12 — 5 from
Phase 1a + 7 new). `clippy --workspace --all-targets -- -D warnings` exits 0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR adds phase 1d of the --shrink feature infrastructure. It introduces the AutoShrinkEntry registry type and print_auto_shrinking_line() reporting function, both with empty/stub implementations, plus a new owo-colors dependency for styled output.

Changes

Phase 1d: Auto-shrink registry and reporting

Layer / File(s) Summary
Dependency and module structure
crates/fbuild-build/Cargo.toml, crates/fbuild-build/src/shrink/mod.rs
Adds owo-colors workspace dependency and updates module documentation with phase 1d activation notes for per-platform registry and reporting modules.
Registry type and per-platform stub function
crates/fbuild-build/src/shrink/registry.rs
Defines AutoShrinkEntry struct with category and symbols fields, implements registry_for(platform) returning an empty slice for all platforms in phase 1d, and includes tests validating empty registries and basic struct construction.
Reporting implementation with colored output
crates/fbuild-build/src/shrink/reporting.rs
Implements print_auto_shrinking_line() to emit a green-styled one-liner status message with flattened symbol lists, conditional output when registries are empty, and comprehensive tests covering output format, ANSI styling, and edge cases.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

  • FastLED/fbuild#493: Phase 1 meta-issue that defines the overall --shrink feature roadmap; this PR implements the phase 1d checkpoint (registry type and green reporting one-liner).

Possibly related PRs

  • FastLED/fbuild#495: Updates shrink module documentation with phase roadmap context that this PR builds upon with actual registry and reporting implementations.

Poem

🐰 A registry takes shape, green hues appear,
Future phases whisper: your shrink data here,
Colors are ready, the structure's in place,
Empty for now, but we're winning the race! 🎨✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 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 describes the main changes: per-platform registry and green reporting one-liner, with linked issue references.
Linked Issues check ✅ Passed All coding requirements from issue #498 are met: AutoShrinkEntry struct defined, registry_for function returns empty slice, print_auto_shrinking_line implemented with green coloring, and unit tests added.
Out of Scope Changes check ✅ Passed All changes align with Phase 1d scope; owo-colors dependency addition supports the green reporting requirement, and no populating of real registry entries or other out-of-scope items included.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ 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 shrink/phase-1d-reporting

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.

🧹 Nitpick comments (2)
crates/fbuild-build/src/shrink/reporting.rs (1)

67-85: 💤 Low value

Consider documenting the ASCII-only assumption.

The byte-by-byte as char cast at line 80 will corrupt multi-byte UTF-8 characters. For example, an emoji would be split into multiple mojibake characters instead of being preserved correctly.

In practice, this helper only processes output from print_auto_shrinking_line, which contains ASCII-only C symbol names, so the issue won't occur. However, the function signature fn strip_ansi(s: &str) doesn't indicate this limitation.

📝 Suggested improvements

Option 1: Document the ASCII assumption

 /// Strip ANSI escape sequences from `s` so the assertion text doesn't
 /// have to embed terminal codes. Handles the small subset emitted by
-/// `owo-colors` (CSI `<params>` `m`).
+/// `owo-colors` (CSI `<params>` `m`).
+///
+/// Note: Assumes ASCII input. Multi-byte UTF-8 would be corrupted, but
+/// the current usage (C symbol names) is ASCII-only.
 fn strip_ansi(s: &str) -> String {

Option 2: Use proper UTF-8 handling

 fn strip_ansi(s: &str) -> String {
-    let bytes = s.as_bytes();
-    let mut out = String::with_capacity(bytes.len());
-    let mut i = 0;
-    while i < bytes.len() {
-        if bytes[i] == 0x1b && i + 1 < bytes.len() && bytes[i + 1] == b'[' {
-            // Skip until the terminating letter (A–Z, a–z).
-            i += 2;
-            while i < bytes.len() && !bytes[i].is_ascii_alphabetic() {
-                i += 1;
-            }
-            i += 1; // skip the terminator itself
-        } else {
-            out.push(bytes[i] as char);
-            i += 1;
-        }
-    }
-    out
+    let mut out = String::with_capacity(s.len());
+    let mut chars = s.chars().peekable();
+    while let Some(c) = chars.next() {
+        if c == '\x1b' && chars.peek() == Some(&'[') {
+            chars.next(); // consume '['
+            // Skip until terminating letter
+            while let Some(&c) = chars.peek() {
+                chars.next();
+                if c.is_ascii_alphabetic() {
+                    break;
+                }
+            }
+        } else {
+            out.push(c);
+        }
+    }
+    out
 }
🤖 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 `@crates/fbuild-build/src/shrink/reporting.rs` around lines 67 - 85, The
strip_ansi function currently iterates bytes and casts each byte to char (the
bytes[i] as char at the push site), which will corrupt multi‑byte UTF‑8; either
document that strip_ansi(s: &str) only supports ASCII input or implement proper
UTF‑8 handling. To fix quickly, add a clear doc comment above fn strip_ansi(s:
&str) stating it assumes ASCII-only input (used for ASCII C symbol names), and
leave the byte-based logic; alternatively replace the byte loop with a
char-aware implementation that iterates s.chars(), detects and skips ANSI
sequences while preserving multi-byte characters. Ensure references to the
byte-to-char cast and the ANSI-skip loop (the inner while scanning until
.is_ascii_alphabetic()) are updated accordingly.
crates/fbuild-build/src/shrink/registry.rs (1)

49-73: Phase 1d empty-registry test covers all current Platform variants, but needs future-proofing.

The test’s manual list matches the 15 Platform variants defined in crates/fbuild-core/src/lib.rs, so there’s no current coverage gap. Since Platform doesn’t expose a variants()/ALL helper, it will require manual updates when new variants are added—consider adding a centralized variant list (e.g., Platform::ALL) in fbuild-core and iterating it here.

🤖 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 `@crates/fbuild-build/src/shrink/registry.rs` around lines 49 - 73, The test
every_platform_returns_empty_in_phase_1d currently hardcodes all Platform
variants and should iterate a centralized variant list to be future-proof;
update the test to iterate Platform::ALL (or whatever centralized
constant/iterator you add in fbuild-core) instead of the manual array, using
registry_for(platform).is_empty() and registry_for(platform).len() as before—if
Platform::ALL doesn't exist yet, add a public Platform::ALL (or variants() ->
impl Iterator<Item=Platform>) in fbuild-core and then use that here so new
variants are automatically covered.
🤖 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.

Nitpick comments:
In `@crates/fbuild-build/src/shrink/registry.rs`:
- Around line 49-73: The test every_platform_returns_empty_in_phase_1d currently
hardcodes all Platform variants and should iterate a centralized variant list to
be future-proof; update the test to iterate Platform::ALL (or whatever
centralized constant/iterator you add in fbuild-core) instead of the manual
array, using registry_for(platform).is_empty() and registry_for(platform).len()
as before—if Platform::ALL doesn't exist yet, add a public Platform::ALL (or
variants() -> impl Iterator<Item=Platform>) in fbuild-core and then use that
here so new variants are automatically covered.

In `@crates/fbuild-build/src/shrink/reporting.rs`:
- Around line 67-85: The strip_ansi function currently iterates bytes and casts
each byte to char (the bytes[i] as char at the push site), which will corrupt
multi‑byte UTF‑8; either document that strip_ansi(s: &str) only supports ASCII
input or implement proper UTF‑8 handling. To fix quickly, add a clear doc
comment above fn strip_ansi(s: &str) stating it assumes ASCII-only input (used
for ASCII C symbol names), and leave the byte-based logic; alternatively replace
the byte loop with a char-aware implementation that iterates s.chars(), detects
and skips ANSI sequences while preserving multi-byte characters. Ensure
references to the byte-to-char cast and the ANSI-skip loop (the inner while
scanning until .is_ascii_alphabetic()) are updated accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: efc55fad-d6b1-48dc-83d0-afeee7bef18f

📥 Commits

Reviewing files that changed from the base of the PR and between 0405e35 and 9594355.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • crates/fbuild-build/Cargo.toml
  • crates/fbuild-build/src/shrink/mod.rs
  • crates/fbuild-build/src/shrink/registry.rs
  • crates/fbuild-build/src/shrink/reporting.rs

@zackees
zackees merged commit 95a5147 into main Jun 8, 2026
87 checks passed
@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Jun 8, 2026
@zackees
zackees deleted the shrink/phase-1d-reporting branch October 16, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

Phase 1d: AutoShrinkEntry registry + green reporting one-liner

1 participant