""" Tests for run-payload logging. Covers sanitize_payload() in session_logger.py — the guard that lets the full run payload go into the Supabase session_logs meta column on every run without ever leaking secrets (trusted-auth keys, API keys, passwords). """ import json from session_logger import sanitize_payload def test_secret_keys_are_redacted(): payload = { 'thoughtspot_trusted_auth_key': 'super-secret-value-123', 'openai_api_key': 'sk-abc', 'password': 'hunter2', 'some_token': 'tok_xyz', 'thoughtspot_url': 'https://demo.thoughtspot.cloud', 'company': 'Acme', } out = sanitize_payload(payload) dumped = json.dumps(out) assert 'super-secret-value-123' not in dumped assert 'sk-abc' not in dumped assert 'hunter2' not in dumped assert 'tok_xyz' not in dumped # Non-secret values pass through untouched assert out['thoughtspot_url'] == 'https://demo.thoughtspot.cloud' assert out['company'] == 'Acme' # Redacted values carry a length marker, not the secret assert out['thoughtspot_trusted_auth_key'].startswith('