Skip to content

Commit 17468e3

Browse files
committed
fix MockStorage missing append_audit_event, remove stale protocol docstrings
1 parent 352aab4 commit 17468e3

2 files changed

Lines changed: 14 additions & 10 deletions

File tree

src/ghdcbot/adapters/storage/sqlite.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def list_verified_identity_mappings(self) -> list[IdentityMapping]:
541541

542542
def get_identity_links_for_discord_user(self, discord_user_id: str) -> list[dict]:
543543
"""Return all identity link rows for a Discord user (verified and pending).
544-
Optional method; not part of the Storage protocol. Used for /verify and /status.
544+
Used for /verify and /status.
545545
"""
546546
with self._connect() as conn:
547547
rows = conn.execute(
@@ -657,9 +657,7 @@ def update_issue_request_status(self, request_id: str, status: str) -> None:
657657
conn.execute("UPDATE issue_requests SET status = ? WHERE request_id = ?", (status, request_id))
658658

659659
def append_audit_event(self, event: dict) -> None:
660-
"""Append a single audit event (append-only) to data_dir/audit_events.jsonl.
661-
Optional method; not part of the Storage protocol.
662-
"""
660+
"""Append a single audit event (append-only) to data_dir/audit_events.jsonl."""
663661
path = self._db_path.parent / "audit_events.jsonl"
664662
payload = dict(event)
665663
if "timestamp" not in payload:
@@ -670,7 +668,6 @@ def append_audit_event(self, event: dict) -> None:
670668
def list_audit_events(self) -> list[dict]:
671669
"""Read-only: return all audit events from audit_events.jsonl.
672670
Returns empty list if file doesn't exist. Does not modify data.
673-
Optional method; not part of the Storage protocol.
674671
"""
675672
path = self._db_path.parent / "audit_events.jsonl"
676673
events = []
@@ -729,7 +726,6 @@ def mark_notification_sent(
729726
def list_recent_notifications(self, limit: int = 1000) -> list[dict]:
730727
"""List recent notifications (for snapshot export).
731728
Returns list of notification dicts, ordered by sent_at DESC.
732-
Optional method; not part of the Storage protocol.
733729
"""
734730
with self._connect() as conn:
735731
rows = conn.execute(

tests/test_snapshots.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@
2929

3030
class MockStorage:
3131
"""Mock storage for testing."""
32-
32+
3333
def __init__(self) -> None:
34-
self.notifications = []
35-
34+
self.notifications: list[dict] = []
35+
self.audit_events: list[dict] = []
36+
3637
def list_recent_notifications(self, limit: int = 1000) -> list[dict]:
3738
return self.notifications[:limit]
38-
39+
3940
def list_pending_issue_requests(self) -> list[dict]:
4041
return []
4142

43+
def append_audit_event(self, event: dict) -> None:
44+
self.audit_events.append(event)
45+
4246

4347
class MockGitHubWriter:
4448
"""Mock GitHub writer for testing."""
@@ -298,6 +302,10 @@ def test_write_snapshots_enabled() -> None:
298302
assert "schema_version" in parsed
299303
assert parsed["org"] == "test-org"
300304

305+
# Audit event should be recorded after a successful snapshot write
306+
assert len(storage.audit_events) == 1
307+
assert storage.audit_events[0]["event_type"] == "snapshot_written"
308+
301309

302310
def test_write_snapshots_handles_errors() -> None:
303311
"""Test that snapshot writing errors don't propagate."""

0 commit comments

Comments
 (0)