6da65b8d8f
Admin-configurable thresholds (min R:R, default 2.0; min confidence, default 70%) defining what counts as an actionable signal: - Admin Settings: new Activation Thresholds panel (GET/PUT /admin/settings/activation) - GET /trades/activation exposes values to all users with access - Signals/Setups: filters initialize from activation values - Track Record: "Qualified signals only" toggle (default on) via min_rr/min_confidence params on /trades/performance; the confidence breakdown always covers the full population so the thresholds can be validated against outcomes - Dashboard: "Qualified" metric and qualified-first Top Setups - Outcome evaluator unchanged: every setup is still evaluated Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
"""Unit tests for activation threshold configuration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.exceptions import ValidationError
|
|
from app.services.admin_service import (
|
|
get_activation_config,
|
|
update_activation_config,
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
async def session() -> AsyncSession:
|
|
"""DB session compatible with services that commit."""
|
|
from tests.conftest import _test_session_factory
|
|
|
|
async with _test_session_factory() as session:
|
|
yield session
|
|
|
|
|
|
class TestActivationConfig:
|
|
async def test_defaults_when_unset(self, session: AsyncSession):
|
|
config = await get_activation_config(session)
|
|
assert config == {"min_rr": 2.0, "min_confidence": 70.0}
|
|
|
|
async def test_update_and_read_back(self, session: AsyncSession):
|
|
updated = await update_activation_config(
|
|
session, {"min_rr": 1.5, "min_confidence": 60.0}
|
|
)
|
|
assert updated == {"min_rr": 1.5, "min_confidence": 60.0}
|
|
|
|
config = await get_activation_config(session)
|
|
assert config == {"min_rr": 1.5, "min_confidence": 60.0}
|
|
|
|
async def test_partial_update_keeps_other_value(self, session: AsyncSession):
|
|
await update_activation_config(session, {"min_confidence": 80.0})
|
|
config = await get_activation_config(session)
|
|
assert config["min_rr"] == 2.0 # default untouched
|
|
assert config["min_confidence"] == 80.0
|
|
|
|
async def test_rejects_negative_rr(self, session: AsyncSession):
|
|
with pytest.raises(ValidationError):
|
|
await update_activation_config(session, {"min_rr": -1.0})
|
|
|
|
async def test_rejects_out_of_range_confidence(self, session: AsyncSession):
|
|
with pytest.raises(ValidationError):
|
|
await update_activation_config(session, {"min_confidence": 120.0})
|