Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Cover prompt-injection-redact findContainer escalation paths#145

Merged
twschiller merged 1 commit into
mainfrom
coverage/prompt-injection-redact-branches
Jun 5, 2026
Merged

Cover prompt-injection-redact findContainer escalation paths#145
twschiller merged 1 commit into
mainfrom
coverage/prompt-injection-redact-branches

Conversation

@twschiller

Copy link
Copy Markdown
Contributor

Summary

Brings `src/rules/prompt-injection-redact.ts` from 81.25% → 90.62% statements and 44.44% → 77.77% branches. The gap was in `findContainer`'s escalation guard.

What the new tests cover

  • BODY/HTML guard — when injection text lives as a direct text-node child of ``, the rule must not redact (wrapping `` in a placeholder would black out the whole page). Confirms `findContainer` returns null on that branch.
  • Non-block fallback — when the only ancestor is a non-block element (a bare `
    ` / ``, not in `BLOCK_CONTAINER_SELECTOR`), the rule wraps the direct parent rather than escalating further up.

Remaining gap

The three still-uncovered checks (`!parent`, `!element.isConnected`, inner `isInsidePlaceholder` at lines 41/78/81) are defense-in-depth fallbacks. `walkTextNodes` and `filterToOutermost` invariants upstream prevent the conditions from being reachable in normal flow. Leaving them as-is documents intent without forcing synthetic coverage.

Ratchet

`./src/rules/` thresholds 90/77/95/90 → 91/78/96/91.

Test plan

  • `bun run preflight` passes
  • `prompt-injection-redact.ts` branches 44% → 77% in the coverage report
  • `./src/rules/` threshold passes at 91/78/96/91

🤖 Generated with Claude Code

Brings src/rules/prompt-injection-redact.ts from 81.25% to 90.62%
statements and 44.44% to 77.77% branches. The gap was in findContainer's
escalation guard — when the only ancestor is <body>/<html> the rule must
*not* redact (that would black out the whole page), and when the only
ancestor is a non-block element the rule should fall back to the direct
parent rather than escalate further. Both branches now have direct tests.

The remaining uncovered locations (the `!parent`, `!element.isConnected`,
and inner `isInsidePlaceholder` checks at lines 41/78/81) are
defense-in-depth fallbacks that the upstream `walkTextNodes` and
`filterToOutermost` invariants already prevent — leaving them in the
source documents intent but they can't be exercised from a normal DOM.

Ratchet src/rules thresholds 90/77/95/90 → 91/78/96/91.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@vercel

vercel Bot commented Jun 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser-shield-demo-site Ready Ready Preview, Comment Jun 5, 2026 2:39am

Request Review

@twschiller twschiller merged commit fbf3a4e into main Jun 5, 2026
7 checks passed
@twschiller twschiller deleted the coverage/prompt-injection-redact-branches branch June 5, 2026 02:42
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