Task 5 review fixes: update the stale observed-track invariant pin (Task 3 added bybit_4edge_exec), move funding_since off the kill-switch dry-run path so it doesn't make a wasted network call, and add unit coverage proving plan_orders flattens a held position when equity=0 (de-funded/ killswitched edge). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
from fxhnt.application.forward_definition import definition_hash, track_definition
|
|
from fxhnt.registry import STRATEGY_REGISTRY
|
|
|
|
|
|
def test_hash_is_stable_under_key_reordering():
|
|
assert definition_hash({"a": 1, "b": 2}, 1) == definition_hash({"b": 2, "a": 1}, 1)
|
|
|
|
|
|
def test_hash_changes_when_a_param_changes():
|
|
# the BTC-drop case: instruments 6 -> 5 must change the hash
|
|
six = definition_hash({"instruments": ["SPY", "IEF", "GLD", "PDBC", "DBMF", "BTC-USD"]}, 1)
|
|
five = definition_hash({"instruments": ["SPY", "IEF", "GLD", "PDBC", "DBMF"]}, 1)
|
|
assert six != five
|
|
|
|
|
|
def test_hash_changes_when_version_bumps():
|
|
assert definition_hash({"a": 1}, 1) != definition_hash({"a": 1}, 2)
|
|
|
|
|
|
def test_every_active_track_declares_a_definition():
|
|
for sid in STRATEGY_REGISTRY:
|
|
params, version, mode = track_definition(sid)
|
|
assert isinstance(params, dict) and isinstance(version, int)
|
|
assert mode in ("recompute", "observed")
|
|
|
|
|
|
def test_observed_mode_is_exactly_xsfunding():
|
|
# Pin is deliberately exhaustive: whenever a new track adopts record_mode="observed", update this set
|
|
# (C2 Task 3 added bybit_4edge_exec) so the change is reviewed, not silently absorbed.
|
|
observed = {sid for sid in STRATEGY_REGISTRY if track_definition(sid)[2] == "observed"}
|
|
assert observed == {"xsfunding", "multistrat_exec", "bybit_4edge_exec"}
|