def test_risk_delay_present(client):
    r = client.get("/api/risks?area=work").json()
    kinds = [x["kind"] for x in r]
    assert "지연 위험" in kinds
    delay = next(x for x in r if x["kind"] == "지연 위험")
    assert "마감인데" in delay["text"] and delay["icon"] == "clock"


def test_risk_dependency(client):
    r = client.get("/api/risks?area=work").json()
    dep = [x for x in r if x["kind"] == "의존성"]
    assert dep, "예산 섹션 작성→경영진 검토 요청 메일 의존성 1건"
    assert "함께 밀려요" in dep[0]["text"]


def test_risk_max_three(client):
    r = client.get("/api/risks?area=work").json()
    assert len(r) <= 3


def test_risk_overload_threshold(client):
    # 시드 기준 업무 쏠림이 topN>=avg*1.5 && topN>=4 를 만족하면 포함
    r = client.get("/api/risks?area=work").json()
    over = [x for x in r if x["kind"] == "업무 쏠림"]
    for o in over:
        assert o["icon"] == "scale" and o["tone"] == "amber"
