test: property-check display-width clustering and parseKey totality#598
test: property-check display-width clustering and parseKey totality#598ndycode wants to merge 2 commits into
Conversation
Six fast-check properties over the ui-02 measurement layer and the stdin key parser: - displayWidth is total, integer, non-negative, and bounded by two columns per code point over an adversarial alphabet (ZWJ, VS-16, keycap, combining marks, skin tones, regional indicators, CJK, emoji) - plain alphabets (no joiners/modifiers) sum per-character widths exactly and concatenate additively - the table formatter's standing assumption - truncateToWidth returns a self-consistent prefix (its reported width IS displayWidth of the kept text), stays in budget, stops only when the remaining gap is 0 or 1 columns (clusters max out at 2), and is idempotent - truncation prefixes grow monotonically with the width budget - parseKey is total over arbitrary byte buffers and only returns known KeyAction values - the full recognized-sequence table is pinned, and everything else maps to null Companion to the property suites in #574/#575/#592-#597. https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
Warning Review limit reached
More reviews will be available in 11 minutes and 7 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
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 |
One extra budget column can admit at most two more columns of content, which is externally equivalent to 'no cluster wider than 2' - the assumption the truncation maximality bound relies on. https://claude.ai/code/session_01XNtnkLbBiXZxfQQYLMpucB
Summary
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):
displayWidthreturns a non-negative integer bounded by two columns per code point, for any combination including pathological joiner/modifier soup.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.parseKey:
KeyActionunion; no input throws.null.No SUT bugs found.
Validation
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)npm run typecheck(also via pre-commit hook)npx eslint test/property/display-width.property.test.ts --max-warnings=0Docs and Governance Checklist
Risk and Rollback
test/property/suites.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) andparseKeytotality + table fidelity. no sut code is changed.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
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| JReviews (2): Last reviewed commit: "test: make the 2-column cluster granular..." | Re-trigger Greptile