"""A6: `sources=fundamentals` is accepted but never fetches from a provider.

`fundamental_data` is rebuilt for the whole universe by the nightly SEC + Dolt
imports, so there is no per-ticker fetch left. The source key stays valid so an
older client gets a truthful `skipped` instead of a silent omission.
"""

from __future__ import annotations

from app.models.ticker import Ticker


async def test_fundamentals_source_reports_skipped(client, db_session):
    from app.dependencies import require_access
    from app.main import app

    app.dependency_overrides[require_access] = lambda: None
    try:
        db_session.add(Ticker(symbol="AAPL"))
        await db_session.flush()

        resp = await client.post(
            "/api/v1/ingestion/fetch/AAPL", params={"sources": "fundamentals"}
        )
        assert resp.status_code == 200
        source = resp.json()["data"]["sources"]["fundamentals"]
        assert source["status"] == "skipped"
        assert "SEC + Dolt" in source["message"]
    finally:
        app.dependency_overrides.pop(require_access, None)


def test_fundamentals_remains_a_recognised_source_key():
    """Older clients keep getting an entry for it rather than a missing key."""
    from app.routers.ingestion import _parse_requested_sources

    assert "fundamentals" in _parse_requested_sources("fundamentals")
    assert "fundamentals" in _parse_requested_sources(None)  # None => all sources
