forked from luopingyi/xc_agent_platform_demo
- Overlay ModelHub XC Phase1 (health/status, STRATEGY_ID gate, dry-run) - Dockerfile CMD -> python -m src.server; FROM stays platform TCR base - Remove demo main.py and requirements.txt (stdlib only) - Add tests/, scripts/, docs/, Makefile, config/examples (no secrets)
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
"""Missing STRATEGY_ID must cause startup failure (exit non-zero)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest import mock
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
|
|
class TestStrategyStartup(unittest.TestCase):
|
|
def test_missing_strategy_id_exits_nonzero(self) -> None:
|
|
env = os.environ.copy()
|
|
env["STRATEGY_ID"] = ""
|
|
env["PORT"] = "19081"
|
|
env["HOST"] = "127.0.0.1"
|
|
proc = subprocess.run(
|
|
[sys.executable, "-m", "src.server"],
|
|
cwd=str(ROOT),
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10,
|
|
)
|
|
self.assertNotEqual(proc.returncode, 0)
|
|
self.assertIn("STRATEGY_ID", proc.stderr)
|
|
|
|
def test_whitespace_strategy_id_exits_nonzero(self) -> None:
|
|
env = os.environ.copy()
|
|
env["STRATEGY_ID"] = " "
|
|
env["PORT"] = "19082"
|
|
env["HOST"] = "127.0.0.1"
|
|
proc = subprocess.run(
|
|
[sys.executable, "-m", "src.server"],
|
|
cwd=str(ROOT),
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=10,
|
|
)
|
|
self.assertNotEqual(proc.returncode, 0)
|
|
|
|
def test_require_strategy_id_helper(self) -> None:
|
|
from src.strategy import require_strategy_id
|
|
|
|
with self.assertRaises(SystemExit) as ctx:
|
|
with mock.patch.dict(os.environ, {"STRATEGY_ID": ""}, clear=False):
|
|
require_strategy_id()
|
|
self.assertNotEqual(ctx.exception.code, 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|