VIOLET V2c: synthetic intent scripts + ExecStormHarness + 9-scenario matrix
synthetic_intents.py: seeded IntentScriptSpec -> CycleSpec scripts (script_hash + outcomes_hash determinism, V0 discipline); per-scenario router ExecConfig constructed directly (no env mutation); cycle executor runs full ENTER->terminal->flatten lifecycles with per-scenario terminal predicates and cycle-end invariants (working registry empty, driver drained, slot flat). exec_harness.py: composition root — production bundle (MOCK, injected ScriptedVenue), ExecDeadlineDriver ports wired, pump = venue.reconcile() -> kernel + driver.on_fill forwarding (the production seam), gate report via the ExecGateReport schema, archive next to V0 reports. scripted_venue.py amendment: MARKET orders never rest (venue realism — directives are keyed by trade_id and the R1 MARKET fallback shares the position's trade_id). Matrix green through the REAL kernel at 100ms TTL: immediate fill, rest-then-fill (deadline cancelled), fill-races-cancel (no retry), rest-expire-retry (-r1 opens), retry-exhaust skip|market, exit-expire -> MARKET same trade_id, post-only reject, cancel-reject (no strand). Two runs same seed -> identical outcomes_hash. Router 77 green; shared clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
75
prod/clean_arch/violet/test_violet_synthetic_intents.py
Normal file
75
prod/clean_arch/violet/test_violet_synthetic_intents.py
Normal file
@@ -0,0 +1,75 @@
|
||||
"""V2c: script generation determinism + plan→intent mapping."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.insert(0, "/mnt/dolphinng5_predict")
|
||||
|
||||
import pytest
|
||||
|
||||
from prod.clean_arch.dita_v2.exec_router import ExecConfig, ExecutionRouter
|
||||
from prod.clean_arch.violet.synthetic_intents import (
|
||||
CycleSpec,
|
||||
IntentScriptSpec,
|
||||
Scenario,
|
||||
build_enter_intent,
|
||||
build_exit_intent,
|
||||
generate_script,
|
||||
router_config_for,
|
||||
script_hash,
|
||||
)
|
||||
|
||||
|
||||
def test_script_is_seed_deterministic():
|
||||
spec = IntentScriptSpec(n_cycles=18, seed=7)
|
||||
a, b = generate_script(spec), generate_script(spec)
|
||||
assert a == b
|
||||
assert script_hash(a) == script_hash(b)
|
||||
c = generate_script(IntentScriptSpec(n_cycles=18, seed=8))
|
||||
assert script_hash(a) != script_hash(c)
|
||||
|
||||
|
||||
def test_round_robin_covers_all_scenarios():
|
||||
cycles = generate_script(IntentScriptSpec(n_cycles=18, seed=7))
|
||||
seen = {c.scenario for c in cycles}
|
||||
assert seen == set(Scenario)
|
||||
assert all(c.price > 0 for c in cycles)
|
||||
assert len({c.trade_id for c in cycles}) == 18
|
||||
|
||||
|
||||
def test_router_config_mapping():
|
||||
assert router_config_for(Scenario.IMMEDIATE_FILL).entry_miss == "skip"
|
||||
r = router_config_for(Scenario.REST_EXPIRE_RETRY)
|
||||
assert (r.entry_miss, r.entry_retries, r.retry_exhaust) == ("retry", 1, "skip")
|
||||
m = router_config_for(Scenario.RETRY_EXHAUST_MARKET)
|
||||
assert (m.entry_miss, m.retry_exhaust) == ("retry", "market")
|
||||
assert all(router_config_for(s).style == "maker_both" for s in Scenario)
|
||||
|
||||
|
||||
def test_enter_intent_carries_plan_fields():
|
||||
router = ExecutionRouter(ExecConfig(style="maker_both"))
|
||||
cycle = CycleSpec(idx=0, scenario=Scenario.IMMEDIATE_FILL,
|
||||
trade_id="T1", price=100.0)
|
||||
plan = router.plan_entry(trade_id="T1", asset="STORMUSDT",
|
||||
position_side="SHORT", reference_price=100.0)
|
||||
intent = build_enter_intent(cycle, plan, "STORMUSDT")
|
||||
assert intent.order_type == "LIMIT" and intent.limit_price == plan.limit_price
|
||||
assert intent.metadata["_time_in_force"] == "PostOnly"
|
||||
assert intent.trade_id == "T1" and intent.action.value == "ENTER"
|
||||
|
||||
|
||||
def test_exit_intent_market_when_urgent():
|
||||
router = ExecutionRouter(ExecConfig(style="maker_both"))
|
||||
plan = router.plan_exit(trade_id="T2", asset="STORMUSDT",
|
||||
position_side="SHORT", reference_price=100.0,
|
||||
reason="CATASTROPHIC")
|
||||
assert not plan.is_maker and plan.order_type == "MARKET"
|
||||
intent = build_exit_intent("T2", plan, "STORMUSDT", size=1.0, price=100.0)
|
||||
assert intent.order_type == "MARKET"
|
||||
assert intent.metadata["_time_in_force"] == "GTC"
|
||||
assert intent.target_size == 1.0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(pytest.main([__file__, "-v"]))
|
||||
Reference in New Issue
Block a user