Skip to content

test: property-check display-width clustering and parseKey totality#598

Open
ndycode wants to merge 2 commits into
mainfrom
claude/audit-79-display-width-property
Open

test: property-check display-width clustering and parseKey totality#598
ndycode wants to merge 2 commits into
mainfrom
claude/audit-79-display-width-property

Conversation

@ndycode

@ndycode ndycode commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

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):

  1. Totality and boundsdisplayWidth returns a non-negative integer bounded by two columns per code point, for any combination including pathological joiner/modifier soup.
  2. 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).
  3. Truncation contracttruncateToWidth returns a prefix whose reported width is displayWidth of 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.
  4. Budget monotonicity — widening the budget only ever extends the kept prefix.

parseKey:

  1. Totality — arbitrary byte buffers always produce a member of the KeyAction union; no input throws.
  2. 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

  • 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=0

Docs and Governance Checklist

  • 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 to null.

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
Loading

Reviews (2): Last reviewed commit: "test: make the 2-column cluster granular..." | Re-trigger Greptile

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
@chatgpt-codex-connector

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1a5f99eb-c584-44f6-9664-9d51f0366670

📥 Commits

Reviewing files that changed from the base of the PR and between dae10cb and 70707c9.

📒 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread test/property/display-width.property.test.ts
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants