"""Adversarial + false-positive corpora (BRIEF §9, PLAN §120). Two labeled corpora, both asserted against the real detectors: * **Adversarial** — one payload per detection channel (carriers + each obfuscation variant + secret egress). We measure *recall* and assert it is total: every planted class is caught. A silent drop here is a regression. * **False-positive** — content that legitimately *resembles* an attack (security docs discussing injection, secret-shaped placeholders, high-entropy checksums). Under a trusted source these must dispose ``WARN``, not block — and the strongest signal is that most produce *no finding at all* (the suppression rules hold). Hard-fail / quarantine is an explicit opt-in via policy, shown by the same finding escalating under the high-untrust upload preset. """ from __future__ import annotations import base64 import codecs import pytest from llm_ingestion_guard import ( prepare_input, scan_output, decide, Report, Source, Disposition, PRESET_TRUSTED_SOURCE, PRESET_USER_UPLOAD, ) def _scan_input(text: str) -> Report: """Sanitize+fence then scan — the input-side detection a pipeline runs.""" combined = Report() prepared = prepare_input(text) combined.extend(prepared.report.findings) combined.extend(scan_output(prepared.fenced, source=Source.INPUT).findings) return combined # --- adversarial corpus: (id, payload, expected label) --------------------- _TAG = "".join(chr(0xE0000 + ord(c)) for c in "hi") _ADVERSARIAL = [ ("carrier-zero-width", "impor​tant", "sanitize:zero-width"), ("carrier-bidi", "‮kcatta", "sanitize:bidi-override"), ("carrier-unicode-tag", f"legit{_TAG}", "sanitize:unicode-tag"), ("carrier-html-comment", "", "sanitize:html-comment"), ("carrier-data-uri", "data:text/html,