mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-09 12:40:59 +00:00
fix(mcp): ruff format remote-mode files; make migration head test revision-agnostic
CI follow-up to the local/remote MCP work: - Apply ruff format to provider/tools/loaders/mcp.py and the 0006 normalize-remote-mode migration (Lint job failed on formatting). - test_migrations.py hardcoded the head revision as 0005_*, which broke once 0006 landed. Resolve the actual head from the Alembic ScriptDirectory so future migrations don't require editing the test.
This commit is contained in:
@@ -31,9 +31,7 @@ def upgrade() -> None:
|
|||||||
inspector = sa.inspect(conn)
|
inspector = sa.inspect(conn)
|
||||||
if 'mcp_servers' not in inspector.get_table_names():
|
if 'mcp_servers' not in inspector.get_table_names():
|
||||||
return
|
return
|
||||||
conn.execute(
|
conn.execute(sa.text("UPDATE mcp_servers SET mode = 'remote' WHERE mode IN ('sse', 'http')"))
|
||||||
sa.text("UPDATE mcp_servers SET mode = 'remote' WHERE mode IN ('sse', 'http')")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
@@ -46,6 +44,4 @@ def downgrade() -> None:
|
|||||||
inspector = sa.inspect(conn)
|
inspector = sa.inspect(conn)
|
||||||
if 'mcp_servers' not in inspector.get_table_names():
|
if 'mcp_servers' not in inspector.get_table_names():
|
||||||
return
|
return
|
||||||
conn.execute(
|
conn.execute(sa.text("UPDATE mcp_servers SET mode = 'http' WHERE mode = 'remote'"))
|
||||||
sa.text("UPDATE mcp_servers SET mode = 'http' WHERE mode = 'remote'")
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -191,9 +191,7 @@ class RuntimeMCPSession:
|
|||||||
try:
|
try:
|
||||||
await self.exit_stack.aclose()
|
await self.exit_stack.aclose()
|
||||||
except Exception as cleanup_err:
|
except Exception as cleanup_err:
|
||||||
self.ap.logger.debug(
|
self.ap.logger.debug(f'MCP server {self.server_name}: error cleaning up before SSE fallback: {cleanup_err}')
|
||||||
f'MCP server {self.server_name}: error cleaning up before SSE fallback: {cleanup_err}'
|
|
||||||
)
|
|
||||||
self.exit_stack = AsyncExitStack()
|
self.exit_stack = AsyncExitStack()
|
||||||
self.session = None
|
self.session = None
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,21 @@ from langbot.pkg.persistence.alembic_runner import (
|
|||||||
run_alembic_upgrade,
|
run_alembic_upgrade,
|
||||||
run_alembic_stamp,
|
run_alembic_stamp,
|
||||||
get_alembic_current,
|
get_alembic_current,
|
||||||
|
_ALEMBIC_DIR,
|
||||||
)
|
)
|
||||||
|
from alembic.config import Config
|
||||||
|
from alembic.script import ScriptDirectory
|
||||||
|
|
||||||
|
|
||||||
|
def _get_script_head() -> str:
|
||||||
|
"""Resolve the current Alembic head revision from the script directory.
|
||||||
|
|
||||||
|
Avoids hardcoding a revision number in assertions so adding a new
|
||||||
|
migration doesn't require editing the migration tests.
|
||||||
|
"""
|
||||||
|
cfg = Config()
|
||||||
|
cfg.set_main_option('script_location', _ALEMBIC_DIR)
|
||||||
|
return ScriptDirectory.from_config(cfg).get_current_head()
|
||||||
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.integration
|
pytestmark = pytest.mark.integration
|
||||||
@@ -103,8 +117,10 @@ class TestSQLiteMigrationUpgrade:
|
|||||||
# Verify revision
|
# Verify revision
|
||||||
rev = await get_alembic_current(sqlite_engine)
|
rev = await get_alembic_current(sqlite_engine)
|
||||||
assert rev is not None, 'Expected a revision after upgrade'
|
assert rev is not None, 'Expected a revision after upgrade'
|
||||||
# Head should be the latest migration
|
# Head should be the latest migration. Resolve the actual head from the
|
||||||
assert rev.startswith('0005'), f'Expected head to be 0005_*, got {rev}'
|
# Alembic script directory instead of hardcoding a revision number, so
|
||||||
|
# adding a new migration doesn't require editing this assertion.
|
||||||
|
assert rev == _get_script_head(), f'Expected head {_get_script_head()}, got {rev}'
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_upgrade_idempotent(self, sqlite_engine):
|
async def test_upgrade_idempotent(self, sqlite_engine):
|
||||||
|
|||||||
Reference in New Issue
Block a user