Snapshot PINK DITAv2 system + Sprint 0 flaw-fix verification

First commit of the previously-untracked PINK-on-DITAv2 migration system
(execution moves to the Rust kernel; policy stays on legacy DITA, so Alpha
Engine algorithmic integrity is preserved). BLUE is untouched.

Sprint 0 (safety snapshot + flaw-fix verification, MARKET single-leg scope):
- Verified Rust FSM fixes (flaws 2,4,10,11,13) by source read of lib.rs.
- Hardened 5 vacuous/guarded assertions in test_flaws.py so each flaw test
  genuinely exercises its fix. Most important: Flaw 5 now asserts capital
  moves by EXACTLY realized PnL (was entering/exiting at the same price).
- Offline suites: 533 passed, 0 failed (35 flaws + 402 kernel/accounting/
  bridge + 96 runtime/persistence/multi-exit/restart/seams).
- GATE PASS: MARKET-path-critical flaws 1,2,5 confirmed fixed + green.
- Added SPRINT0_FLAW_VERIFICATION.md report and _rust_kernel/.gitignore
  (excludes Rust target/ build artifacts).

LIMIT/partial-fill remain explicitly out of scope (MARKET-only bring-up).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-05-30 18:26:43 +02:00
parent 34d01fe6a4
commit 3d7b00e28d
89 changed files with 32782 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
from __future__ import annotations
from uuid import uuid4
import os
import unittest
from unittest.mock import patch
from prod.clean_arch.dita_v2 import (
DITAv2LauncherBundle,
LauncherVenueMode,
LauncherZincMode,
KernelControlSnapshot,
MockVenueAdapter,
build_launcher_bundle,
)
from prod.bingx.enums import BingxEnvironment
from prod.clean_arch.dita_v2.launcher import _maybe_close
from prod.clean_arch.dita_v2.launcher import build_bingx_exec_client_config
class DummyCloseable:
def __init__(self) -> None:
self.closed = False
def close(self) -> None:
self.closed = True
class DummyControlPlane:
def __init__(self) -> None:
self.snapshot = KernelControlSnapshot()
def read(self) -> KernelControlSnapshot:
return self.snapshot
def close(self) -> None:
pass
class DummyZincPlane:
def __init__(self) -> None:
self.control_updates: list[KernelControlSnapshot] = []
self.slot_writes: list[object] = []
def update_control(self, snapshot: KernelControlSnapshot) -> None:
self.control_updates.append(snapshot)
def write_slot(self, slot: object) -> None:
self.slot_writes.append(slot)
class TestDITAv2Launcher(unittest.TestCase):
def test_build_launcher_bundle_defaults_to_mock_and_in_memory(self) -> None:
bundle = build_launcher_bundle(prefix=f"dita_v2_{uuid4().hex}")
try:
self.assertIsInstance(bundle, DITAv2LauncherBundle)
self.assertIsInstance(bundle.venue, MockVenueAdapter)
self.assertEqual(bundle.kernel.max_slots, 10)
self.assertEqual(bundle.kernel.control.mode.value, "NORMAL")
finally:
bundle.close()
def test_build_launcher_bundle_can_select_real_components_via_env(self) -> None:
prefix = f"dita_v2_{uuid4().hex}"
dummy_control = DummyControlPlane()
dummy_zinc = DummyZincPlane()
with patch("prod.clean_arch.dita_v2.launcher.build_control_plane", return_value=dummy_control), patch(
"prod.clean_arch.dita_v2.launcher._build_zinc_plane", return_value=dummy_zinc
):
bundle = build_launcher_bundle(
prefix=prefix,
venue_mode=LauncherVenueMode.BINGX,
zinc_mode=LauncherZincMode.REAL,
bingx_backend=object(),
)
try:
self.assertIs(bundle.control_plane, dummy_control)
self.assertIs(bundle.zinc_plane, dummy_zinc)
self.assertEqual(bundle.venue.__class__.__name__, "BingxVenueAdapter")
finally:
bundle.close()
def test_build_launcher_bundle_respects_explicit_modes(self) -> None:
prefix = f"dita_v2_{uuid4().hex}"
bundle = build_launcher_bundle(
prefix=prefix,
venue_mode=LauncherVenueMode.MOCK,
zinc_mode=LauncherZincMode.IN_MEMORY,
)
try:
self.assertIsInstance(bundle.venue, MockVenueAdapter)
self.assertEqual(bundle.kernel.max_slots, 10)
finally:
bundle.close()
def test_bingx_exec_client_config_uses_standard_testnet_credentials(self) -> None:
with patch.dict(
os.environ,
{
"BINGX_API_KEY": "test-api-key",
"BINGX_SECRET_KEY": "test-secret-key",
"DOLPHIN_BINGX_ENV": "VST",
"DOLPHIN_BINGX_ALLOW_MAINNET": "0",
"DOLPHIN_BINGX_RECV_WINDOW_MS": "60000",
"DOLPHIN_BINGX_DEFAULT_LEVERAGE": "1",
"DOLPHIN_BINGX_EXCHANGE_LEVERAGE_CAP": "3",
},
clear=False,
):
cfg = build_bingx_exec_client_config()
self.assertEqual(cfg.api_key, "test-api-key")
self.assertEqual(cfg.secret_key, "test-secret-key")
self.assertIs(cfg.environment, BingxEnvironment.VST)
self.assertFalse(cfg.allow_mainnet)
self.assertEqual(cfg.recv_window_ms, 60000)
self.assertEqual(cfg.default_leverage, 1)
self.assertEqual(cfg.exchange_leverage_cap, 3)
def test_maybe_close_handles_closeable_objects(self) -> None:
dummy = DummyCloseable()
_maybe_close(dummy)
self.assertTrue(dummy.closed)
if __name__ == "__main__":
unittest.main()