Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
34 lines
1019 B
Python
34 lines
1019 B
Python
"""detect_pii must treat JSON null pii_values like an empty list."""
|
|
import json
|
|
from unittest.mock import patch
|
|
|
|
from agent import LogSanitizationAgent
|
|
|
|
|
|
def test_null_pii_values_returns_empty_list():
|
|
agent = object.__new__(LogSanitizationAgent)
|
|
agent.count_tokens = lambda text: len(text) // 4
|
|
agent._chat_stream = lambda messages: iter(
|
|
[json.dumps({"pii_values": None})]
|
|
)
|
|
|
|
with patch("builtins.print"):
|
|
pii_values, metrics = agent.detect_pii("Alice phone 555-0100")
|
|
|
|
assert pii_values == []
|
|
assert metrics["pii_items_found"] == 0
|
|
|
|
|
|
def test_list_pii_values_still_cleaned():
|
|
agent = object.__new__(LogSanitizationAgent)
|
|
agent.count_tokens = lambda text: len(text) // 4
|
|
agent._chat_stream = lambda messages: iter(
|
|
[json.dumps({"pii_values": [" Alice ", "-", "Bob"]})]
|
|
)
|
|
|
|
with patch("builtins.print"):
|
|
pii_values, metrics = agent.detect_pii("text")
|
|
|
|
assert pii_values == ["Alice", "Bob"]
|
|
assert metrics["pii_items_found"] == 2
|