Skip to content

Commit 4d88a0e

Browse files
Pigbibicodex
andcommitted
fix: bind LongBridge paper commands to runtime scope
Co-Authored-By: Codex <noreply@openai.com>
1 parent 911b2fa commit 4d88a0e

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

application/paper_execution_command_consumer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def consume_due_paper_execution_commands(
213213
market_data_port: Any,
214214
runtime_release_receipt: Mapping[str, Any] | None,
215215
expected_strategy_release: StrategyReleaseIdentity | Mapping[str, object] | None,
216+
expected_command_binding: Mapping[str, object] | None,
216217
) -> dict[str, object]:
217218
"""Claim and simulate due paper commands through the shared lifecycle."""
218219

@@ -227,4 +228,5 @@ def consume_due_paper_execution_commands(
227228
),
228229
runtime_release_receipt=runtime_release_receipt,
229230
expected_strategy_release=expected_strategy_release,
231+
expected_command_binding=expected_command_binding,
230232
)

main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,11 @@ def run_paper_execution_command_consumer() -> bool:
10271027
market_data_port=composer.broker_adapters.build_market_data_port(quote_context),
10281028
runtime_release_receipt=config.runtime_release_receipt,
10291029
expected_strategy_release=config.expected_strategy_release,
1030+
expected_command_binding={
1031+
"platform": "longbridge",
1032+
"account_scope": str(config.execution_state_account_scope or "unknown"),
1033+
"strategy_profile": str(config.strategy_profile or "unknown"),
1034+
},
10301035
)
10311036
report_status = "ok" if result.get("status") == "ok" else "skipped"
10321037
finalize_runtime_report(

tests/test_paper_execution_command_consumer.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ def _portfolio(*, include_unmanaged: bool = False) -> PortfolioSnapshot:
104104
)
105105

106106

107+
def _command_binding() -> dict[str, str]:
108+
return {
109+
"platform": "longbridge",
110+
"account_scope": "paper",
111+
"strategy_profile": "soxl_soxx_trend_income",
112+
}
113+
114+
107115
def test_paper_consumer_simulates_reconciled_orders_and_never_calls_an_execution_port(tmp_path: Path) -> None:
108116
store = ExecutionCommandStore(local_dir=tmp_path)
109117
command = _command()
@@ -118,6 +126,7 @@ def test_paper_consumer_simulates_reconciled_orders_and_never_calls_an_execution
118126
market_data_port=_MarketDataPort(),
119127
runtime_release_receipt=build_runtime_loaded_receipt(strategy_release=release),
120128
expected_strategy_release=release,
129+
expected_command_binding=_command_binding(),
121130
)
122131

123132
assert result["status"] == "ok"
@@ -169,6 +178,7 @@ def test_paper_consumer_requires_runtime_release_before_claiming(tmp_path: Path)
169178
market_data_port=_MarketDataPort(),
170179
runtime_release_receipt=None,
171180
expected_strategy_release=_release_identity(),
181+
expected_command_binding=_command_binding(),
172182
)
173183

174184
assert result["status"] == "blocked"
@@ -190,6 +200,7 @@ def test_paper_consumer_rejects_unbound_or_unreconciled_commands(tmp_path: Path)
190200
market_data_port=_MarketDataPort(),
191201
runtime_release_receipt=build_runtime_loaded_receipt(strategy_release=release),
192202
expected_strategy_release=release,
203+
expected_command_binding=_command_binding(),
193204
)
194205

195206
assert result["commands"][0]["status"] == "rejected"
@@ -217,6 +228,7 @@ def test_paper_consumer_rejects_risk_receipt_bound_to_another_decision(tmp_path:
217228
market_data_port=_MarketDataPort(),
218229
runtime_release_receipt=build_runtime_loaded_receipt(strategy_release=release),
219230
expected_strategy_release=release,
231+
expected_command_binding=_command_binding(),
220232
)
221233

222234
assert result["commands"][0]["status"] == "rejected"

tests/test_request_handling.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,8 @@ def build_rebalance_config(self):
475475
execution_command_store="command-store",
476476
runtime_release_receipt={"attestation_state": "self_attested"},
477477
expected_strategy_release={"release_id": "release-1"},
478+
execution_state_account_scope="paper-command-verify",
479+
strategy_profile=module.STRATEGY_PROFILE,
478480
)
479481

480482
def build_reporting_adapters(self):
@@ -510,6 +512,14 @@ def fake_consume(**kwargs):
510512
self.assertEqual(observed["consumer"]["store"], "command-store")
511513
self.assertEqual(observed["consumer"]["portfolio"], "portfolio-snapshot")
512514
self.assertEqual(observed["consumer"]["market_data_port"], "market-data-port")
515+
self.assertEqual(
516+
observed["consumer"]["expected_command_binding"],
517+
{
518+
"platform": "longbridge",
519+
"account_scope": "paper-command-verify",
520+
"strategy_profile": module.STRATEGY_PROFILE,
521+
},
522+
)
513523

514524
def test_handle_probe_checks_account_snapshot_without_success_notification(self):
515525
module = load_module()

0 commit comments

Comments
 (0)