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
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import datetime
|
|
import importlib.util
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
pytest.importorskip("openai")
|
|
_module_path = (
|
|
Path(__file__).resolve().parent.parent / "chapter6" / "phone-agent" / "agent.py"
|
|
)
|
|
_spec = importlib.util.spec_from_file_location("phone_agent", _module_path)
|
|
_module = importlib.util.module_from_spec(_spec)
|
|
sys.modules["phone_agent"] = _module
|
|
_spec.loader.exec_module(_module)
|
|
_redact_secrets = _module._redact_secrets
|
|
|
|
|
|
class CustomObject:
|
|
def __str__(self):
|
|
return "CustomObjectRepresentation"
|
|
|
|
|
|
def test_redact_secrets_non_serializable(monkeypatch):
|
|
monkeypatch.setenv("MY_API_KEY", "secret_key_12345678")
|
|
|
|
now = datetime.datetime(2026, 1, 1, 12, 0, 0)
|
|
data = {
|
|
"timestamp": now,
|
|
"tags": {"tag1", "tag2"},
|
|
"custom": CustomObject(),
|
|
"api_key": "secret_key_12345678",
|
|
"openai_key": "sk-12345678901234567890",
|
|
}
|
|
|
|
sanitized = _redact_secrets(data)
|
|
|
|
assert sanitized["api_key"] == "[REDACTED]"
|
|
assert sanitized["openai_key"] == "[REDACTED]"
|
|
assert sanitized["timestamp"] == str(now)
|
|
assert sanitized["custom"] == "CustomObjectRepresentation"
|
|
assert isinstance(sanitized["tags"], str) or isinstance(sanitized["tags"], list)
|