d7a58e52fd
lint / lint (push) Successful in 54s
test / integration-docker (pull_request) Successful in 38s
test / unit (pull_request) Successful in 45s
test / integration-firecracker (pull_request) Successful in 3m31s
test / coverage (pull_request) Successful in 18s
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Failing after 6s
Move the DbStore base (db_store), the shared schema-migration base (migrations / TableMigrations), the concrete stores (audit_store, config_store, queue_store), and StoreManager out of the package root into a bot_bottle/store/ package, so persistence lives in one place rather than scattered across the root. Callers use direct submodule imports (from bot_bottle.store.store_manager import StoreManager). Inside the moved modules the relative imports point back up to their non-store siblings (..paths, ..supervise_types) while co-moved siblings stay package-local; the flat-import fallbacks are untouched. The orchestrator's own stores (config_store, secret_store, registry) stay in orchestrator/ and repoint to the moved DbStore / TableMigrations. No behavior change; full unit suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
3.4 KiB
Python
87 lines
3.4 KiB
Python
"""Unit tests for the host-side configuration store."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sqlite3
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
from bot_bottle.store.config_store import (
|
|
DEFAULT_CACHED_IMAGE_STALE_WARNING_DAYS,
|
|
ConfigStore,
|
|
)
|
|
from bot_bottle.store.store_manager import StoreManager
|
|
|
|
|
|
class TestConfigStore(unittest.TestCase):
|
|
def test_cached_image_warning_days_defaults_to_one(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
|
store = ConfigStore(Path(tmp) / "bot-bottle.db")
|
|
store.migrate()
|
|
self.assertEqual(
|
|
DEFAULT_CACHED_IMAGE_STALE_WARNING_DAYS,
|
|
store.cached_image_stale_warning_days(),
|
|
)
|
|
|
|
def test_cached_image_warning_days_reads_value(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
|
store = ConfigStore(Path(tmp) / "bot-bottle.db")
|
|
store.migrate()
|
|
store.set_cached_image_stale_warning_days(7)
|
|
self.assertEqual(7, store.cached_image_stale_warning_days())
|
|
|
|
def test_config_schema_uses_explicit_settings_columns(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
|
store = ConfigStore(Path(tmp) / "bot-bottle.db")
|
|
store.migrate()
|
|
with sqlite3.connect(store.db_path) as conn:
|
|
conn.row_factory = sqlite3.Row
|
|
columns = [
|
|
row["name"]
|
|
for row in conn.execute("PRAGMA table_info(bot_bottle_config)")
|
|
]
|
|
self.assertEqual([
|
|
"id",
|
|
"cached_image_stale_warning_days",
|
|
], columns)
|
|
|
|
def test_store_manager_includes_config_store(self) -> None:
|
|
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
|
db = Path(tmp) / "bot-bottle.db"
|
|
manager = StoreManager(db)
|
|
self.assertFalse(manager.is_migrated())
|
|
manager.migrate()
|
|
self.assertTrue(manager.is_migrated())
|
|
|
|
def test_cached_image_warning_days_returns_default_when_db_missing(self) -> None:
|
|
# When the db file doesn't exist yet (parent exists, file doesn't),
|
|
# the store returns the default without touching the file.
|
|
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
|
store = ConfigStore(Path(tmp) / "missing.db")
|
|
self.assertEqual(
|
|
DEFAULT_CACHED_IMAGE_STALE_WARNING_DAYS,
|
|
store.cached_image_stale_warning_days(),
|
|
)
|
|
|
|
def test_cached_image_warning_days_returns_default_on_null_value(self) -> None:
|
|
# If the row exists but the value is NULL (or not castable to int),
|
|
# the store falls back to the default.
|
|
with tempfile.TemporaryDirectory(prefix="config-store.") as tmp:
|
|
db_path = Path(tmp) / "bot-bottle.db"
|
|
store = ConfigStore(db_path)
|
|
store.migrate()
|
|
# Write a NULL value directly.
|
|
with sqlite3.connect(db_path) as conn:
|
|
conn.execute(
|
|
"UPDATE bot_bottle_config SET cached_image_stale_warning_days = NULL WHERE id = 1"
|
|
)
|
|
self.assertEqual(
|
|
DEFAULT_CACHED_IMAGE_STALE_WARNING_DAYS,
|
|
store.cached_image_stale_warning_days(),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|