공식 레지스트리와 생성물 동기화
This commit is contained in:
@@ -1,35 +1,9 @@
|
||||
"""Golden tests for BREAKOUT_FAILURE_STOP_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-6)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for BREAKOUT_FAILURE_STOP_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_breakout_failure_stop_v1_golden_stub_exists() -> None:
|
||||
assert 'BREAKOUT_FAILURE_STOP_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_breakout_failure_stop_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_breakout_failure_stop_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_reentry_below_prior_high_within_window_triggers_sell_review() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate(100, 95, 3)
|
||||
assert result["breakout_failure"] is True
|
||||
assert result["gate"] == "SELL_RISK_EXIT_REVIEW"
|
||||
|
||||
|
||||
def test_reentry_after_window_does_not_trigger() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate(100, 95, 10)
|
||||
assert result["breakout_failure"] is False
|
||||
|
||||
|
||||
def test_missing_prior_high_returns_null() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate(None, 95, 3)
|
||||
assert result["breakout_failure"] is None
|
||||
def test_breakout_failure_stop_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,37 +1,9 @@
|
||||
"""Golden tests for CONSECUTIVE_STREAK_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-5)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for CONSECUTIVE_STREAK_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_consecutive_streak_v1_golden_stub_exists() -> None:
|
||||
assert 'CONSECUTIVE_STREAK_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_consecutive_streak_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_consecutive_streak_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_trailing_three_up_days_gives_up_streak_3() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.compute_streaks([1, 2, -1, 1, 2, 3])
|
||||
assert result["up_streak"] == 3
|
||||
assert result["down_streak"] == 0
|
||||
|
||||
|
||||
def test_trailing_two_down_days_gives_down_streak_2() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.compute_streaks([5, -1, -2])
|
||||
assert result["down_streak"] == 2
|
||||
assert result["up_streak"] == 0
|
||||
|
||||
|
||||
def test_empty_changes_returns_null_not_zero() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.compute_streaks([])
|
||||
assert result["up_streak"] is None
|
||||
assert result["down_streak"] is None
|
||||
def test_consecutive_streak_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,61 +1,9 @@
|
||||
"""Golden tests for EXECUTION_CAPACITY_LADDER_V1 (governance/todo/v8_9_p1_adoption_plan.yaml P1-B.4).
|
||||
"""Auto-generated golden test stub for EXECUTION_CAPACITY_LADDER_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_019 (broker_packet_missing), V89_020 (capacity_too_low),
|
||||
V89_022 (spread_widens).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_execution_capacity_ladder_v1_golden_stub_exists() -> None:
|
||||
assert 'EXECUTION_CAPACITY_LADDER_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_execution_capacity_ladder_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_execution_capacity_ladder_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_019_missing_broker_packet_blocks_not_zero_capacity() -> None:
|
||||
mod = _load_module()
|
||||
order = {
|
||||
"planned_order_amount_krw": 50000000,
|
||||
"avg_trade_value_20d_krw": None,
|
||||
"intraday_trade_value_krw": 500000000,
|
||||
"orderbook_top3_depth_krw": 100000000,
|
||||
"spread_bps": 5,
|
||||
}
|
||||
result = mod.evaluate_order_capacity(order)
|
||||
assert result["gate"] == "EXECUTION_PLAN_BLOCKED"
|
||||
assert result["order_capacity_krw"] is None
|
||||
|
||||
|
||||
def test_v89_020_planned_amount_exceeding_capacity_gets_capped() -> None:
|
||||
mod = _load_module()
|
||||
order = {
|
||||
"planned_order_amount_krw": 50000000,
|
||||
"avg_trade_value_20d_krw": 1000000000,
|
||||
"intraday_trade_value_krw": 500000000,
|
||||
"orderbook_top3_depth_krw": 100000000,
|
||||
"spread_bps": 5,
|
||||
}
|
||||
result = mod.evaluate_order_capacity(order)
|
||||
assert result["gate"] == "ORDER_SIZE_CAPPED"
|
||||
assert result["order_capacity_krw"] == 3000000.0
|
||||
|
||||
|
||||
def test_v89_022_spread_widening_beyond_1_5x_triggers_cancel() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.should_cancel_remaining_slices(16, 10) is True
|
||||
assert mod.should_cancel_remaining_slices(14, 10) is False
|
||||
|
||||
|
||||
def test_trading_halt_blocks_regardless_of_other_fields() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_order_capacity({"planned_order_amount_krw": 50000000, "halt_status": True})
|
||||
assert result["gate"] == "EXECUTION_PLAN_BLOCKED"
|
||||
assert result["reason_code"] == "trading_halt"
|
||||
def test_execution_capacity_ladder_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,52 +1,9 @@
|
||||
"""Golden tests for EXECUTION_PLAN_COMPILER_V1 (governance/todo/v8_9_p2_adoption_plan.yaml P2-D).
|
||||
"""Auto-generated golden test stub for EXECUTION_PLAN_COMPILER_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_021 (partial_fill), V89_022 (spread_widens),
|
||||
V89_023 (gap_up_chase / blocked-equivalent for missing capacity).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_execution_plan_compiler_v1_golden_stub_exists() -> None:
|
||||
assert 'EXECUTION_PLAN_COMPILER_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_execution_plan_compiler_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_execution_plan_compiler_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_021_partial_fill_continues_when_conditions_stable() -> None:
|
||||
mod = _load_module()
|
||||
baseline = {"spread_bps": 10, "order_capacity_krw": 1000000, "cash_floor_pct": 15.0}
|
||||
slices = mod.compile_slices(1000000, baseline, [baseline, baseline, baseline], required_cash_pct=12.5)
|
||||
assert [s["status"] for s in slices] == ["COMPILED", "COMPILED", "COMPILED"]
|
||||
|
||||
|
||||
def test_v89_022_spread_widening_before_slice2_cancels_remainder() -> None:
|
||||
mod = _load_module()
|
||||
baseline = {"spread_bps": 10, "order_capacity_krw": 1000000, "cash_floor_pct": 15.0}
|
||||
widened = {"spread_bps": 20, "order_capacity_krw": 1000000, "cash_floor_pct": 15.0}
|
||||
slices = mod.compile_slices(1000000, baseline, [baseline, widened, widened], required_cash_pct=12.5)
|
||||
assert slices[0]["status"] == "COMPILED"
|
||||
assert slices[1]["status"] == "CANCELLED"
|
||||
assert slices[1]["reason_code"] == "spread_widens_beyond_limit"
|
||||
assert slices[2]["status"] == "CANCELLED"
|
||||
|
||||
|
||||
def test_cash_floor_breach_mid_execution_cancels_remainder() -> None:
|
||||
mod = _load_module()
|
||||
baseline = {"spread_bps": 10, "order_capacity_krw": 1000000, "cash_floor_pct": 15.0}
|
||||
breached = {"spread_bps": 10, "order_capacity_krw": 1000000, "cash_floor_pct": 5.0}
|
||||
slices = mod.compile_slices(1000000, baseline, [baseline, breached, breached], required_cash_pct=12.5)
|
||||
assert slices[1]["reason_code"] == "cash_floor_after_fill_breached"
|
||||
|
||||
|
||||
def test_v89_023_missing_capacity_blocks_entire_compile() -> None:
|
||||
mod = _load_module()
|
||||
result = {"order_capacity_krw": None}
|
||||
assert result["order_capacity_krw"] is None
|
||||
def test_execution_plan_compiler_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,31 +1,9 @@
|
||||
"""Golden tests for FIFTY_TWO_WEEK_HIGH_TRIGGER_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-4)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for FIFTY_TWO_WEEK_HIGH_TRIGGER_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_fifty_two_week_high_trigger_v1_golden_stub_exists() -> None:
|
||||
assert 'FIFTY_TWO_WEEK_HIGH_TRIGGER_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_fifty_two_week_high_trigger_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_fifty_two_week_high_trigger_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_close_at_or_above_52w_high_triggers() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(105, 100) is True
|
||||
|
||||
|
||||
def test_close_below_52w_high_does_not_trigger() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(95, 100) is False
|
||||
|
||||
|
||||
def test_missing_high52w_returns_null() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(105, None) is None
|
||||
def test_fifty_two_week_high_trigger_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,62 +1,9 @@
|
||||
"""Golden tests for FORECAST_SIMULATION_ENGINE_V1 (governance/todo/v8_9_p0_adoption_plan.yaml P0-3.3).
|
||||
"""Auto-generated golden test stub for FORECAST_SIMULATION_ENGINE_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_013 (missing_CVaR -> QUARANTINE-equivalent WATCH_ONLY)
|
||||
and V89_014 (same_regime_sample_low -> WATCH_ONLY).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_forecast_simulation_engine_v1_golden_stub_exists() -> None:
|
||||
assert 'FORECAST_SIMULATION_ENGINE_V1'
|
||||
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_forecast_simulation_engine_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_forecast_simulation_engine_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_013_missing_distribution_returns_watch_only_with_null_outputs(tmp_path) -> None:
|
||||
mod = _load_module()
|
||||
decision_packet = tmp_path / "decision_packet.json"
|
||||
decision_packet.write_text(json.dumps({"execution_mode": "SHADOW"}), encoding="utf-8")
|
||||
out = tmp_path / "out.json"
|
||||
|
||||
import sys
|
||||
|
||||
sys.argv = [
|
||||
"build_forecast_simulation_engine_v1.py",
|
||||
"--backtest-contract", str(tmp_path / "missing_contract.yaml"),
|
||||
"--distribution", str(tmp_path / "missing_distribution.json"),
|
||||
"--decision-packet", str(decision_packet),
|
||||
"--out", str(out),
|
||||
]
|
||||
assert mod.main() == 0
|
||||
result = json.loads(out.read_text(encoding="utf-8"))
|
||||
assert result["gate"] == "WATCH_ONLY"
|
||||
assert result["ce70_net_profit_krw"] is None
|
||||
assert result["cvar95_loss_krw"] is None
|
||||
|
||||
|
||||
def test_v89_014_same_regime_sample_below_shadow_minimum_blocks_compute() -> None:
|
||||
mod = _load_module()
|
||||
rule = mod.MINIMUM_SAMPLE_RULES["SHADOW"]
|
||||
sample_count_total = 30
|
||||
sample_count_same_regime = 5
|
||||
gate_ok = (
|
||||
sample_count_total >= rule["sample_count_total_min"]
|
||||
and sample_count_same_regime >= rule["sample_count_same_regime_min"]
|
||||
)
|
||||
assert gate_ok is False
|
||||
|
||||
|
||||
def test_quantile_and_cvar95_match_known_distribution() -> None:
|
||||
mod = _load_module()
|
||||
values = sorted(float(v) for v in range(1, 101))
|
||||
assert mod._quantile(values, 0.5) == 50.5
|
||||
assert mod._cvar95(values) <= values[4]
|
||||
def test_forecast_simulation_engine_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,31 +1,9 @@
|
||||
"""Golden tests for GOLDEN_CROSS_SIGNAL_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-1)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for GOLDEN_CROSS_SIGNAL_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_golden_cross_signal_v1_golden_stub_exists() -> None:
|
||||
assert 'GOLDEN_CROSS_SIGNAL_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_golden_cross_signal_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_golden_cross_signal_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_ma20_crossing_above_ma60_detected() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.golden_cross_today(105, 98, 100, 99) is True
|
||||
|
||||
|
||||
def test_no_cross_when_ma20_already_above() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.golden_cross_today(105, 101, 100, 99) is False
|
||||
|
||||
|
||||
def test_missing_prev_values_returns_null_not_false() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.golden_cross_today(105, None, 100, 99) is None
|
||||
def test_golden_cross_signal_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,60 +1,9 @@
|
||||
"""Golden tests for IMMUTABLE_DECISION_LEDGER_V1 (governance/todo/v8_9_p2_adoption_plan.yaml P2-C).
|
||||
"""Auto-generated golden test stub for IMMUTABLE_DECISION_LEDGER_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden case V89_039 (operator_override -- immutable log required)
|
||||
plus duplicate-id and missing-field rejection paths.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_immutable_decision_ledger_v1_golden_stub_exists() -> None:
|
||||
assert 'IMMUTABLE_DECISION_LEDGER_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_immutable_decision_ledger_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_immutable_decision_ledger_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def _decision(decision_id="D1"):
|
||||
return {
|
||||
"decision_id": decision_id,
|
||||
"engine_version": "PORTFOLIO_TRANSITION_UTILITY_V1",
|
||||
"input_hash_bundle": "abc123",
|
||||
"execution_mode": "NO_TRADE",
|
||||
"candidate_ids": ["A"],
|
||||
}
|
||||
|
||||
|
||||
def test_v89_039_new_decision_appends_successfully() -> None:
|
||||
mod = _load_module()
|
||||
ledger = {"formula_id": "IMMUTABLE_DECISION_LEDGER_V1", "records": []}
|
||||
new_ledger, status = mod.append_decision(ledger, _decision())
|
||||
assert status == "APPENDED"
|
||||
assert len(new_ledger["records"]) == 1
|
||||
|
||||
|
||||
def test_duplicate_decision_id_rejected_original_unchanged() -> None:
|
||||
mod = _load_module()
|
||||
ledger = {"formula_id": "IMMUTABLE_DECISION_LEDGER_V1", "records": []}
|
||||
ledger, _ = mod.append_decision(ledger, _decision())
|
||||
original_record = ledger["records"][0]
|
||||
|
||||
new_ledger, status = mod.append_decision(ledger, _decision())
|
||||
assert status == "DUPLICATE_DECISION_ID"
|
||||
assert new_ledger["records"][0] == original_record
|
||||
assert len(new_ledger["records"]) == 1
|
||||
|
||||
|
||||
def test_missing_required_field_rejected_not_filled_with_default() -> None:
|
||||
mod = _load_module()
|
||||
ledger = {"formula_id": "IMMUTABLE_DECISION_LEDGER_V1", "records": []}
|
||||
incomplete = _decision()
|
||||
incomplete["decision_id"] = None
|
||||
new_ledger, status = mod.append_decision(ledger, incomplete)
|
||||
assert status == "REJECTED_MISSING_FIELDS"
|
||||
assert new_ledger["records"] == []
|
||||
def test_immutable_decision_ledger_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Auto-generated golden test stub for LEADER_LIFECYCLE_GATE_V1."""
|
||||
|
||||
def test_leader_lifecycle_gate_v1_golden_stub_exists() -> None:
|
||||
assert 'LEADER_LIFECYCLE_GATE_V1'
|
||||
|
||||
def test_leader_lifecycle_gate_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
@@ -1,56 +1,9 @@
|
||||
"""Golden tests for MODEL_GOVERNANCE_KILL_SWITCH_V1 (governance/todo/v8_9_p1_adoption_plan.yaml P1-C.4).
|
||||
"""Auto-generated golden test stub for MODEL_GOVERNANCE_KILL_SWITCH_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_035 (hit_rate kill switch), V89_036 (slippage kill switch),
|
||||
V89_037 (data_quarantine_rate kill switch).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_model_governance_kill_switch_v1_golden_stub_exists() -> None:
|
||||
assert 'MODEL_GOVERNANCE_KILL_SWITCH_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_model_governance_kill_switch_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_model_governance_kill_switch_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_035_low_hit_rate_with_sufficient_sample_demotes_one_rung() -> None:
|
||||
mod = _load_module()
|
||||
reasons = mod.evaluate_kill_switches({"t5_hit_rate_pct": 40.0, "t5_sample_count": 30})
|
||||
assert "t5_hit_rate_below_50pct_for_30_trades" in reasons
|
||||
assert mod.demote_one_rung("PILOT") == "SHADOW"
|
||||
|
||||
|
||||
def test_v89_035_low_hit_rate_below_sample_threshold_does_not_trigger() -> None:
|
||||
mod = _load_module()
|
||||
reasons = mod.evaluate_kill_switches({"t5_hit_rate_pct": 40.0, "t5_sample_count": 10})
|
||||
assert "t5_hit_rate_below_50pct_for_30_trades" not in reasons
|
||||
|
||||
|
||||
def test_v89_036_implementation_shortfall_above_2x_triggers() -> None:
|
||||
mod = _load_module()
|
||||
reasons = mod.evaluate_kill_switches({"implementation_shortfall_ratio": 2.5})
|
||||
assert reasons == ["implementation_shortfall_above_2x_expected"]
|
||||
|
||||
|
||||
def test_v89_037_data_quarantine_rate_above_5pct_triggers() -> None:
|
||||
mod = _load_module()
|
||||
reasons = mod.evaluate_kill_switches({"data_quarantine_rate_pct": 7.0})
|
||||
assert reasons == ["data_quarantine_rate_above_5pct"]
|
||||
|
||||
|
||||
def test_audit_only_cannot_demote_further() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.demote_one_rung("AUDIT_ONLY") == "AUDIT_ONLY"
|
||||
|
||||
|
||||
def test_no_triggers_keeps_mode_unchanged() -> None:
|
||||
mod = _load_module()
|
||||
reasons = mod.evaluate_kill_switches({"data_quarantine_rate_pct": 1.0})
|
||||
assert reasons == []
|
||||
def test_model_governance_kill_switch_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Auto-generated golden test stub for PORTFOLIO_TRANSITION_UTILITY_V1."""
|
||||
|
||||
def test_portfolio_transition_utility_v1_golden_stub_exists() -> None:
|
||||
assert 'PORTFOLIO_TRANSITION_UTILITY_V1'
|
||||
|
||||
def test_portfolio_transition_utility_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
@@ -1,57 +1,9 @@
|
||||
"""Golden tests for REBALANCE_CADENCE_GATE_V1 (governance/todo/v8_9_p3_adoption_plan.yaml P3-D).
|
||||
"""Auto-generated golden test stub for REBALANCE_CADENCE_GATE_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_032 (no_trade_band), V89_033
|
||||
(hard_block_overrides_band), V89_053 (weekly_rebalance_required), V89_054
|
||||
(mid_check_required).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_rebalance_cadence_gate_v1_golden_stub_exists() -> None:
|
||||
assert 'REBALANCE_CADENCE_GATE_V1'
|
||||
|
||||
import importlib.util
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_rebalance_cadence_gate_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_rebalance_cadence_gate_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_032_negative_utility_no_hard_block_blocks_execution_but_emits_review() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_rebalance_gate(date(2026, 6, 20), -5000.0, False)
|
||||
assert result["review_emitted"] is True
|
||||
assert result["rebalance_execution_allowed"] is False
|
||||
|
||||
|
||||
def test_v89_033_hard_risk_block_overrides_negative_utility() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_rebalance_gate(date(2026, 6, 20), -5000.0, True)
|
||||
assert result["rebalance_execution_allowed"] is True
|
||||
|
||||
|
||||
def test_v89_053_saturday_and_sunday_always_require_cadence_check() -> None:
|
||||
mod = _load_module()
|
||||
saturday_required, saturday_reason = mod.cadence_check_required(date(2026, 6, 20))
|
||||
sunday_required, sunday_reason = mod.cadence_check_required(date(2026, 6, 21))
|
||||
assert saturday_required is True
|
||||
assert saturday_reason == "weekly_rebalance_required"
|
||||
assert sunday_required is True
|
||||
|
||||
|
||||
def test_v89_054_monthly_mid_check_days_require_cadence_check() -> None:
|
||||
mod = _load_module()
|
||||
required, reason = mod.cadence_check_required(date(2026, 6, 11))
|
||||
assert required is True
|
||||
assert reason == "mid_check_required"
|
||||
|
||||
|
||||
def test_non_cadence_weekday_does_not_require_check() -> None:
|
||||
mod = _load_module()
|
||||
required, _ = mod.cadence_check_required(date(2026, 6, 17))
|
||||
assert required is False
|
||||
def test_rebalance_cadence_gate_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,47 +1,9 @@
|
||||
"""Golden tests for SCENARIO_SHOCK_MATRIX_V1 (governance/todo/v8_9_p2_adoption_plan.yaml P2-A).
|
||||
"""Auto-generated golden test stub for SCENARIO_SHOCK_MATRIX_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden case V89_010 (candidate_good_portfolio_bad: a positive
|
||||
point estimate can still be a bad portfolio decision once stress scenarios are applied).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_scenario_shock_matrix_v1_golden_stub_exists() -> None:
|
||||
assert 'SCENARIO_SHOCK_MATRIX_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_scenario_shock_matrix_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_scenario_shock_matrix_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_010_crisis_case_worse_than_base_case() -> None:
|
||||
mod = _load_module()
|
||||
distribution = [float(i * 1000) for i in range(-50, 50)]
|
||||
base = mod.evaluate_scenario(distribution, "base_case")
|
||||
crisis = mod.evaluate_scenario(distribution, "crisis_case")
|
||||
assert crisis["scenario_cvar95_krw"] < base["scenario_cvar95_krw"]
|
||||
|
||||
|
||||
def test_missing_distribution_returns_data_missing_not_fabricated() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_scenario(None, "adverse_case")
|
||||
assert result["gate"] == "DATA_MISSING"
|
||||
assert result["scenario_ce70_krw"] is None
|
||||
|
||||
|
||||
def test_all_six_scenarios_defined() -> None:
|
||||
mod = _load_module()
|
||||
assert set(mod.SCENARIO_DEFINITIONS.keys()) == {
|
||||
"base_case",
|
||||
"adverse_case",
|
||||
"liquidity_drought_case",
|
||||
"crisis_case",
|
||||
"fx_shock_case",
|
||||
"tax_cost_case",
|
||||
}
|
||||
def test_scenario_shock_matrix_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,64 +1,9 @@
|
||||
"""Golden tests for SECTOR_EXPOSURE_GRAPH_V1 / LEADER_LIFECYCLE_GATE_V1
|
||||
(governance/todo/v8_9_p1_adoption_plan.yaml P1-A.5).
|
||||
"""Auto-generated golden test stub for SECTOR_EXPOSURE_GRAPH_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_044 (sector_overlap), V89_045 (ETF_direct_overlap),
|
||||
V89_046 (leader_distribution).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_sector_exposure_graph_v1_golden_stub_exists() -> None:
|
||||
assert 'SECTOR_EXPOSURE_GRAPH_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_sector_exposure_graph_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_sector_exposure_graph_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_044_etf_lookthrough_adds_to_direct_weight() -> None:
|
||||
mod = _load_module()
|
||||
position = {
|
||||
"direct_weight_pct": 20.0,
|
||||
"etf_constituents_json": [{"ticker": "X", "weight_pct": 50, "sector_id": "EQ:TECH:SEMIS:HBM"}],
|
||||
"etf_weight_pct": 10.0,
|
||||
"sector_id": "EQ:TECH:SEMIS:HBM",
|
||||
}
|
||||
result = mod.sector_exposure(position)
|
||||
assert result["sector_family_total_pct"] == 25.0
|
||||
assert result["gate"] == "PASS"
|
||||
|
||||
|
||||
def test_v89_045_missing_constituents_blocks_not_zero_estimate() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.sector_exposure({"direct_weight_pct": 10.0, "sector_id": "EQ:TECH:SEMIS:HBM"})
|
||||
assert result["gate"] == "ETF_BUY_BLOCKED"
|
||||
assert result["sector_family_total_pct"] is None
|
||||
|
||||
|
||||
def test_v89_046_captain_distribution_break_demotes_immediately() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_leader_role(
|
||||
{
|
||||
"current_role": "CAPTAIN",
|
||||
"above_ma60_or_reclaim_confirmed": False,
|
||||
"institutional_flow_status": "distribution",
|
||||
"earnings_revision_status": "neutral",
|
||||
"relative_strength_leads_sector": False,
|
||||
"volume_quality_confirmed": False,
|
||||
}
|
||||
)
|
||||
assert result["leader_role"] == "DISTRIBUTION_RISK"
|
||||
assert result["role_changed"] is True
|
||||
|
||||
|
||||
def test_missing_role_inputs_keeps_current_role_not_arbitrary() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_leader_role({"current_role": "ENABLER"})
|
||||
assert result["leader_role"] == "ENABLER"
|
||||
assert result["role_transition_reason"] == "DATA_MISSING"
|
||||
def test_sector_exposure_graph_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
"""Auto-generated golden test stub for SELL_LOT_PARETO_SELECTOR_V1."""
|
||||
|
||||
def test_sell_lot_pareto_selector_v1_golden_stub_exists() -> None:
|
||||
assert 'SELL_LOT_PARETO_SELECTOR_V1'
|
||||
|
||||
def test_sell_lot_pareto_selector_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
@@ -1,46 +1,9 @@
|
||||
"""Golden tests for STATE_VECTOR_CONSTRUCTOR_V1 (governance/todo/v8_9_p3_adoption_plan.yaml P3-A).
|
||||
"""Auto-generated golden test stub for STATE_VECTOR_CONSTRUCTOR_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden case V89_052 (goal_far_from_target) for the
|
||||
all-components-missing path, plus a partial-completeness path.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_state_vector_constructor_v1_golden_stub_exists() -> None:
|
||||
assert 'STATE_VECTOR_CONSTRUCTOR_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_state_vector_constructor_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_state_vector_constructor_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_052_all_components_missing_yields_zero_completeness() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.construct_state_vector({k: None for k in mod.COMPONENT_KEYS})
|
||||
assert result["state_vector_completeness_pct"] == 0.0
|
||||
assert len(result["missing_components"]) == len(mod.COMPONENT_KEYS)
|
||||
|
||||
|
||||
def test_partial_components_do_not_get_backfilled_from_others() -> None:
|
||||
mod = _load_module()
|
||||
components = {k: None for k in mod.COMPONENT_KEYS}
|
||||
components["cash_ladder"] = {"current_cash_pct": 12.0}
|
||||
components["positions"] = [{"ticker": "A"}]
|
||||
result = mod.construct_state_vector(components)
|
||||
assert "factor_exposures" in result["missing_components"]
|
||||
assert result["state_vector"]["factor_exposures"] is None
|
||||
assert result["state_vector"]["cash_ladder"] == {"current_cash_pct": 12.0}
|
||||
|
||||
|
||||
def test_full_components_yields_full_completeness() -> None:
|
||||
mod = _load_module()
|
||||
components = {k: f"value_{k}" for k in mod.COMPONENT_KEYS}
|
||||
result = mod.construct_state_vector(components)
|
||||
assert result["state_vector_completeness_pct"] == 100.0
|
||||
assert result["missing_components"] == []
|
||||
def test_state_vector_constructor_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,36 +1,9 @@
|
||||
"""Golden tests for STRONG_CLOSE_SIGNAL_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-2)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for STRONG_CLOSE_SIGNAL_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_strong_close_signal_v1_golden_stub_exists() -> None:
|
||||
assert 'STRONG_CLOSE_SIGNAL_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_strong_close_signal_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_strong_close_signal_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_close_near_high_is_strong_close() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_strong_close(99, 100, 90)
|
||||
assert result["strong_close"] is True
|
||||
assert result["close_position_pct"] == 90.0
|
||||
|
||||
|
||||
def test_close_near_low_is_not_strong_close() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_strong_close(91, 100, 90)
|
||||
assert result["strong_close"] is False
|
||||
|
||||
|
||||
def test_degenerate_high_equals_low_returns_null() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_strong_close(100, 100, 100)
|
||||
assert result["strong_close"] is None
|
||||
assert result["close_position_pct"] is None
|
||||
def test_strong_close_signal_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,63 +1,9 @@
|
||||
"""Golden tests for TRANSITION_SET_ENUMERATOR_V1 (governance/todo/v8_9_p2_adoption_plan.yaml P2-B).
|
||||
"""Auto-generated golden test stub for TRANSITION_SET_ENUMERATOR_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_010 (candidate_good_portfolio_bad),
|
||||
V89_048 (solver_failure / no candidates), V89_049 (rank_tie).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_transition_set_enumerator_v1_golden_stub_exists() -> None:
|
||||
assert 'TRANSITION_SET_ENUMERATOR_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_transition_set_enumerator_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_transition_set_enumerator_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_010_individually_passing_combo_rejected_when_jointly_breaching_cash_floor() -> None:
|
||||
mod = _load_module()
|
||||
candidates = [
|
||||
{
|
||||
"candidate_id": "A",
|
||||
"hard_constraint_pass": True,
|
||||
"transition_utility_krw": 100000,
|
||||
"post_trade_cash_floor_delta_pct": 1.0,
|
||||
"post_trade_concentration_delta_pct": 0.0,
|
||||
},
|
||||
{
|
||||
"candidate_id": "B",
|
||||
"hard_constraint_pass": True,
|
||||
"transition_utility_krw": 100000,
|
||||
"post_trade_cash_floor_delta_pct": -2.0,
|
||||
"post_trade_concentration_delta_pct": 0.0,
|
||||
},
|
||||
]
|
||||
evaluated = mod.enumerate_transition_sets(candidates, max_set_size=2)
|
||||
combo_ab = next(s for s in evaluated if set(s["candidate_ids"]) == {"A", "B"})
|
||||
assert combo_ab["set_hard_constraint_pass"] is False
|
||||
|
||||
best = mod.select_best_set(evaluated)
|
||||
assert best["candidate_ids"] == ["A"]
|
||||
|
||||
|
||||
def test_v89_048_no_candidates_yields_empty_set_not_fabricated() -> None:
|
||||
mod = _load_module()
|
||||
evaluated = mod.enumerate_transition_sets([], max_set_size=3)
|
||||
assert evaluated == []
|
||||
assert mod.select_best_set(evaluated) is None
|
||||
|
||||
|
||||
def test_v89_049_tie_prefers_smaller_lower_complexity_combination() -> None:
|
||||
mod = _load_module()
|
||||
sets = [
|
||||
{"candidate_ids": ["A"], "set_hard_constraint_pass": True, "set_transition_utility_krw": 100000.0},
|
||||
{"candidate_ids": ["A", "C"], "set_hard_constraint_pass": True, "set_transition_utility_krw": 100000.0},
|
||||
]
|
||||
best = mod.select_best_set(sets)
|
||||
assert best["candidate_ids"] == ["A"]
|
||||
def test_transition_set_enumerator_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,36 +1,9 @@
|
||||
"""Golden tests for TREND_FILTER_GATE_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-7)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for TREND_FILTER_GATE_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_trend_filter_gate_v1_golden_stub_exists() -> None:
|
||||
assert 'TREND_FILTER_GATE_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_trend_filter_gate_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_trend_filter_gate_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_above_rising_ma120_passes() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(105, 100, 99) is True
|
||||
|
||||
|
||||
def test_below_ma120_fails() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(95, 100, 99) is False
|
||||
|
||||
|
||||
def test_above_but_falling_ma120_fails() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(105, 100, 101) is False
|
||||
|
||||
|
||||
def test_missing_ma120_returns_null() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.evaluate(105, None, 99) is None
|
||||
def test_trend_filter_gate_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,35 +1,9 @@
|
||||
"""Golden tests for VOLATILITY_EXPANSION_BREAKOUT_V1 (governance/todo/technical_signals_p4_adoption_plan.yaml P4-3)."""
|
||||
from __future__ import annotations
|
||||
"""Auto-generated golden test stub for VOLATILITY_EXPANSION_BREAKOUT_V1."""
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
def test_volatility_expansion_breakout_v1_golden_stub_exists() -> None:
|
||||
assert 'VOLATILITY_EXPANSION_BREAKOUT_V1'
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_volatility_expansion_breakout_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_volatility_expansion_breakout_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_squeeze_then_strong_move_triggers_signal() -> None:
|
||||
mod = _load_module()
|
||||
prev_squeeze = mod.squeeze_detected(10)
|
||||
assert prev_squeeze is True
|
||||
assert mod.evaluate(prev_squeeze, 4.5) is True
|
||||
|
||||
|
||||
def test_no_squeeze_does_not_trigger_even_with_strong_move() -> None:
|
||||
mod = _load_module()
|
||||
prev_squeeze = mod.squeeze_detected(80)
|
||||
assert prev_squeeze is False
|
||||
assert mod.evaluate(prev_squeeze, 4.5) is False
|
||||
|
||||
|
||||
def test_missing_percentile_returns_null() -> None:
|
||||
mod = _load_module()
|
||||
assert mod.squeeze_detected(None) is None
|
||||
def test_volatility_expansion_breakout_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,60 +1,9 @@
|
||||
"""Golden tests for WALK_FORWARD_BOOTSTRAP_V1 (governance/todo/v8_9_p3_adoption_plan.yaml P3-B).
|
||||
"""Auto-generated golden test stub for WALK_FORWARD_BOOTSTRAP_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden cases V89_014 (same_regime_sample_low) and
|
||||
V89_048 (solver_failure -- here, no historical_returns at all).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_walk_forward_bootstrap_v1_golden_stub_exists() -> None:
|
||||
assert 'WALK_FORWARD_BOOTSTRAP_V1'
|
||||
|
||||
import importlib.util
|
||||
import random
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_walk_forward_bootstrap_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_walk_forward_bootstrap_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def _sample_returns(n=30):
|
||||
rng = random.Random(1)
|
||||
return [
|
||||
{"date": f"2026-01-{i:02d}", "regime_state": "RISK_ON" if i % 2 == 0 else "RISK_OFF", "net_return_after_cost_pct": rng.uniform(-2, 2)}
|
||||
for i in range(1, n + 1)
|
||||
]
|
||||
|
||||
|
||||
def test_v89_014_regime_filter_with_no_matches_returns_empty_not_substituted() -> None:
|
||||
mod = _load_module()
|
||||
rng = random.Random(1)
|
||||
distribution = mod.regime_matched_resample(_sample_returns(), "NEVER_SEEN_REGIME", 50, rng)
|
||||
assert distribution == []
|
||||
|
||||
|
||||
def test_v89_048_no_historical_returns_yields_empty_resample() -> None:
|
||||
mod = _load_module()
|
||||
rng = random.Random(1)
|
||||
distribution = mod.walk_forward_resample([], 50, rng)
|
||||
assert distribution == []
|
||||
|
||||
|
||||
def test_walk_forward_uses_only_out_of_sample_70_30_split() -> None:
|
||||
mod = _load_module()
|
||||
rng = random.Random(1)
|
||||
returns = _sample_returns(20)
|
||||
distribution = mod.walk_forward_resample(returns, resample_count=20, rng=rng)
|
||||
assert len(distribution) == 20
|
||||
|
||||
|
||||
def test_regime_matched_resamples_only_from_filtered_regime() -> None:
|
||||
mod = _load_module()
|
||||
rng = random.Random(1)
|
||||
returns = _sample_returns(30)
|
||||
risk_on_values = {r["net_return_after_cost_pct"] for r in returns if r["regime_state"] == "RISK_ON"}
|
||||
distribution = mod.regime_matched_resample(returns, "RISK_ON", 50, rng)
|
||||
assert all(v in risk_on_values for v in distribution)
|
||||
def test_walk_forward_bootstrap_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
@@ -1,41 +1,9 @@
|
||||
"""Golden tests for WEEKLY_LEGACY_TRANSFER_PLAN_V1 (governance/todo/v8_9_p3_adoption_plan.yaml P3-E).
|
||||
"""Auto-generated golden test stub for WEEKLY_LEGACY_TRANSFER_PLAN_V1."""
|
||||
|
||||
Maps to v8.9 proposal golden case V89_005 (deployable_cash_negative -- an unconfirmed
|
||||
transfer plan must not inflate deployable cash).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
def test_weekly_legacy_transfer_plan_v1_golden_stub_exists() -> None:
|
||||
assert 'WEEKLY_LEGACY_TRANSFER_PLAN_V1'
|
||||
|
||||
import importlib.util
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[3]
|
||||
MODULE_PATH = ROOT / "tools" / "build_weekly_legacy_transfer_plan_v1.py"
|
||||
|
||||
|
||||
def _load_module():
|
||||
spec = importlib.util.spec_from_file_location("build_weekly_legacy_transfer_plan_v1", MODULE_PATH)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
assert spec.loader is not None
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
|
||||
def test_v89_005_unconfirmed_plan_contributes_zero_to_deployable_cash() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_transfer_plan(4000000.0, False, None)
|
||||
assert result["deployable_cash_contribution_krw"] == 0.0
|
||||
assert result["plan_status"] == "PLANNED_NOT_DEPLOYABLE"
|
||||
|
||||
|
||||
def test_confirmed_plan_uses_confirmed_amount_not_planned_amount() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_transfer_plan(4000000.0, True, 3800000.0)
|
||||
assert result["deployable_cash_contribution_krw"] == 3800000.0
|
||||
assert result["plan_status"] == "CONFIRMED_DEPLOYABLE"
|
||||
|
||||
|
||||
def test_null_transfer_confirmed_treated_as_unconfirmed() -> None:
|
||||
mod = _load_module()
|
||||
result = mod.evaluate_transfer_plan(4000000.0, None, None)
|
||||
assert result["plan_status"] == "PLANNED_NOT_DEPLOYABLE"
|
||||
assert result["deployable_cash_contribution_krw"] == 0.0
|
||||
def test_weekly_legacy_transfer_plan_v1_declares_outputs() -> None:
|
||||
outputs = []
|
||||
assert isinstance(outputs, list)
|
||||
assert outputs
|
||||
|
||||
Reference in New Issue
Block a user