Repository navigation
fix(pacquet-cli): align outdated table borders when output is colorized - #13227
Conversation
pacquet renders the `pnpm outdated` report with the `tabled` crate, whose ANSI-handling (`ansi`) feature is not enabled by default. On a terminal the cells are colorized (blue headers, green/yellow/red `Latest` version segments, dim `(dev)`/`(github action)` labels), and without the feature `tabled` counts the invisible color-escape bytes toward each cell's width. Cells carry different amounts of escape codes, so columns were padded inconsistently and the box-drawing borders drifted out of alignment. Enable the `tabled` `ansi` feature so widths are measured by display columns, ignoring SGR escapes. This also corrects the `outdated --long`, recursive, `licenses`, and `audit` tables, which share the crate. The TypeScript CLI is unaffected: it renders with `@zkochan/table`, which is already ANSI-width-aware, so this is a Rust-only fix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Satisfy the `perfectionist::macro-trailing-comma` dylint rule for the multi-line `assert!` in the colored-table alignment regression test. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
📝 WalkthroughWalkthroughEnables ANSI support for ChangesOutdated table ANSI alignment
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested labels: Suggested reviewers: ✨ 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 |
PR Summary by QodoFix pacquet-cli outdated table alignment when output is colorized
AI Description
Diagram
High-Level Assessment
Files changed (4)
|
Micro-Benchmark ResultsLinux |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (4): Last reviewed commit: "test(pacquet-cli): color outdated table ..." | Re-trigger Greptile |
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pnpm/crates/cli/src/cli_args/outdated/tests.rs (1)
193-202: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winExercise the
longrendering branches.The regression test only passes
false, leaving bothDetails-column paths untested. Add colored assertions forrender_table(..., true)andrender_recursive_table(..., true); add equivalent coverage for licenses/audit if they use separate table renderers.As per path instructions, regression tests should prove the user-visible behavior and have matching coverage.
Suggested coverage
assert_borders_aligned(&render_table(&packages, false)); + assert_borders_aligned(&render_table(&packages, true)); assert_borders_aligned(&render_recursive_table(&workspace, false)); + assert_borders_aligned(&render_recursive_table(&workspace, true));🤖 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 `@pnpm/crates/cli/src/cli_args/outdated/tests.rs` around lines 193 - 202, Extend the regression tests around render_table and render_recursive_table to exercise the long=true Details-column branches, asserting the colored output and border alignment alongside the existing false cases. If licenses or audit have separate table renderers, add equivalent long-mode colored assertions for those renderers as well.Source: Path instructions
🤖 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 `@pnpm/crates/cli/src/cli_args/outdated/tests.rs`:
- Around line 172-178: Update assert_borders_aligned to strip ANSI escape
sequences and extract every vertical border position from each row, then assert
those positions match across all rows. Do not rely solely on equal total display
widths, so compensating column shifts are detected.
- Around line 184-205: The colored_table_borders_stay_aligned test leaves the
process-global owo_colors override active if an assertion panics. Add a
Drop-based guard that enables the override on setup and reliably calls
unset_override during cleanup, and ensure these override-dependent tests run
serially by applying the repository’s existing serial-test mechanism or
equivalent test-thread constraint.
---
Nitpick comments:
In `@pnpm/crates/cli/src/cli_args/outdated/tests.rs`:
- Around line 193-202: Extend the regression tests around render_table and
render_recursive_table to exercise the long=true Details-column branches,
asserting the colored output and border alignment alongside the existing false
cases. If licenses or audit have separate table renderers, add equivalent
long-mode colored assertions for those renderers as well.
🪄 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 Plus
Run ID: 0b361c83-729d-4cb2-b17f-affd3b6564c9
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (3)
.changeset/outdated-table-ansi-alignment.mdCargo.tomlpnpm/crates/cli/src/cli_args/outdated/tests.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13227 +/- ##
==========================================
- Coverage 86.94% 86.93% -0.01%
==========================================
Files 527 527
Lines 90053 90101 +48
==========================================
+ Hits 78298 78333 +35
- Misses 11755 11768 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…se visible_width Address review feedback on the colored-table alignment test: - The test flipped the process-global `owo_colors` override and only cleared it at the end, so a panic mid-test would leave forced color on for the rest of the process and a concurrent test could observe it. Guard the override with an RAII `ForcedColor` (clears on drop) and serialize the toggling tests behind a module-local mutex. - Reuse the existing `pacquet_default_reporter::format::visible_width` instead of a second, less-correct ANSI-width helper in the test module.
…le test Comparing only total row width could miss an inner separator shifting while another column compensates. Extract the visible column index of every box-drawing vertical border (skipping ANSI escapes) and assert those positions match across all rows, which directly tests that the borders line up.
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
Notes on the two remaining summary-level findings: Changeset missing Duplicate Written by an agent (Claude Code, claude-opus-4-8). |
|
Code review by qodo was updated up to the latest commit 9bc84fe |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
…lobal override The regression test forced `owo_colors`' process-global color override on for its duration. Even guarded by an RAII reset and a module-local mutex, other tests in the same binary that render color-gated output could still observe the override while it was set, since they don't take the lock. Drop the override entirely: color the cells with `owo_colors`' unconditional styling (which emits ANSI regardless of TTY detection) and feed them through a modern-style `tabled` table the way the renderers do. The test now touches no process-global state, so it is fully parallel-safe and still fails without the `tabled` `ansi` feature.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pnpm/crates/cli/src/cli_args/outdated/tests.rs (1)
192-200: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winKeep only the non-obvious test-isolation rationale.
Most of this comment narrates the test fixture. Reduce it to why direct ANSI styling is required: it avoids
owo_colorsprocess-global state in parallel tests.Proposed revision
-// Enabling `tabled`'s `ansi` feature makes it size a colored cell by its -// visible glyphs, not its escape bytes; without it the columns and borders -// drift apart. Feed a modern-style table the kind of ANSI-colored cells the -// `outdated` renderers emit — a highlighted version segment, a dim group -// label, bright-blue headers — and confirm every vertical border lands on the -// same column. Coloring the cells directly (`owo_colors` unconditional -// styling) rather than forcing the global color override keeps the test free -// of process-global state, so it can't leak into or be perturbed by other -// tests running in the same binary. +// Build ANSI sequences directly to avoid `owo_colors`' process-global override, +// keeping this parallel test isolated.As per coding guidelines, Rust comments should explain only “non-obvious reasons or invariants.”
🤖 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 `@pnpm/crates/cli/src/cli_args/outdated/tests.rs` around lines 192 - 200, Shorten the comment above the ANSI-colored table test to retain only the non-obvious isolation rationale: style cells directly with owo_colors to avoid its process-global color state affecting or being affected by parallel tests. Remove the fixture, rendering, and table-layout narration.Sources: Coding guidelines, Path instructions
🤖 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 `@pnpm/crates/cli/src/cli_args/outdated/tests.rs`:
- Around line 192-200: Shorten the comment above the ANSI-colored table test to
retain only the non-obvious isolation rationale: style cells directly with
owo_colors to avoid its process-global color state affecting or being affected
by parallel tests. Remove the fixture, rendering, and table-layout narration.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8e695b53-5cf6-4e9e-b5f2-ab440cbc5594
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock,!Cargo.lock
📒 Files selected for processing (1)
pnpm/crates/cli/src/cli_args/outdated/tests.rs
|
Code review by qodo was updated up to the latest commit f63e010 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Summary
pnpm outdatedrenders a misaligned table on a terminal: the columns and box-drawing borders drift out of alignment, producing what looks like a spurious empty column.The report is rendered (in the Rust
pnpm/port) with thetabledcrate, whose ANSI-handling (ansi) feature is not enabled by default. When the output goes to a TTY the cells are colorized — the blue headers, the green/yellow/red highlighted segment of theLatestversion, and the dim(dev)/(github action)labels — and without the featuretabledcounts the invisible color-escape bytes toward each cell's width. Because different cells carry different amounts of escape codes, columns get padded inconsistently and the borders no longer line up.Enabling
tabled'sansifeature makes it measure width by display columns, ignoring SGR escapes. This also corrects theoutdated --long, recursive,licenses, andaudittables, which share the crate.The TypeScript CLI is not affected: it renders with
@zkochan/table, which is already ANSI-width-aware (verified directly — colored cells still produce equal-width, aligned rows). So this is a Rust-only fix; there is no counterpart change to make on the TS side.Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting. (Rust-only bug; the TS CLI is already correct — see Summary.)pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-4-8).
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
pnpm outdatedwhen ANSI-colored output is enabled.Tests