3e2cbcab88
tracker-policy-pr / check-pr (pull_request) Successful in 8s
test / integration-docker (pull_request) Successful in 12s
test / unit (pull_request) Successful in 43s
lint / lint (push) Failing after 59s
test / integration-firecracker (pull_request) Successful in 3m16s
test / coverage (pull_request) Successful in 16s
test / publish-infra (pull_request) Has been skipped
Move the `Supervise` lifecycle out of its own `orchestrator/supervisor/ supervise.py` and into the package `__init__`, renaming the class to `Supervisor`. Callers now import it from `bot_bottle.orchestrator.supervisor` alongside the queue surface it belongs with. Remove the dead `try/except ImportError` flat-import fallbacks from the package-only store modules (db_store, audit_store, config_store, queue_store) and image_cache. Those fallbacks existed for when the store files were flat-copied into the gateway; post-PRD-0070 the data plane never opens the DB, so these modules are only ever imported as part of the package. The two gateway data-plane files that may still be loaded flat (egress_addon_core, git_gate_render) keep their fallbacks. Full unit suite green (2251). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
88 lines
2.9 KiB
Python
88 lines
2.9 KiB
Python
"""SQLite-backed audit store for supervise (PRD 0013)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
from ..supervisor.types import AuditEntry
|
|
from ..paths import host_db_path
|
|
from .db_store import DbStore
|
|
from .migrations import TableMigrations
|
|
|
|
|
|
class AuditStore(DbStore):
|
|
"""SQLite-backed persistent store for supervise audit entries."""
|
|
|
|
def __init__(self, db_path: Path | None = None) -> None:
|
|
# One entry per schema version: migrations[0] brings a fresh DB to
|
|
# version 1, [1] to version 2, etc. Add new entries at the end; never
|
|
# edit existing ones.
|
|
migrations = TableMigrations("audit_store", [
|
|
# v1 — initial schema
|
|
"""
|
|
CREATE TABLE IF NOT EXISTS supervise_audit_entries (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
timestamp TEXT NOT NULL,
|
|
bottle_slug TEXT NOT NULL,
|
|
component TEXT NOT NULL,
|
|
operator_action TEXT NOT NULL,
|
|
operator_notes TEXT NOT NULL,
|
|
justification TEXT NOT NULL,
|
|
diff TEXT NOT NULL
|
|
)
|
|
""",
|
|
])
|
|
super().__init__(db_path or host_db_path(), migrations)
|
|
|
|
def write_audit_entry(self, entry: AuditEntry) -> Path:
|
|
with self._connection() as conn:
|
|
conn.execute(
|
|
"""
|
|
INSERT INTO supervise_audit_entries (
|
|
timestamp, bottle_slug, component, operator_action,
|
|
operator_notes, justification, diff
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
""",
|
|
(
|
|
entry.timestamp,
|
|
entry.bottle_slug,
|
|
entry.component,
|
|
entry.operator_action,
|
|
entry.operator_notes,
|
|
entry.justification,
|
|
entry.diff,
|
|
),
|
|
)
|
|
self._chmod()
|
|
return self.db_path
|
|
|
|
def read_audit_entries(self, component: str, slug: str) -> list[AuditEntry]:
|
|
if not self.db_path.is_file():
|
|
return []
|
|
with self._connection() as conn:
|
|
rows = conn.execute(
|
|
"""
|
|
SELECT * FROM supervise_audit_entries
|
|
WHERE component = ? AND bottle_slug = ?
|
|
ORDER BY id
|
|
""",
|
|
(component, slug),
|
|
).fetchall()
|
|
return [self._row_to_entry(row) for row in rows]
|
|
|
|
@staticmethod
|
|
def _row_to_entry(row: sqlite3.Row) -> AuditEntry:
|
|
return AuditEntry(
|
|
timestamp=row["timestamp"],
|
|
bottle_slug=row["bottle_slug"],
|
|
component=row["component"],
|
|
operator_action=row["operator_action"],
|
|
operator_notes=row["operator_notes"],
|
|
justification=row["justification"],
|
|
diff=row["diff"],
|
|
)
|
|
|
|
|
|
__all__ = ["AuditStore"]
|