Files
crypto_monitor/tests/test_sync_force_close_policy.py
T
dekun 8d2da921ee Stop deploy from overwriting manual FORCE_CLOSE settings.
Apply force-close defaults only when keys are missing so system-settings toggles survive pull_and_restart.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-15 11:54:31 +08:00

42 lines
1.5 KiB
Python

"""FORCE_CLOSE 部署策略:只补缺失,不覆盖手调."""
import os
import tempfile
import unittest
from pathlib import Path
from unittest import mock
from scripts import sync_common_trading_env as sync
class TestForceCloseFillMissing(unittest.TestCase):
def test_does_not_overwrite_existing(self):
with tempfile.TemporaryDirectory() as td:
gate = Path(td) / "crypto_monitor_gate"
gate.mkdir()
(gate / ".env").write_text(
"FORCE_CLOSE_ENABLED=false\nFORCE_CLOSE_BJ_HOUR=1\n",
encoding="utf-8",
)
with mock.patch.object(sync, "REPO", td):
changed = sync.apply_force_close_policy(dry_run=False)
self.assertFalse(changed)
text = (gate / ".env").read_text(encoding="utf-8")
self.assertIn("FORCE_CLOSE_ENABLED=false", text)
self.assertIn("FORCE_CLOSE_BJ_HOUR=1", text)
def test_fills_missing_keys(self):
with tempfile.TemporaryDirectory() as td:
gate = Path(td) / "crypto_monitor_gate"
gate.mkdir()
(gate / ".env").write_text("APP_USERNAME=x\n", encoding="utf-8")
with mock.patch.object(sync, "REPO", td):
changed = sync.apply_force_close_policy(dry_run=False)
self.assertTrue(changed)
text = (gate / ".env").read_text(encoding="utf-8")
self.assertIn("FORCE_CLOSE_ENABLED=true", text)
self.assertIn("FORCE_CLOSE_BJ_HOUR=0", text)
if __name__ == "__main__":
unittest.main()