Sprint 2 (accounting + observability parity, PINK scope):
- Verified pink_clickhouse.py writes the 8 BLUE-legacy row families at
matching schema and that capital authority in pink_direct.step() is
solely kernel.account (no balance-poll overwrite in the hot loop).
- Report: prod/clean_arch/dita_v2/SPRINT2_ACCOUNTING_PARITY.md.
Sprint 3 offline groundwork (no exchange contact):
- Add _write_trade_exit_leg to pink_clickhouse.py: one BLUE-schema-faithful
trade_exit_legs row per exit leg, with isolated (non-cumulative) per-leg
deltas tracked via _leg_state (reset on ENTER). Closes the docstring gap.
- New offline suite test_pink_multi_exit_groundwork.py (3 passed):
* Flaw 4 — two-leg exit closes once, realized accrues per leg, closed
slot rejects further EXIT (no double-close).
* Overshoot invariant — a final EXIT requesting more than the remaining
size CLAMPS (size to 0, no oversell), retiring the Sprint 0 cumulative-
ratio risk empirically.
* trade_exit_legs delta + full BLUE column-set assertions.
- Persistence regression after edits: 10 passed.
BLUE untouched: no changes to dolphin.* / DOLPHIN_*_BLUE / nautilus_event_trader.py.
Live VST multi-leg run remains deferred pending explicit authorization.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
80 lines
3.2 KiB
Python
80 lines
3.2 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from types import SimpleNamespace
|
|
from pathlib import Path
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
import prod.launch_dita_v2 as launch_dita_v2
|
|
|
|
|
|
class DummyBundle:
|
|
def __init__(self) -> None:
|
|
self.closed = False
|
|
self.kernel = SimpleNamespace(snapshot=lambda: {"ok": True}, control=SimpleNamespace(as_dict=lambda: {"mode": "NORMAL"}))
|
|
self.venue = SimpleNamespace(__class__=SimpleNamespace(__name__="MockVenueAdapter"))
|
|
self.zinc_plane = SimpleNamespace(__class__=SimpleNamespace(__name__="InMemoryZincPlane"))
|
|
self.projection = SimpleNamespace(__class__=SimpleNamespace(__name__="HazelcastProjection"))
|
|
|
|
def close(self) -> None:
|
|
self.closed = True
|
|
|
|
|
|
class TestLaunchDitaV2(unittest.TestCase):
|
|
def test_supervisor_config_contains_dita_v2_program(self) -> None:
|
|
conf = Path("/mnt/dolphinng5_predict/prod/supervisor/dolphin-supervisord.conf").read_text()
|
|
self.assertIn("[program:dita_v2]", conf)
|
|
self.assertIn("launch_dita_v2.py", conf)
|
|
self.assertIn("DITA_V2_LAUNCHER_MODE=\"serve\"", conf)
|
|
|
|
def test_env_mode_defaults_to_serve(self) -> None:
|
|
previous = os.environ.get("DITA_V2_LAUNCHER_MODE")
|
|
try:
|
|
os.environ.pop("DITA_V2_LAUNCHER_MODE", None)
|
|
self.assertEqual(launch_dita_v2._env_mode(), "serve")
|
|
os.environ["DITA_V2_LAUNCHER_MODE"] = "once"
|
|
self.assertEqual(launch_dita_v2._env_mode(), "once")
|
|
finally:
|
|
if previous is None:
|
|
os.environ.pop("DITA_V2_LAUNCHER_MODE", None)
|
|
else:
|
|
os.environ["DITA_V2_LAUNCHER_MODE"] = previous
|
|
|
|
def test_main_once_uses_snapshot_path(self) -> None:
|
|
bundle = DummyBundle()
|
|
with patch.object(launch_dita_v2, "build_launcher_bundle", return_value=bundle), patch.object(
|
|
launch_dita_v2, "_serve", side_effect=AssertionError("_serve should not run in once mode")
|
|
):
|
|
previous = os.environ.get("DITA_V2_LAUNCHER_MODE")
|
|
os.environ["DITA_V2_LAUNCHER_MODE"] = "once"
|
|
try:
|
|
self.assertEqual(launch_dita_v2.main(), 0)
|
|
self.assertTrue(bundle.closed)
|
|
finally:
|
|
if previous is None:
|
|
os.environ.pop("DITA_V2_LAUNCHER_MODE", None)
|
|
else:
|
|
os.environ["DITA_V2_LAUNCHER_MODE"] = previous
|
|
|
|
def test_main_serve_routes_to_serve(self) -> None:
|
|
bundle = DummyBundle()
|
|
with patch.object(launch_dita_v2, "build_launcher_bundle", return_value=bundle), patch.object(
|
|
launch_dita_v2, "_serve", return_value=7
|
|
) as serve:
|
|
previous = os.environ.get("DITA_V2_LAUNCHER_MODE")
|
|
os.environ["DITA_V2_LAUNCHER_MODE"] = "serve"
|
|
try:
|
|
self.assertEqual(launch_dita_v2.main(), 7)
|
|
serve.assert_called_once()
|
|
self.assertTrue(bundle.closed)
|
|
finally:
|
|
if previous is None:
|
|
os.environ.pop("DITA_V2_LAUNCHER_MODE", None)
|
|
else:
|
|
os.environ["DITA_V2_LAUNCHER_MODE"] = previous
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|