Skip to content

Commit fcb2c04

Browse files
committed
fix file handle leak in append_audit_event, assert no audit event on error path
1 parent da8831e commit fcb2c04

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/ghdcbot/adapters/storage/sqlite.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ def append_audit_event(self, event: dict) -> None:
663663
if "timestamp" not in payload:
664664
payload["timestamp"] = datetime.now(timezone.utc).isoformat()
665665
line = json.dumps(payload, separators=(",", ":")) + "\n"
666-
path.open("a", encoding="utf-8").write(line)
666+
with path.open("a", encoding="utf-8") as f:
667+
f.write(line)
667668

668669
def list_audit_events(self) -> list[dict]:
669670
"""Read-only: return all audit events from audit_events.jsonl.

tests/test_snapshots.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,6 @@ def test_write_snapshots_handles_errors() -> None:
342342

343343
# Should not have written files due to error
344344
assert len(github_writer.files_written) == 0
345+
346+
# Should not have recorded an audit event on error path
347+
assert len(storage.audit_events) == 0

0 commit comments

Comments
 (0)