"""持仓锁定出场目标。"""

from __future__ import annotations

from app.strategy.exits import check_exits, resolve_exit_target


def test_locked_target_ignores_setting_drift() -> None:
    d = check_exits(
        net_pnl=20.0,
        exit_mode="fixed_usdt",
        net_profit_target=50.0,  # 设置已被改大
        premium_exit_multiple=1.0,
        initial_premium=10.0,
        locked_exit_target=15.0,  # 开仓锁定
    )
    assert d.should_close is True
    assert d.target == 15.0


def test_locked_target_not_yet() -> None:
    d = check_exits(
        net_pnl=10.0,
        exit_mode="fixed_usdt",
        net_profit_target=5.0,
        premium_exit_multiple=1.0,
        initial_premium=10.0,
        locked_exit_target=15.0,
    )
    assert d.should_close is False
    assert d.target == 15.0


def test_resolve_premium_still_works_without_lock() -> None:
    t, mode = resolve_exit_target(
        exit_mode="premium_multiple",
        net_profit_target=15.0,
        premium_exit_multiple=2.0,
        initial_premium=10.0,
    )
    assert t == 20.0
    assert mode == "premium_multiple"
