test(prompt-injection): make the sanitization test able to fail#9666
Open
zied-jlassi wants to merge 1 commit into
Open
test(prompt-injection): make the sanitization test able to fail#9666zied-jlassi wants to merge 1 commit into
zied-jlassi wants to merge 1 commit into
Conversation
The prompt-injection test always reported success: both branches of the result check incremented `passed`, `failed` was never touched, and the only condition tested was whether the input string changed at all. A case whose injection slipped through unchanged was still counted as a pass, so a regression in the sanitizer could never turn the suite red. Give each case explicit expectations (substrings that must be removed and markers that must appear) and assert them, incrementing `failed` and exiting non-zero when an expectation is not met. The existing cases still pass; a broken sanitizer now makes the suite fail as it should.
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.
Problem
scripts/test/test-prompt-injection.tsalways reported success regardless of the outcome:failedis declared but never incremented.As a result
failed === 0is always true, the script always prints "All tests passed!" and always exits 0 — a regression in the sanitizer could never make this suite fail.Fix
Give each test case explicit, checkable expectations:
mustNotSurvive: substrings that must be absent from the sanitized output.mustAppear: substrings that must be present (e.g.[REDACTED], the truncation notice).The runner now asserts these, increments
failedon any unmet expectation, and exits non-zero — turning a no-op script into a real regression test.Verification
npm run build(tsc): passes.Scope
This PR only fixes the test oracle's correctness. It intentionally does not broaden the payload corpus; the existing cases are kept as-is.