import datetime as dt

from fxhnt.adapters.persistence.cockpit_models import StrategyAllocationRow
from fxhnt.adapters.persistence.forward_nav import ForwardNavRepo


def _row(sid, dollars, at):
    return StrategyAllocationRow(strategy_id=sid, target_weight=0.5, target_dollars=dollars,
                                 policy_version=1, policy_hash="h", as_of="2026-07-09", computed_at=at)


def test_replace_allocations_wholesale_replaces(tmp_path):
    repo = ForwardNavRepo(f"sqlite:///{tmp_path}/a.db")
    repo.migrate()
    at = dt.datetime(2026, 7, 9, 23, 30)
    repo.replace_allocations([_row("multistrat", 6000.0, at), _row("bybit_4edge", 4000.0, at)], at)
    assert repo.current_allocation() == {"multistrat": 6000.0, "bybit_4edge": 4000.0}
    repo.replace_allocations([_row("multistrat", 5000.0, at)], at)          # bybit_4edge drops out
    assert repo.current_allocation() == {"multistrat": 5000.0}              # wholesale-replaced, no stale row
