from fastapi.testclient import TestClient

from zbt.core.config import Settings
from zbt.domains.agent.repository import InMemoryAgentRepository
from zbt.domains.catalog.repository import InMemoryCatalogRepository
from zbt.domains.enrollment.repository import InMemoryEnrollmentRepository
from zbt.domains.identity.repository import InMemoryIdentityRepository
from zbt.domains.knowledge.index import InMemoryKnowledgeIndex
from zbt.domains.knowledge.repository import InMemoryKnowledgeRepository
from zbt.domains.service_request.repository import InMemoryServiceRequestRepository
from zbt.main import create_app


def test_live_health_reports_project_identity() -> None:
    app = create_app(
        settings=Settings(
            app_env="test",
            jwt_access_secret="a" * 32,
            jwt_refresh_secret="b" * 32,
            field_encryption_key="c" * 32,
        ),
        identity_repository=InMemoryIdentityRepository(),
        catalog_repository=InMemoryCatalogRepository(),
        agent_repository=InMemoryAgentRepository(),
        enrollment_repository=InMemoryEnrollmentRepository(),
        knowledge_repository=InMemoryKnowledgeRepository(),
        knowledge_index=InMemoryKnowledgeIndex(),
        service_request_repository=InMemoryServiceRequestRepository(),
    )
    response = TestClient(app).get("/api/v1/system/health/live")

    assert response.status_code == 200
    assert response.json()["data"] == {
        "status": "alive",
        "project": "智保通",
        "stage": "s2",
    }
    assert response.json()["meta"]["request_id"]
