def test_e2e_invalid_language_falls_back_without_error(client, seeded_news):
    response = client.get("/api/news/latest?language=xx")
    assert response.status_code == 200
    payload = response.json()
    assert payload["language"] == "en"


def test_e2e_invalid_permalink_query_does_not_break_home(client):
    response = client.get("/?article=not-a-number")
    assert response.status_code == 200
    html = response.text
    assert 'x-data="newsFeed()"' in html


def test_e2e_empty_feed_shape_is_stable(client):
    response = client.get("/api/news?limit=10&language=en")
    assert response.status_code == 200
    payload = response.json()
    assert "items" in payload
    assert "has_more" in payload
