AUDIT-WP-0004 T01, T02, T07. T01 - ingestion wrote to SQLite directly and never called the AuditBackend contract, so a 202 meant a row existed rather than that a backend with a declared retention policy had accepted the event. Adds IdempotentAuditBackend to the contract: duplicate detection lives inside the backend so custody and idempotency state share a transaction and cannot diverge. SQLiteAuditBackend implements it with WAL, synchronous=FULL and a busy timeout. Ingestion now refuses any backend declaring durable=False, so the development file backend cannot silently become the production sink. The atomicity claim was tested rather than asserted, and the first attempt failed: with a single shared connection, 16 racing submissions of one event told two callers they were first. Storage was correct but the response was not. Fixed with per-thread connections and BEGIN IMMEDIATE around the insert/read pair, and locked in by a test. T02 - storage errors previously escaped the handler with start_response never called, and the auth check sat outside the try block so a non-ASCII Authorization header crashed the request. Adds a catch-all, maps conflict to 409, backend unavailability to 503 and unexpected faults to 500, and documents the full response contract with the retry semantics each status implies, since senders key their behaviour off it. T07 - ingestion tests 2 -> 23, suite 15 -> 36. accepted_at is now UTC rather than local time, and naive timestamps are rejected instead of silently assumed. Remaining in WP-0004: T03 tenant/source binding, T04 redaction policy, T05 operator read surface, T06 production serving layer. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
34 lines
797 B
Python
34 lines
797 B
Python
"""Audit Core public interface.
|
|
|
|
Contract reference: ``docs/audit-backend-contract.md``.
|
|
"""
|
|
|
|
from audit_core.interface import (
|
|
AcceptResult,
|
|
AuditBackend,
|
|
AuditEvent,
|
|
BackendUnavailableError,
|
|
EventConflictError,
|
|
EventValidationError,
|
|
IdempotentAuditBackend,
|
|
RetentionPolicy,
|
|
SCHEMA_VERSION_V1ALPHA1,
|
|
validate_event,
|
|
)
|
|
from audit_core.mock_file_backend import MockFileAuditBackend
|
|
from audit_core.sqlite_backend import SQLiteAuditBackend
|
|
|
|
__all__ = [
|
|
"AcceptResult",
|
|
"AuditBackend",
|
|
"AuditEvent",
|
|
"BackendUnavailableError",
|
|
"EventConflictError",
|
|
"EventValidationError",
|
|
"IdempotentAuditBackend",
|
|
"MockFileAuditBackend",
|
|
"RetentionPolicy",
|
|
"SCHEMA_VERSION_V1ALPHA1",
|
|
"SQLiteAuditBackend",
|
|
"validate_event",
|
|
]
|