diff --git a/application/runtime_composer.py b/application/runtime_composer.py index ca280cf..a8fb059 100644 --- a/application/runtime_composer.py +++ b/application/runtime_composer.py @@ -84,7 +84,11 @@ def build_reporting_adapters(self): service_name=self.service_name, strategy_profile=self.strategy_profile, runtime_target=self.runtime_target, - account_scope=self.account_group, + account_scope=( + self.runtime_target.account_scope + if self.runtime_target and self.runtime_target.account_scope + else self.account_group + ), account_group=self.account_group, project_id=self.project_id, instance_name=self.instance_name, diff --git a/runtime_config_support.py b/runtime_config_support.py index 7fb8281..54d4980 100644 --- a/runtime_config_support.py +++ b/runtime_config_support.py @@ -505,7 +505,11 @@ def load_platform_runtime_settings( ) ), account_group=account_group, - service_name=group_config.service_name, + service_name=first_non_empty( + os.getenv("K_SERVICE"), + runtime_target.service_name, + group_config.service_name, + ), account_ids=group_config.account_ids, tg_token=os.getenv("TELEGRAM_TOKEN"), tg_chat_id=os.getenv("QSL_GLOBAL_TELEGRAM_CHAT_ID") or os.getenv("GLOBAL_TELEGRAM_CHAT_ID"), diff --git a/tests/test_runtime_composer.py b/tests/test_runtime_composer.py index 6c4725f..251e383 100644 --- a/tests/test_runtime_composer.py +++ b/tests/test_runtime_composer.py @@ -26,7 +26,7 @@ def fake_reporting_builder(**kwargs): service_name="interactive-brokers-platform", strategy_profile="global_etf_rotation", strategy_domain="us_equity", - account_group="default", + account_group="shared-live", project_id="project-1", instance_name="ib-gateway", account_ids=("U123456",), @@ -44,7 +44,7 @@ def fake_reporting_builder(**kwargs): platform_id="interactive_brokers", strategy_profile="global_etf_rotation", dry_run_only=True, - account_scope="default", + account_scope="us-combo-shadow", service_name="interactive-brokers-platform", ), strategy_config_source="env", @@ -87,7 +87,8 @@ def fake_reporting_builder(**kwargs): assert notification_adapters.notification_port == "notification-port" assert observed["notification_builder"]["send_message"] - assert observed["reporting_builder"]["runtime_assembly"].account_scope == "default" + assert observed["reporting_builder"]["runtime_assembly"].account_scope == "us-combo-shadow" + assert observed["reporting_builder"]["runtime_assembly"].account_group == "shared-live" assert observed["reporting_builder"]["managed_symbols"] == ("AAA", "BIL") assert observed["reporting_builder"]["signal_effective_after_trading_days"] == 1 assert observed["reporting_builder"]["runtime_assembly"].runtime_target.platform_id == "interactive_brokers" diff --git a/tests/test_runtime_config_support.py b/tests/test_runtime_config_support.py index a2c3491..c9c61a5 100644 --- a/tests/test_runtime_config_support.py +++ b/tests/test_runtime_config_support.py @@ -354,6 +354,32 @@ def test_load_platform_runtime_settings_supports_explicit_group_config_values(mo assert settings.notify_lang == "zh" +def test_runtime_target_service_name_overrides_shared_account_group_service(monkeypatch): + monkeypatch.setenv( + "RUNTIME_TARGET_JSON", + runtime_target_json( + "us_equity_combo_leveraged", + dry_run_only=True, + deployment_selector="us-combo-shadow", + account_scope="us-combo-shadow", + service_name="interactive-brokers-us-combo-shadow-service", + ), + ) + monkeypatch.setenv("ACCOUNT_GROUP", "shared-live") + monkeypatch.setenv( + "IB_ACCOUNT_GROUP_CONFIG_JSON", + '{"groups":{"shared-live":{"ib_gateway_instance_name":"ib-gateway",' + '"ib_gateway_mode":"live","ib_client_id":1,' + '"service_name":"interactive-brokers-quant-live-u18336562-service",' + '"account_ids":["U123456"]}}}', + ) + + settings = load_platform_runtime_settings(project_id_resolver=lambda: "project-1") + + assert settings.account_group == "shared-live" + assert settings.service_name == "interactive-brokers-us-combo-shadow-service" + + def test_load_platform_runtime_settings_derives_hk_market_from_account_group(monkeypatch): monkeypatch.setenv("RUNTIME_TARGET_JSON", runtime_target_json(SAMPLE_STRATEGY_PROFILE)) monkeypatch.setenv("ACCOUNT_GROUP", "hk-live")