Files
Shadowbroker/backend/tests/test_gt_backtest.py
T
Shadowbroker cfbeabda1e Feat/gt analytics openclaw (#392)
* feat(telegram): auto-translate OSINT channel posts to English

Cherry-picked from @Bobpick PR #391 (telegram-only slice): server-side translation during fetch, SHOW ORIGINAL toggle in TelegramOsintPopup, and on-demand /api/telegram-feed?lang=.

Co-authored-by: Robert Pickett <bobpickettsr@yahoo.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

* feat(gt): experimental Derived OSINT analytics with lean-node safeguards

Cherry-picked from @Bobpick PR #391 (GT + OpenClaw slice): Bayesian strategic-risk engine, map overlay, OpenClaw commands, and telegram_rhetoric watchdog. Off by default (GT_ANALYTICS_ENABLED=false, gt_risk layer false). 1 vCPU nodes get cgroup detection, UI warning on layer toggle, and lean profile that skips scheduled ingest/Louvain unless GT_ANALYTICS_ACK_LOW_CPU=true. Backtest HUD removed from dashboard (OpenClaw/API regression only).

Co-authored-by: Robert Pickett <bobpickettsr@yahoo.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Robert Pickett <bobpickettsr@yahoo.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 17:05:46 -06:00

52 lines
1.7 KiB
Python

"""Historical backtest validation for Strategic Risk Analytics."""
from __future__ import annotations
from analytics.backtest import (
DEFAULT_BACKTEST_ALERT_THRESHOLD,
MAX_BACKTEST_ALERT_THRESHOLD,
run_historical_backtest,
tune_alert_threshold,
wilson_interval,
)
from analytics.historical_events import default_historical_cases, expanded_historical_cases
def test_wilson_interval_perfect_run() -> None:
lower, upper = wilson_interval(18, 18)
assert lower >= 0.80
assert upper == 1.0
def test_base_suite_meets_eighty_percent_confidence() -> None:
report = run_historical_backtest(
default_historical_cases(),
use_expanded_suite=False,
target_confidence=0.80,
)
assert report.accuracy >= 0.95
assert report.confidence_rate >= 0.80
assert report.meets_target
assert report.false_positives == 0
assert report.false_negatives == 0
def test_expanded_suite_meets_ninety_five_percent_confidence() -> None:
threshold, report = tune_alert_threshold(target_confidence=0.95)
assert len(expanded_historical_cases()) >= 80
assert report.accuracy == 1.0
assert report.confidence_rate >= 0.95
assert report.meets_target
assert report.false_positives == 0
assert report.false_negatives == 0
assert DEFAULT_BACKTEST_ALERT_THRESHOLD <= threshold <= MAX_BACKTEST_ALERT_THRESHOLD
def test_default_backtest_threshold_on_expanded_suite() -> None:
report = run_historical_backtest(
use_expanded_suite=True,
target_confidence=0.95,
)
assert report.alert_threshold == DEFAULT_BACKTEST_ALERT_THRESHOLD
assert report.accuracy == 1.0
assert report.confidence_rate >= 0.95