test(v2): prove runtime dispatch and persistence invariants

This commit is contained in:
2026-07-27 19:34:14 +02:00
parent 8d1de81f2b
commit 45a526a1e9
2 changed files with 144 additions and 2 deletions
+30 -1
View File
@@ -94,6 +94,35 @@ def test_system_clock_returns_aware_utc() -> None:
def test_cli_declares_isolated_runtime_roles() -> None:
parser = build_parser()
for role in ("web", "scheduler", "worker", "migrate", "admin"):
for role in ("web", "scheduler", "worker", "admin"):
args = parser.parse_args([role])
assert args.role == role
def test_cli_dispatches_selected_role(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
settings = valid_settings(tmp_path)
observed: list[Any] = []
def handler(received: Any) -> int:
observed.append(received)
return 23
monkeypatch.setattr(cli, "require_current_schema", lambda _settings: None)
monkeypatch.setitem(cli.ROLE_HANDLERS, "web", handler)
assert cli.main(["web"], settings=settings) == 23
assert observed == [settings]
def test_migrate_upgrade_dispatches_to_alembic(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
settings = valid_settings(tmp_path)
calls: list[tuple[str, str]] = []
def upgrade(_config: Any, revision: str) -> None:
calls.append(("upgrade", revision))
monkeypatch.setattr(cli.command, "upgrade", upgrade)
assert cli.main(["migrate", "upgrade"], settings=settings) == 0
expected_calls = [("upgrade", "head")]
assert calls == expected_calls