import importlib.util from pathlib import Path SPEC = importlib.util.spec_from_file_location( "audit_core_e2_runner", Path("runners/audit_core_e2.py") ) runner = importlib.util.module_from_spec(SPEC) assert SPEC.loader is not None SPEC.loader.exec_module(runner) def test_equivalent_denial_includes_digest(): base = { "status": 404, "content_type": "application/json", "count": 1, "schema": ["$", "$.error:str"], "run_digest": "same", } assert runner.equivalent(base, dict(base)) changed = dict(base, run_digest="different") assert not runner.equivalent(base, changed) def test_event_is_synthetic_and_correlation_bound(): payload = runner.event("event-a", "tenant-a", "corr", "2026-08-21T23:00:00Z") assert payload["id"] == payload["data"]["fixture_id"] assert payload["tenant"] == "tenant-a" assert payload["correlation_id"] == "corr" assert payload["occurred_at"] == "2026-08-21T23:00:00Z" def test_p95_is_conservative_for_small_runs(): assert runner._p95([10, 20, 30]) == 30 def test_post_headers_bind_idempotency_key_to_event_id(): headers = runner.request_headers( "secret-not-rendered", "eng-1", "corr-1", {"id": "event-1"} ) assert headers["Idempotency-Key"] == "event-1" assert headers["User-Agent"] == "whitehat-security/eng-1" def test_get_headers_have_no_idempotency_key(): headers = runner.request_headers("secret", "eng-1", "corr-1", None) assert "Idempotency-Key" not in headers