Skip to content

test: cover ProfanityFilter edge cases (#940) - #1100

Open
lily1c wants to merge 1 commit into
llm4s:mainfrom
lily1c:test/940-profanity-filter-gaps
Open

test: cover ProfanityFilter edge cases (#940)#1100
lily1c wants to merge 1 commit into
llm4s:mainfrom
lily1c:test/940-profanity-filter-gaps

Conversation

@lily1c

@lily1c lily1c commented Jul 19, 2026

Copy link
Copy Markdown

What does this PR do?

Adds edge-case tests for the ProfanityFilter guardrail.

While looking at #940 I found that ProfanityFilter already has coverage — it
lives in SimpleValidatorSpec.scala in the same package rather than a
standalone ProfanityFilterSpec.scala. (Same reason the issue's pointer to
LengthCheckSpec.scala 404s: LengthCheck is covered in that combined file
too.) Rather than duplicate the file, this adds the cases that weren't yet
covered:

  • caseSensitive mode combined with customBadWords — previously untested together
  • withCustomWords(Set.empty) falls back to default behaviour
  • tab and newline separators (split("\\s+") handles these, but it wasn't asserted)
  • a bad word after leading whitespace, where the split produces an empty first token
  • punctuation-attached tokens — see below

Known limitation documented, not fixed: validate splits on whitespace
only, so "badword." and "badword," don't match the word list. I've added a
test asserting current behaviour and labelled it a known limitation rather than
silently changing it. Happy to follow up with a fix (stripping punctuation, or a
word-boundary regex) if that's the preferred direction — it seemed like a
behaviour change that should be a maintainer call rather than folded into a
test-only PR.

Two items in #940's acceptance criteria also conflict with the implementation:
obfuscated variants ("F*CK", "f.u.c.k") aren't detectable given the
exact-token matching and two-word default list, and the error message
deliberately withholds the matched word for privacy — there's an existing test
asserting that.

Related issue

Relates to #940

How was this tested?

  • sbt "core/testOnly *SimpleValidatorSpec" — passes
  • sbt scalafmtAll — applied, no diff
  • sbt test — full suite passes

Checklist

  • I have read the Contributing Guide
  • PR is small and focused — one change, one reason
  • sbt scalafmtAll — code is formatted
  • sbt test — tests pass on Scala 3
  • New code includes tests
  • No unrelated changes included (branched from main, not from another PR)
  • Commit messages explain the "why"
  • Updated CHANGELOG.md under [Unreleased] — N/A, tests only

@github-actions

Copy link
Copy Markdown
Contributor

🔒 Claude Code Review Status

Thank you for your contribution! This PR is from an external repository, so automated Claude review is disabled for security reasons.

For maintainers: To get Claude review for this PR, comment @claude and I'll trigger a manual review.

PR Summary:

  • Files changed: 1
  • Additions: +32
  • Deletions: -0
  • Author: @lily1c

@lily1c

lily1c commented Jul 23, 2026

Copy link
Copy Markdown
Author

@claude

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.

1 participant