"""Guard (Phase 0b Task 7d): the dead Binance-era combined-crypto `/paper` book is retired in full.

`paper_sleeves.py` (TRACKED_SLEEVES/BOOK_CONFIGS/TRUSTED_BOOK/REPLAYABLE_SLEEVES — the crypto-combined-book
vocabulary), `paper_backfill.py` (`backfill_paper_book`, the combined-book replay loop) and `paper_snapshot.py`
(`PaperSnapshotService`, the combined-book nightly snapshot service) are unimportable; the `paper_book_snapshot`
Dagster asset and the `paper-backfill` CLI are gone. This book was a dead Binance-era artifact — it read the
`features` table Task 7b stopped ingesting, the cockpit stopped displaying it (Bybit-only) since Task 7a, and
it was redundant with the `bybit_4edge` deploy book (the real crypto fund, on `bybit_features`).

Scope = CODE, not comments: checks MODULES/ASSETS/CLIs are gone. The `bybit_4edge` deploy book (on
`bybit_features`), the `bybit-paper-backfill` CLI, the Bybit paper-book asset, and the Bybit sim are a
SEPARATE, live, untouched path — this file also asserts they still survive (a guard against over-deletion).
`paper_book.py` / `paper_sim.py` (shared low-level primitives — `persist_paper_book`, `IncrementalRiskOverlay`,
`paper_risk_overlay`, `simulate_book`, ...) are heavily reused by the Bybit path and web app, so they are NOT
retired — only the crypto-combined-book-specific orchestration wrappers around them are gone."""
from __future__ import annotations

import importlib

import pytest

_DELETED_MODULES = [
    "fxhnt.application.paper_sleeves",
    "fxhnt.application.paper_backfill",
    "fxhnt.application.paper_snapshot",
]

_DELETED_CLIS = {"paper-backfill"}

# CLIs/assets that MUST survive (the live Bybit deploy book) — a guard against over-deletion.
_KEPT_CLIS = {"bybit-paper-backfill"}
_KEPT_ASSETS = ("bybit_paper_book", "bybit_warehouse_refresh", "bybit_4edge_nav", "bybit_4edge_levered_nav")


@pytest.mark.parametrize("mod", _DELETED_MODULES)
def test_combined_crypto_book_module_gone(mod: str) -> None:
    with pytest.raises(ModuleNotFoundError):
        importlib.import_module(mod)


def test_paper_book_snapshot_asset_gone() -> None:
    from fxhnt.adapters.orchestration import assets
    for name in ("paper_book_snapshot", "build_paper_book_snapshot", "_live_sleeves",
                 "_sleeve_return_series", "_assemble_paper_snapshot_inputs"):
        assert not hasattr(assets, name), f"{name} (combined-crypto-book code) still present"


def test_paper_book_snapshot_not_in_definitions() -> None:
    from fxhnt.adapters.orchestration.definitions import defs
    asset_keys = {k.to_user_string() for k in defs.get_repository_def().assets_defs_by_key}
    assert "paper_book_snapshot" not in asset_keys, "paper_book_snapshot must be retired from the asset graph"
    for kept in _KEPT_ASSETS:
        assert kept in asset_keys, f"{kept} (live Bybit path) must survive Task 7d"


def test_paper_backfill_cli_gone() -> None:
    from fxhnt.cli import app
    names = {c.name for c in app.registered_commands}
    assert not (_DELETED_CLIS & names), f"combined-crypto-book CLIs still registered: {_DELETED_CLIS & names}"


def test_bybit_deploy_book_survives() -> None:
    """No over-deletion: the live Bybit deploy book's backfill CLI is untouched."""
    from fxhnt.cli import app
    names = {c.name for c in app.registered_commands}
    missing = _KEPT_CLIS - names
    assert not missing, f"a KEPT Bybit CLI was wrongly removed: {missing}"
