-
Notifications
You must be signed in to change notification settings - Fork 1
fix: harden IBKR runtime against historical failures #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/usr/bin/env python3 | ||
| """Import the production WSGI app with an inert IBKR configuration. | ||
|
|
||
| This check performs no network or broker operations. It catches dependency API | ||
| drift, module import failures, and Flask route registration conflicts before a | ||
| container can be deployed. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import json | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
| if str(ROOT) not in sys.path: | ||
| sys.path.insert(0, str(ROOT)) | ||
|
|
||
|
|
||
| def _install_smoke_environment() -> None: | ||
| account_group = "startup-smoke" | ||
| os.environ["ACCOUNT_GROUP"] = account_group | ||
| os.environ["IB_ACCOUNT_GROUP_CONFIG_JSON"] = json.dumps( | ||
| { | ||
| "groups": { | ||
| account_group: { | ||
| "ib_gateway_instance_name": "127.0.0.1", | ||
| "ib_gateway_mode": "paper", | ||
| "ib_client_id": 1, | ||
| "account_ids": ["DU000000"], | ||
| } | ||
| } | ||
| }, | ||
| separators=(",", ":"), | ||
| ) | ||
| os.environ["IB_ACCOUNT_GROUP_CONFIG_SECRET_NAME"] = "" | ||
| os.environ["RUNTIME_TARGET_JSON"] = json.dumps( | ||
| { | ||
| "platform_id": "ibkr", | ||
| "strategy_profile": "global_etf_rotation", | ||
| "dry_run_only": True, | ||
| "execution_mode": "paper", | ||
| "account_scope": account_group, | ||
| }, | ||
| separators=(",", ":"), | ||
| ) | ||
|
|
||
|
|
||
| def validate_startup() -> None: | ||
| _install_smoke_environment() | ||
|
|
||
| import main | ||
|
|
||
| routes = { | ||
| rule.rule: set(rule.methods) - {"HEAD", "OPTIONS"} | ||
| for rule in main.app.url_map.iter_rules() | ||
| } | ||
| required_routes = { | ||
| "/health": {"GET"}, | ||
| "/run": {"GET", "POST"}, | ||
| "/dry-run": {"GET", "POST"}, | ||
| "/probe": {"GET", "POST"}, | ||
| "/monitor-dispatch": {"GET", "POST"}, | ||
| } | ||
| missing_or_invalid = { | ||
| path: {"expected": sorted(methods), "actual": sorted(routes.get(path, set()))} | ||
| for path, methods in required_routes.items() | ||
| if routes.get(path) != methods | ||
| } | ||
| if missing_or_invalid: | ||
| raise RuntimeError(f"Cloud Run route contract is invalid: {missing_or_invalid}") | ||
|
|
||
| print(f"Cloud Run startup validation passed: routes={len(routes)}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| validate_startup() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
|
|
||
| def test_production_startup_validation_is_a_ci_and_image_build_gate(): | ||
| command = "python scripts/validate_cloud_run_startup.py" | ||
| dockerfile = (ROOT / "Dockerfile").read_text() | ||
| ci_workflow = (ROOT / ".github" / "workflows" / "ci.yml").read_text() | ||
|
|
||
| assert command in dockerfile | ||
| assert "Validate production Cloud Run startup" in ci_workflow | ||
| assert f"uv run --no-sync {command}" in ci_workflow |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.