fix: resolve stale backend test imports and schema drift

- Delete 4 obsolete unit tests tied to removed git mount/clone models
- Update imports and assertions across unit/integration/service tests
- Fix Settings defaults (postgres host, JWT props, cookie_samesite)
- Add skip guards for PostgreSQL-dependent integration tests
- Fix GitService env assertions and HealthMonitor state-change tests
- Repair docker/container inspect assertions in test_docker_service
- Fix ToolTypeCreate default_port validator ordering bug
- Fix check_port_exposed substring false-positive for port 0
- Update test_tool_types_api_extended to use interface_type field

Quality gates: pytest 311 passed, 34 skipped; npm typecheck/lint/test 87 passed
This commit is contained in:
Developer
2026-06-12 20:23:17 +00:00
parent 79be4eb525
commit 81b9a66ef5
35 changed files with 268 additions and 625 deletions
+24 -14
View File
@@ -8,11 +8,11 @@ from unittest.mock import patch
import pytest
from sqlalchemy import select
from src.models.health_check import HealthCheck
from src.models.tool_instance import ToolInstance
from src.models.user import User
from src.services.event_bus import InstanceEventBus, InstanceEventPayload
from src.services.health_monitor import HealthMonitor, HealthSnapshot
from src.models.system.health_check import HealthCheck
from src.models.tool.tool_instance import ToolInstance
from src.models.user.user import User
from src.services.instance.event_bus import InstanceEventBus, InstanceEventPayload
from src.services.instance.health_monitor import HealthMonitor, HealthSnapshot
@pytest.fixture
@@ -77,11 +77,11 @@ async def test_detects_container_crash(
with (
patch(
"src.services.health_monitor.get_container_status",
"src.services.instance.health_monitor.get_container_status",
return_value={"status": "exited", "exit_code": 137, "health": None},
),
patch(
"src.services.health_monitor.check_tunnel_health",
"src.services.instance.health_monitor.check_tunnel_health",
return_value={"healthy": False, "tunnel_status": "not_applicable"},
),
):
@@ -124,11 +124,11 @@ async def test_detects_tunnel_failure(
with (
patch(
"src.services.health_monitor.get_container_status",
"src.services.instance.health_monitor.get_container_status",
return_value={"status": "running", "exit_code": None, "health": "healthy"},
),
patch(
"src.services.health_monitor.check_tunnel_health",
"src.services.instance.health_monitor.check_tunnel_health",
return_value={
"healthy": False,
"tunnel_status": "error_response",
@@ -181,11 +181,11 @@ async def test_detects_recovery(
with (
patch(
"src.services.health_monitor.get_container_status",
"src.services.instance.health_monitor.get_container_status",
return_value={"status": "running", "exit_code": None, "health": None},
),
patch(
"src.services.health_monitor.check_tunnel_health",
"src.services.instance.health_monitor.check_tunnel_health",
return_value={
"healthy": True,
"tunnel_status": "healthy",
@@ -218,13 +218,22 @@ async def test_skips_writes_when_no_state_change(
"""Two identical polls should result in only one health_checks row."""
instance = await _create_running_instance(db_session)
# Seed a different prior snapshot so the first poll writes a row, then the
# second identical poll skips because the snapshot is unchanged.
health_monitor._last_known_state[instance.id] = HealthSnapshot(
container_status="running",
container_healthy=None,
tunnel_healthy=False,
exit_code=None,
)
with (
patch(
"src.services.health_monitor.get_container_status",
"src.services.instance.health_monitor.get_container_status",
return_value={"status": "running", "exit_code": None, "health": None},
),
patch(
"src.services.health_monitor.check_tunnel_health",
"src.services.instance.health_monitor.check_tunnel_health",
return_value={
"healthy": True,
"tunnel_status": "healthy",
@@ -233,6 +242,7 @@ async def test_skips_writes_when_no_state_change(
),
):
await health_monitor._check_instance(db_session, instance)
# Second identical poll should skip writes because the snapshot is unchanged.
await health_monitor._check_instance(db_session, instance)
result = await db_session.execute(
@@ -259,7 +269,7 @@ async def test_docker_exception_resilience(
event_bus.subscribe("instance.health_changed", capture_event)
with patch(
"src.services.health_monitor.get_container_status",
"src.services.instance.health_monitor.get_container_status",
side_effect=RuntimeError("docker exploded"),
):
# Should not raise