Skip to content

The agent that grows with you

test(security): one redaction cell per (scenario, sink); #56039 KNOWN covers only the platform wire

teknium147d066e85596
diff --git a/tests/e2e/core/security/_redact.py b/tests/e2e/core/security/_redact.py
index 4aa0a37374b..d7ae7725f66 100644
--- a/tests/e2e/core/security/_redact.py
+++ b/tests/e2e/core/security/_redact.py
@@ -15,10 +15,12 @@ import subprocess
import sys
from dataclasses import dataclass, field
from pathlib import Path
-from typing import Callable
+from typing import Any, Callable
+
+import pytest
from tests.e2e.core.delivery._fake_platform import GatewayProcess, read_jsonl, wait_until
-from tests.e2e.core.security._helpers import REPO_ROOT, db_blob, files_containing, run_hermes
+from tests.e2e.core.security._helpers import REPO_ROOT, BoundaryBreach, db_blob, files_containing, run_hermes
from tests.fakes.fake_llm_provider import Error, Response, Text, ToolCall
@@ -62,6 +64,9 @@ CONTENT_SINKS = (LOGS, STORE, EXPORT, EXPORT_REDACTED, WIRE, PLATFORM)
# user-guide/security.md "The session database itself still holds the command as it was executed");
# the provider replay of the model's own tool call and the default (non --redact) export read it back.
RAW_BY_DESIGN_SINKS = (LOGS, EXPORT_REDACTED, PLATFORM)
+# Test-id spelling of each sink: one cell per (scenario, sink), so a KNOWN names exactly one sink.
+SINK_IDS = {LOGS: "logs", STORE: "store", EXPORT: "export", EXPORT_REDACTED: "export_redact", WIRE: "next_request",
+ PLATFORM: "platform"}
@dataclass(frozen=True)
@@ -226,11 +231,6 @@ def collect(home: Path, requests: list[dict], platform_journal: Path | None = No
EXPORT_REDACTED: {"redacted.jsonl": exports["redacted.jsonl"]}, WIRE: wire, PLATFORM: platform})
-def leak_report(sinks: Sinks, scenario: Scenario, keys: Secrets) -> list[str]:
- needles = scenario.secrets(keys)
- return [hit for sink in scenario.sinks for hit in sinks.hits(sink, needles, only=f"chat {chat_for(scenario.name)}")]
-
-
def chat_for(name: str) -> str:
return f"c-{name}"
@@ -253,16 +253,33 @@ class World:
runs: dict[str, str]
-def check(world: World, scenario: str) -> None:
- """Harness precondition (plain AssertionError), then the boundary (BoundaryBreach, KNOWN-able)."""
- from tests.e2e.core.security._helpers import BoundaryBreach
-
+def cells(known: dict[str, str], *, platform: bool) -> list[Any]:
+ """One ``pytest.param(scenario, sink)`` per sink a scenario is held to (``platform``: the surface has a
+ platform wire). A KNOWN key is a cell id ``<scenario>-<sink id>`` and strict-xfails ONLY that sink, so a
+ new leak of the same scenario into any other sink is a plain red, never absorbed by the known gap."""
+ out, ids = [], set()
+ for name, scenario in SCENARIOS.items():
+ for sink in scenario.sinks:
+ if sink == PLATFORM and not platform:
+ continue
+ cid = f"{name}-{SINK_IDS[sink]}"
+ ids.add(cid)
+ marks = ([pytest.mark.xfail(strict=True, raises=BoundaryBreach, reason=known[cid])]
+ if cid in known else [])
+ out.append(pytest.param(name, sink, id=cid, marks=marks))
+ stale = sorted(set(known) - ids)
+ assert not stale, f"KNOWN names cells that do not exist: {stale}"
+ return out
+
+
+def check(world: World, scenario: str, sink: str) -> None:
+ """Harness precondition (plain AssertionError), then the boundary for ONE sink (BoundaryBreach)."""
missing = world.pre[scenario]
assert not missing, (f"{scenario}: the secret never travelled, so absence proves nothing: {missing}\n"
f"{world.runs[scenario]}")
- leaks = leak_report(world.sinks, SCENARIOS[scenario], world.keys)
+ leaks = world.sinks.hits(sink, SCENARIOS[scenario].secrets(world.keys), only=f"chat {chat_for(scenario)}")
if leaks:
- raise BoundaryBreach(f"{scenario}: secret reached a redacted sink:\n " + "\n ".join(leaks))
+ raise BoundaryBreach(f"{scenario}: secret reached the redacted sink {sink!r}:\n " + "\n ".join(leaks))
# Gateway ------------------------------------------------------------------------------------------
diff --git a/tests/e2e/core/security/test_secret_redaction.py b/tests/e2e/core/security/test_secret_redaction.py
index cc8764c4387..631cf75486f 100644
--- a/tests/e2e/core/security/test_secret_redaction.py
+++ b/tests/e2e/core/security/test_secret_redaction.py
@@ -25,16 +25,16 @@ import sys
import pytest
-from tests.e2e.core.security._helpers import known_param, run_hermes, write_home
+from tests.e2e.core.security._helpers import run_hermes, write_home
from tests.e2e.core.security._redact import (
- CONFIG, SCENARIOS, Ctx, Director, Secrets, World, assert_harness_sane, check, collect, echo_preconditions,
+ CONFIG, SCENARIOS, Ctx, Director, Secrets, World, assert_harness_sane, cells, check, collect, echo_preconditions,
prompt_for, seed_workspace,
)
from tests.fakes.fake_llm_provider import FakeLLMServer
pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="POSIX shell commands (cat | tee, curl)")
-KNOWN: dict[str, str] = {}
+KNOWN: dict[str, str] = {} # cell id ``<scenario>-<sink>`` -> "#issue symptom"
_SESSION_RE = re.compile(r"session_id:\s*(\S+)")
@@ -67,6 +67,6 @@ def cli_world(tmp_path_factory) -> World:
return World(keys, sinks, echo_preconditions(ws, keys, gets, logs), runs)
[email protected]("scenario", [known_param(n, KNOWN) for n in SCENARIOS])
-def test_cli_turn_never_persists_or_replays_a_secret(cli_world: World, scenario: str) -> None:
- check(cli_world, scenario)
[email protected]("scenario, sink", cells(KNOWN, platform=False))
+def test_cli_turn_never_persists_or_replays_a_secret(cli_world: World, scenario: str, sink: str) -> None:
+ check(cli_world, scenario, sink)
diff --git a/tests/e2e/core/security/test_secret_redaction_gateway.py b/tests/e2e/core/security/test_secret_redaction_gateway.py
index 11a615fda4a..279e8232b4a 100644
--- a/tests/e2e/core/security/test_secret_redaction_gateway.py
+++ b/tests/e2e/core/security/test_secret_redaction_gateway.py
@@ -13,18 +13,20 @@ import sys
import pytest
-from tests.e2e.core.security._helpers import known_param, write_home
+from tests.e2e.core.security._helpers import write_home
from tests.e2e.core.security._redact import (
- CONFIG, SCENARIOS, Ctx, Director, LoggingGateway, Secrets, World, assert_harness_sane, chat_for, check, collect,
- echo_preconditions, prompt_for, seed_workspace,
+ CONFIG, SCENARIOS, Ctx, Director, LoggingGateway, Secrets, World, assert_harness_sane, cells, chat_for, check,
+ collect, echo_preconditions, prompt_for, seed_workspace,
)
from tests.e2e.core.delivery._fake_platform import wait_until
from tests.fakes.fake_llm_provider import FakeLLMServer
pytestmark = pytest.mark.skipif(sys.platform == "win32", reason="POSIX shell commands and process groups")
+# Keyed by cell id ``<scenario>-<sink>``: only the platform wire of the streamed answer is the known gap;
+# the same answer reaching gateway.log, state.db, an export or the next request stays a plain red.
KNOWN: dict[str, str] = {
- "assistant_text": "#56039 streamed gateway replies reach the platform without secret redaction",
+ "assistant_text-platform": "#56039 streamed gateway replies reach the platform without secret redaction",
}
PLATFORM = "fk_tg"
@@ -66,6 +68,6 @@ def gw_world(tmp_path_factory) -> World:
return World(keys, sinks, echo_preconditions(ws, keys, gets, logs), {n: "(gateway)" for n in SCENARIOS})
[email protected]("scenario", [known_param(n, KNOWN) for n in SCENARIOS])
-def test_gateway_turn_never_persists_delivers_or_replays_a_secret(gw_world: World, scenario: str) -> None:
- check(gw_world, scenario)
[email protected]("scenario, sink", cells(KNOWN, platform=True))
+def test_gateway_turn_never_persists_delivers_or_replays_a_secret(gw_world: World, scenario: str, sink: str) -> None:
+ check(gw_world, scenario, sink)