Add fast-check property tests for placeholder and pii-redact Luhn#136
Merged
Conversation
Property-based tests cover invariants that example-based tests can't easily enumerate: that `replaceMatchesInTextNode` preserves all non-matched text, emits exactly one inline placeholder per disjoint match, and round-trips through reveal back to the original text; and that the PII detector masks every Luhn-valid card number while leaving Luhn-invalid digit runs of the same shape alone. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
fast-checkas a dev dependency inextension/.replaceMatchesInTextNode(extension/src/lib/__tests__/placeholder.property.test.ts): no-op on empty matches; one inline placeholder per disjoint match; non-matched text preserved exactly and in order; reveal round-trips back to the original text; overlapping matches are dropped, not double-replaced.pii-redact(extension/src/rules/__tests__/pii-redact.property.test.ts): every Luhn-valid 13–19-digit number is masked; the same numbers with a single-digit flip (Luhn-invalid, same shape) are left alone.Why fast-check here
These two surfaces have small invariants that are tedious to enumerate by example: the placeholder replacer is cursor-driven and easy to break on overlap/order changes, and the Luhn check sits behind a regex that admits many digit shapes the checksum then has to reject. Property tests give us a regression net for refactors without us having to hand-build cases at every boundary.
Test plan
bun run preflight— biome, eslint, tsc (src + tests), knip, jest with coverage (1015 tests, both new suites included).🤖 Generated with Claude Code