Skip to content

Commit ec82ad3

Browse files
fix(server): update migration dispatch test config
1 parent da5a132 commit ec82ad3

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

server/unit_tests/test_migrate.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,33 @@
99
from __future__ import annotations
1010

1111
import tomllib
12+
from collections.abc import Iterator
13+
from contextlib import contextmanager
1214
from pathlib import Path, PurePosixPath
1315
from unittest.mock import MagicMock
1416

1517
import pytest
18+
from alembic.config import Config
1619
from alembic.script import ScriptDirectory
1720

1821
from agent_control_server import migrate
1922

2023

2124
@pytest.fixture
22-
def stub_config(monkeypatch: pytest.MonkeyPatch) -> object:
23-
"""Replace bundled-config building with a sentinel object.
25+
def stub_config(monkeypatch: pytest.MonkeyPatch) -> Config:
26+
"""Replace runtime config building with a lightweight Alembic config.
2427
2528
Lets dispatch tests verify which Alembic command was called and
26-
what config was passed without needing real migration assets.
29+
what config was passed without touching real migration assets or DB locks.
2730
"""
28-
sentinel = object()
29-
monkeypatch.setattr(migrate, "_bundled_config", lambda: sentinel)
31+
sentinel = Config()
32+
sentinel.set_main_option("sqlalchemy.url", "sqlite:///agent-control-test.db")
33+
34+
@contextmanager
35+
def fake_runtime_bundled_config() -> Iterator[Config]:
36+
yield sentinel
37+
38+
monkeypatch.setattr(migrate, "_runtime_bundled_config", fake_runtime_bundled_config)
3039
return sentinel
3140

3241

@@ -37,7 +46,7 @@ def _patch_command(monkeypatch: pytest.MonkeyPatch, name: str) -> MagicMock:
3746

3847

3948
def test_main_default_runs_upgrade_head(
40-
stub_config: object, monkeypatch: pytest.MonkeyPatch
49+
stub_config: Config, monkeypatch: pytest.MonkeyPatch
4150
) -> None:
4251
upgrade = _patch_command(monkeypatch, "upgrade")
4352
rc = migrate.main([])
@@ -46,7 +55,7 @@ def test_main_default_runs_upgrade_head(
4655

4756

4857
def test_main_bare_upgrade_runs_upgrade_head(
49-
stub_config: object, monkeypatch: pytest.MonkeyPatch
58+
stub_config: Config, monkeypatch: pytest.MonkeyPatch
5059
) -> None:
5160
upgrade = _patch_command(monkeypatch, "upgrade")
5261
rc = migrate.main(["upgrade"])
@@ -55,7 +64,7 @@ def test_main_bare_upgrade_runs_upgrade_head(
5564

5665

5766
def test_main_explicit_upgrade_revision(
58-
stub_config: object, monkeypatch: pytest.MonkeyPatch
67+
stub_config: Config, monkeypatch: pytest.MonkeyPatch
5968
) -> None:
6069
upgrade = _patch_command(monkeypatch, "upgrade")
6170
rc = migrate.main(["upgrade", "abc123"])
@@ -64,7 +73,7 @@ def test_main_explicit_upgrade_revision(
6473

6574

6675
def test_main_upgrade_supports_sql(
67-
stub_config: object, monkeypatch: pytest.MonkeyPatch
76+
stub_config: Config, monkeypatch: pytest.MonkeyPatch
6877
) -> None:
6978
upgrade = _patch_command(monkeypatch, "upgrade")
7079
rc = migrate.main(["upgrade", "head", "--sql"])
@@ -82,7 +91,7 @@ def test_main_bare_downgrade_requires_explicit_revision(
8291

8392

8493
def test_main_explicit_downgrade_revision(
85-
stub_config: object, monkeypatch: pytest.MonkeyPatch
94+
stub_config: Config, monkeypatch: pytest.MonkeyPatch
8695
) -> None:
8796
downgrade = _patch_command(monkeypatch, "downgrade")
8897
rc = migrate.main(["downgrade", "abc123"])
@@ -91,7 +100,7 @@ def test_main_explicit_downgrade_revision(
91100

92101

93102
def test_main_downgrade_supports_sql(
94-
stub_config: object, monkeypatch: pytest.MonkeyPatch
103+
stub_config: Config, monkeypatch: pytest.MonkeyPatch
95104
) -> None:
96105
downgrade = _patch_command(monkeypatch, "downgrade")
97106
rc = migrate.main(["downgrade", "-1", "--sql"])
@@ -101,7 +110,7 @@ def test_main_downgrade_supports_sql(
101110

102111
@pytest.mark.parametrize("op", ["current", "history", "heads"])
103112
def test_main_query_commands(
104-
stub_config: object, monkeypatch: pytest.MonkeyPatch, op: str
113+
stub_config: Config, monkeypatch: pytest.MonkeyPatch, op: str
105114
) -> None:
106115
cmd = _patch_command(monkeypatch, op)
107116
rc = migrate.main([op])
@@ -147,7 +156,7 @@ def test_main_rejects_extra_positional_args(monkeypatch: pytest.MonkeyPatch) ->
147156

148157

149158
def test_main_returns_nonzero_for_command_errors(
150-
stub_config: object, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
159+
stub_config: Config, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
151160
) -> None:
152161
upgrade = _patch_command(monkeypatch, "upgrade")
153162
upgrade.side_effect = RuntimeError("database unavailable")

0 commit comments

Comments
 (0)