Skip to content

Expand PII redaction test coverage beyond the single happy-path case #19

Description

@royalpinto007

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions