Files
siloqy/prod/tests/test_pink_ditav2_rate_limit_contract.py
Codex 3d7b00e28d 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>
2026-05-30 18:26:43 +02:00

72 lines
2.1 KiB
Python

"""Rate-limit classification + downstream emission tests for PINK + DITAv2."""
from __future__ import annotations
from datetime import datetime, timezone
import unittest
from prod.clean_arch.dita_v2 import (
ControlUpdate,
ExecutionKernel,
InMemoryControlPlane,
InMemoryZincPlane,
KernelCommandType,
KernelDiagnosticCode,
KernelIntent,
KernelMode,
MockVenueAdapter,
MockVenueScenario,
TradeSide,
)
class TestRateLimitContract(unittest.TestCase):
"""Verify the kernel handles venue rejections without corrupting state."""
def setUp(self):
self.control = InMemoryControlPlane()
self.control.update(ControlUpdate(
mode=KernelMode.DEBUG, trace_transitions=True,
))
self.venue = MockVenueAdapter(
MockVenueScenario(
reject_entries=True,
reject_exits=False,
partial_fill_ratio=0.0,
cancel_reject=False,
)
)
self.kernel = ExecutionKernel(
max_slots=1,
control_plane=self.control,
venue=self.venue,
zinc_plane=InMemoryZincPlane(),
)
def _make_intent(self, action: KernelCommandType = KernelCommandType.ENTER) -> KernelIntent:
return KernelIntent(
timestamp=datetime.now(timezone.utc),
intent_id="rate-test-001",
trade_id="rate-trade-001",
slot_id=0,
asset="BTCUSDT",
side=TradeSide.SHORT,
action=action,
reference_price=65000.0,
target_size=0.01,
leverage=2.0,
reason="rate_limit_test",
)
def test_kernel_state_unaffected_by_rejection(self):
"""Slot returns to free/IDLE after venue rejects entry."""
intent = self._make_intent(KernelCommandType.ENTER)
self.kernel.process_intent(intent)
slot = self.kernel.slot(0)
self.assertTrue(slot.is_free(),
f"Slot should be free after reject, got {slot.fsm_state}")
if __name__ == "__main__":
unittest.main()