test: property-check display-width clustering and parseKey totality
Summary
- Adds a fast-check property suite for the layer beneath #595:
lib/ui/display-width.ts(the ui-02 column-measurement implementation with grapheme clustering) andlib/ui/ansi.ts'sparseKey(raw stdin bytes → key action, which must be total).
What Changed
New test/property/display-width.property.test.ts (6 properties):
display-width — generated over an adversarial alphabet that includes every cluster mechanic the implementation special-cases (ZWJ, variation selector-16, combining keycap, combining accents, skin-tone modifiers, regional indicators, CJK, emoji):
- Totality and bounds —
displayWidthreturns a non-negative integer bounded by two columns per code point, for any combination including pathological joiner/modifier soup. - Plain-alphabet oracle — with no joiners/modifiers present, width equals the per-character sum and concatenation is exactly additive — the standing assumption the table formatter's geometry rests on (deliberately not asserted for the adversarial alphabet, where VS-16 promotion makes concatenation legitimately non-additive).
- Truncation contract —
truncateToWidthreturns a prefix whose reported width isdisplayWidthof the kept text (self-consistency between the two exports), never exceeds the budget, stops early only when the remaining gap is 0–1 columns (clusters max out at 2, so a 2-column gap proves the next cluster would have fit), and is idempotent. - Budget monotonicity — widening the budget only ever extends the kept prefix.
parseKey:
- Totality — arbitrary byte buffers always produce a member of the
KeyActionunion; no input throws. - Table fidelity — all 16 recognized ANSI sequences map to their documented actions, and every other generated string maps to
null.
No SUT bugs found.
Validation
- [x]
npm test -- test/property/display-width.property.test.ts test/display-width.test.ts test/ansi.test.ts— 25/25 (new 6 + existing suites untouched) - [x]
npm run typecheck(also via pre-commit hook) - [x]
npx eslint test/property/display-width.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. - 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 property-based test file covering displayWidth/truncateToWidth (6 properties over an adversarial grapheme-cluster alphabet) and parseKey totality + table fidelity. no sut code is changed.
- display-width suite: totality/bounds, plain-alphabet oracle, truncation self-consistency + maximality + idempotence, and budget monotonicity — the step assertion in the monotonicity property explicitly self-enforces the "no cluster wider than 2" assumption that the maximality bound relies on.
- parseKey suite: arbitrary byte-buffer totality via
fc.uint8Array, and an exact-match table check for all 16 documented ansi sequences followed by a property asserting every other generated string maps tonull.
Confidence Score: 5/5
additive test file only; no sut code touched and no filesystem or token handling introduced.
every changed line is a new test. the property invariants are logically correct — oracle values checked against the sut, all 16 ansi sequences in the fidelity table match the implementation exactly, and the monotonicity step assertion self-enforces the cluster-width assumption that the maximality bound relies on. no concurrency, windows-path, or token-safety concerns arise in a stateless property suite.
no files require special attention.
Important Files Changed
| Filename | Overview |
|---|---|
| test/property/display-width.property.test.ts | new property suite — 6 tests, logically sound; all oracle values verified against the sut, the ansi table matches all 16 sut branches exactly, and the step assertion makes the cluster-width assumption explicit. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[display-width.property.test.ts] --> B[display-width invariants]
A --> C[parseKey invariants]
B --> D["totality & bounds\narbAdversarialText → non-neg int ≤ codePoints×2"]
B --> E["plain-alphabet oracle\narbPlainText → sum matches per-char + additive split"]
B --> F["truncation contract\nself-consistency · in-budget · prefix · maximality · idempotence"]
B --> G["budget monotonicity\nnarrower prefix ⊆ wider prefix · step width ≤ narrow+2"]
C --> H["totality\nfc.uint8Array → always a known KeyAction"]
C --> I["table fidelity\n16 ANSI sequences exact-match · fc.string !known → null"]
F -->|depends on| J["cluster width ≤ 2\n(assumed)"]
G -->|self-enforces| J
Reviews (2): Last reviewed commit: "test: make the 2-column cluster granular..." | 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 40 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:
83bee9f1-301b-4626-93ee-50032ec71ad6📥 Commits
Reviewing files that changed from the base of the PR and between fa9bde30aea8a966d717907cb005dea514d59927 and d969f5f6da37c36622baf75f3945a0c509a3a637.
📒 Files selected for processing (1)
test/property/display-width.property.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Commit unit tests in branch
claude/audit-79-display-width-property
✨ Simplify code
- [ ] Create PR with simplified code
- [ ] Commit simplified code in branch
claude/audit-79-display-width-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.