"""IT-INST-001 — install mode allows /health + install API, blocks business API."""

from __future__ import annotations

from unittest.mock import patch

import pytest
from httpx import ASGITransport, AsyncClient

pytestmark = [pytest.mark.integration, pytest.mark.slow]


@pytest.mark.asyncio
async def test_install_mode_health_ok_servers_blocked(monkeypatch):
    monkeypatch.setattr("server.main.is_install_mode", lambda: True)
    monkeypatch.setattr("server.api.auth_jwt._is_install_mode", lambda: True)

    from server.main import app

    transport = ASGITransport(app=app)
    async with AsyncClient(transport=transport, base_url="http://test") as client:
        health = await client.get("/health")
        assert health.status_code == 200

        servers = await client.get("/api/servers/")
        assert servers.status_code == 503
        assert "安装" in servers.json()["detail"]

        with patch("server.api.install._is_locked", return_value=False), patch(
            "server.api.install._has_env",
            return_value=False,
        ):
            status = await client.get("/api/install/status")
        assert status.status_code == 200
        body = status.json()
        assert body["configured"] is False
        assert body["locked"] is False
