test: property-check table formatter alignment under unicode content
Summary
- Adds a fast-check property suite for
lib/table-formatter.ts, the CLI table renderer whose alignment guarantee (ui-02) is "measure in display columns, not UTF-16 code units". Property generation is the right tool here: the interesting inputs are exactly the awkward ones — CJK doubles, emoji, wide glyphs straddling a truncation boundary, rows with missing or extra cells.
What Changed
New test/property/table-formatter.property.test.ts (4 properties over buildTable/buildTableRow, cell content drawn from a mixed ASCII/CJK/emoji alphabet):
- Lockstep layout — every line of any table (header, separator, every data row) has exactly the layout's display width, for any column set (widths 0–10), any alignment mix, and rows that are shorter or longer than the column count.
- Fit preservation — content that fits is rendered verbatim with padding on the declared side (
left/right), padding computed in display columns. - Truncation contract — overflowing content truncates to a prefix of the original plus an ellipsis, never exceeding the column width even when a wide glyph can't fill the final column (the case the ui-02 comment in
formatCelldocuments). - Zero-width columns — render empty rather than leaking a one-column ellipsis that would desync the row from the header/separator layout (the documented short-circuit in
formatCell).
No SUT bugs found; the renderer's geometry held for every generated case.
Validation
- [x]
npm test -- test/property/table-formatter.property.test.ts test/table-formatter.test.ts— 15/15 (new 4 + existing 11 untouched) - [x]
npm run typecheck(also via pre-commit hook) - [x]
npx eslint test/property/table-formatter.property.test.ts --max-warnings=0
Docs and Governance Checklist
- [x] Test-only; no behavior or docs surface changed
Risk and Rollback
- Risk level: minimal — additive test file; conventions match the existing
test/property/suites (explicit vitest imports, plainfc.assert,fc.preto partition fit vs overflow). - Rollback plan: revert the single commit.
https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Generated by Claude Code
note: greptile review for oc-chatgpt-multi-auth. cite files like lib/foo.ts:123. confirm regression tests + windows concurrency/token redaction coverage.
Greptile Summary
adds a fast-check property suite for lib/table-formatter.ts covering four invariants: lockstep line width, fit-preservation with padding, truncation to a prefix-plus-ellipsis, and zero-width column emptiness. both issues from the prior review are resolved — the right-aligned overflow prefix check now uses a left-aligned side-channel to avoid stripping content spaces, and arbColumn now generates undefined alignment via fc.option to exercise the default-left branch.
- property 1 (lockstep layout):
expectedLineWidthformulaΣwidth + (n−1)correctly mirrorsArray.join(" ")even for zero-width columns, verified against the sut. - property 3 (truncation contract): prefix fidelity is validated via a dedicated left-aligned render (
leftRow), stripping only trailing padding withreplace(/ +$/, "")— the fix to the previously flagged spurious-failure risk. - property 4 (zero-width): guards the documented
formatCellshort-circuit that prevents an ellipsis from inflating the row width by one column.
Confidence Score: 5/5
additive test file with no production code changes — safe to merge.
the change is a single new test file; it makes no edits to production code, no filesystem i/o, no async/concurrency, and no token or credential handling. both issues raised in the prior round are addressed correctly. the four property invariants are logically sound against the sut.
no files require special attention.
Important Files Changed
| Filename | Overview |
|---|---|
| test/property/table-formatter.property.test.ts | New property suite for table-formatter; both issues from the prior review (right-align prefix conflation and missing undefined-align arm) are now correctly addressed. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[arbCellText\nASCII / CJK / emoji chars] --> B[arbColumn\nheader · width 0-10 · align left/right/undefined]
B --> C[arbOptions\n1-5 columns]
C --> P1[Property 1: Lockstep layout\nevery line == expectedLineWidth]
A --> P2[Property 2: Fit preservation\ndisplayWidth value <= width\nrow == pad+value or value+pad]
A --> P3[Property 3: Truncation contract\ndisplayWidth value > width\nrow ends with … · prefix check via left-aligned side-channel]
A --> P4[Property 4: Zero-width column\nrow == empty string]
P1 --> SUT[buildTable / buildTableRow\nlib/table-formatter.ts]
P2 --> SUT
P3 --> SUT
P4 --> SUT
SUT --> FMT[formatCell\ntruncateToWidth / displayWidth\nlib/ui/display-width.ts]
Reviews (2): Last reviewed commit: "test: validate overflow prefix on the le..." | Re-trigger Greptile
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. Credits must be used to enable repository wide code reviews.
[!WARNING]
Review limit reached
@ndycode, we couldn't start this review because you've reached your PR review rate limit.More reviews will be available in 29 minutes and 53 seconds. Learn how PR review limits work.
Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).
⌛ How to resolve this issue?
After more reviews become available, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.
🚦 How do rate limits work?
CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.
For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.
Please see our Fair Usage Limits Policy for further information.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID:
441cbe9b-47a7-4ff1-9509-c0b8028699a2📥 Commits
Reviewing files that changed from the base of the PR and between 82ff3b0aeb0697d4ef4ec53dac5762be25dcd7ae and 148b38a3c95ece2b599e24b7f37f7ef83a88fb7f.
📒 Files selected for processing (1)
test/property/table-formatter.property.test.ts
📝 Walkthrough
Walkthrough
property test suite validates table-formatter behavior using randomized inputs: ensuring all output lines maintain expected display widths, padding respects alignment when content fits, overflow truncates with ellipsis without exceeding width, and zero-width columns render empty.
Changes
Table formatter property tests
| Layer / File(s) | Summary |
|---|---|
Display width and truncation validation test/property/table-formatter.property.test.ts |
Property-based test suite uses vitest + fast-check to generate randomized table options and cell contents (ascii, cjk, emoji) asserting four invariants: output lines preserve expected display widths, fitted content preserves original characters with alignment-specific padding, overflow truncates with ellipsis respecting column width constraints, and zero-width columns render empty. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
flagged observations
-
missing regression coverage: confirm existing table-formatter unit tests (
test/unit/table-formatter*or similar) still cover edge cases like empty strings, single-character content, and mixed-width boundaries. property tests excel at invariants but unit tests catch specific known regressions. -
windows line-ending risk: verify
test/property/table-formatter.property.test.ts:1-110does not assume unix line endings when validating display width across row separators. if the formatter emits\r\non windows, computed display widths may drift. check whatbuildTablereturns on windows. -
cjk/emoji width assumptions: fast-check generates cjk and emoji—confirm the table-formatter uses a consistent display-width library (like
string-width) across all platforms. if width calculation differs between node versions or terminals, the assertions may flake on ci. -
no concurrency or state-mutation risk detected: this is a stateless property test. good.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | title follows conventional commits format (test: summary), summary is 53 chars in lowercase imperative, clearly describes the property test addition for table formatter unicode handling. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| 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. |
| Description check | ✅ Passed | pr description is comprehensive and well-structured, covering summary, what changed, validation steps, and risk assessment with concrete details about the four properties and edge cases tested. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Commit unit tests in branch
claude/audit-76-table-formatter-property
✨ Simplify code
- [ ] Create PR with simplified code
- [ ] Commit simplified code in branch
claude/audit-76-table-formatter-property
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 @coderabbitai help to get the list of available commands and usage tips.