Why it matters
lib/utils/pii.test.ts currently has exactly one test: a single sentence containing one email and one US phone number. lib/utils/pii.ts handles considerably more than that, and its own doc comment says the patterns "may over-match in edge cases". Right now nothing in the suite pins down what that over-matching actually is, so a future tweak to PHONE_PATTERN could silently change behaviour on real submissions.
What to change
Extend lib/utils/pii.test.ts with cases that lock in current behaviour of redactEmails, redactPhones, and redactPii:
- Multiple emails in one string, all redacted.
- An international format such as
+44 7700 900123.
- A digit run shorter than
MIN_PHONE_DIGITS (7), which should be left alone, for example call 555-1212 versus ext 12.
- A long digit run that is not a phone number (an order ID, a token count). Write the assertion for what the code does today and add a short comment noting it is a known over-match, so the behaviour is documented rather than accidental.
- Text with no PII at all passes through unchanged.
Notes
- Run with
npm test. Vitest is already configured via vitest.config.ts.
- If a case makes you think the regex itself is wrong rather than the test, say so in the PR description. That is a useful finding, not a problem.
Questions are very welcome. Comment here to claim it and ask anything you are unsure about, you will usually get a reply within a day.
Why it matters
lib/utils/pii.test.tscurrently has exactly one test: a single sentence containing one email and one US phone number.lib/utils/pii.tshandles considerably more than that, and its own doc comment says the patterns "may over-match in edge cases". Right now nothing in the suite pins down what that over-matching actually is, so a future tweak toPHONE_PATTERNcould silently change behaviour on real submissions.What to change
Extend
lib/utils/pii.test.tswith cases that lock in current behaviour ofredactEmails,redactPhones, andredactPii:+44 7700 900123.MIN_PHONE_DIGITS(7), which should be left alone, for examplecall 555-1212versusext 12.Notes
npm test. Vitest is already configured viavitest.config.ts.Questions are very welcome. Comment here to claim it and ask anything you are unsure about, you will usually get a reply within a day.