Skip to content

Commit fce8ae8

Browse files
authored
Allow expected plugin schema versions in runtime settings (#4)
1 parent e09ffcd commit fce8ae8

6 files changed

Lines changed: 30 additions & 3 deletions

File tree

examples/targets/ibkr/default.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"plugin": "example_notification_plugin",
3636
"signal_path": "gs://example-bucket/strategy-artifacts/example_strategy_profile/plugins/example_notification_plugin/latest_signal.json",
3737
"enabled": true,
38-
"expected_mode": "shadow"
38+
"expected_mode": "shadow",
39+
"expected_schema_version": "example_notification_plugin.v1"
3940
}
4041
],
4142
"extra_variables": {}

examples/targets/longbridge/sg.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"plugin": "example_notification_plugin",
3737
"signal_path": "gs://example-bucket/strategy-artifacts/example_strategy_profile/plugins/example_notification_plugin/latest_signal.json",
3838
"enabled": true,
39-
"expected_mode": "shadow"
39+
"expected_mode": "shadow",
40+
"expected_schema_version": "example_notification_plugin.v1"
4041
}
4142
],
4243
"extra_variables": {

examples/targets/schwab/live.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"plugin": "example_notification_plugin",
3636
"signal_path": "gs://example-bucket/strategy-artifacts/example_strategy_profile/plugins/example_notification_plugin/latest_signal.json",
3737
"enabled": true,
38-
"expected_mode": "shadow"
38+
"expected_mode": "shadow",
39+
"expected_schema_version": "example_notification_plugin.v1"
3940
}
4041
],
4142
"extra_variables": {}

schemas/runtime-target.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@
143143
},
144144
"expected_mode": {
145145
"type": "string"
146+
},
147+
"expected_schema_version": {
148+
"type": "string"
146149
}
147150
}
148151
}

scripts/runtime_settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ def validate_plugin_mounts(target: dict[str, Any], errors: list[str]) -> None:
248248
if not isinstance(mount.get("enabled"), bool):
249249
errors.append(f"plugin_mounts[{index}].enabled must be boolean")
250250

251+
expected_schema_version = mount.get("expected_schema_version")
252+
if expected_schema_version is not None and (
253+
not isinstance(expected_schema_version, str) or not expected_schema_version.strip()
254+
):
255+
errors.append(f"plugin_mounts[{index}].expected_schema_version must be a non-empty string")
256+
251257
signal_path = mount.get("signal_path")
252258
if not isinstance(signal_path, str) or not signal_path.startswith("gs://"):
253259
errors.append(f"plugin_mounts[{index}].signal_path must be a gs:// URI")

tests/test_runtime_settings.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ def test_example_targets_have_matching_plugin_mount(self):
4949
)
5050
)
5151

52+
def test_plugin_mount_schema_version_is_rendered_for_platform_parser(self):
53+
_, target = self.load_target("examples/targets/schwab/live.example.json")
54+
assignments = {item.name: item.value for item in runtime_settings.build_assignments(target)}
55+
56+
self.assertIn('"expected_schema_version":"example_notification_plugin.v1"', assignments["SCHWAB_STRATEGY_PLUGIN_MOUNTS_JSON"])
57+
58+
def test_plugin_mount_schema_version_must_be_non_empty_string(self):
59+
_, target = self.load_target("examples/targets/schwab/live.example.json")
60+
target["plugin_mounts"][0]["expected_schema_version"] = ""
61+
62+
self.assertIn(
63+
"plugin_mounts[0].expected_schema_version must be a non-empty string",
64+
runtime_settings.validate_target(target),
65+
)
66+
5267
def test_generated_variables_cannot_be_overridden(self):
5368
_, target = self.load_target("examples/targets/schwab/live.example.json")
5469
target["extra_variables"] = {"STRATEGY_PROFILE": "old_strategy"}

0 commit comments

Comments
 (0)