"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix: support Web UI settings persistence on Windows
QinRXbaaf07d1eeb7
diff --git a/agent/src/api/helpers.py b/agent/src/api/helpers.pyindex 3dfc16c12..fbec14dd0 100644--- a/agent/src/api/helpers.py+++ b/agent/src/api/helpers.py@@ -97,9 +97,19 @@ def _atomic_write_secret(path: Path, content: str) -> None:returntry:os.write(fd, data)- os.fchmod(fd, 0o600)+ # ``os.fchmod`` is unavailable on Windows. Keep descriptor-level+ # permission hardening on platforms that support it, then use the+ # portable path-based best effort after the descriptor is closed.+ if hasattr(os, "fchmod"):+ os.fchmod(fd, 0o600)finally:os.close(fd)+ try:+ os.chmod(tmp, 0o600)+ except OSError:+ # Windows ACLs govern effective access and chmod may be unsupported+ # or map only to the read-only flag.+ passtry:os.replace(tmp, path)except BaseException:diff --git a/agent/tests/test_api_infrastructure.py b/agent/tests/test_api_infrastructure.pyindex 920f3e3e7..f1fdf87aa 100644--- a/agent/tests/test_api_infrastructure.py+++ b/agent/tests/test_api_infrastructure.py@@ -2,6 +2,7 @@from __future__ import annotations+import osimport pytestimport api_server@@ -241,8 +242,9 @@ def test_write_env_values_creates_private_parent_directory(tmp_path) -> None:helpers._write_env_values(target, {"KEY": "value"})assert helpers._read_env_values(target) == {"KEY": "value"}- assert (target.parent.stat().st_mode & 0o777) == 0o700- assert (target.stat().st_mode & 0o777) == 0o600+ if os.name != "nt":+ assert (target.parent.stat().st_mode & 0o777) == 0o700+ assert (target.stat().st_mode & 0o777) == 0o600def test_strip_env_value_quotes():diff --git a/agent/tests/test_settings_api.py b/agent/tests/test_settings_api.pyindex a2c5bb9d9..d928b14a9 100644--- a/agent/tests/test_settings_api.py+++ b/agent/tests/test_settings_api.py@@ -2,6 +2,7 @@from __future__ import annotations+import osfrom pathlib import Pathimport pytest@@ -376,7 +377,8 @@ def test_update_settings_writes_env_file_with_0600_mode(assert response.status_code == 200mode = (tmp_path / ".env").stat().st_mode & 0o777- assert mode == 0o600+ if os.name != "nt":+ assert mode == 0o600def test_atomic_write_secret_is_crash_safe(@@ -411,4 +413,19 @@ def test_atomic_write_secret_creates_0600_file(tmp_path: Path) -> None:helpers._atomic_write_secret(target, "KEY=value\n")assert target.read_text(encoding="utf-8") == "KEY=value\n"- assert (target.stat().st_mode & 0o777) == 0o600+ if os.name != "nt":+ assert (target.stat().st_mode & 0o777) == 0o600+++def test_atomic_write_secret_supports_platforms_without_fchmod(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch,+) -> None:+ """Windows must be able to persist Web UI settings without ``os.fchmod``."""+ from src.api import helpers++ monkeypatch.delattr(helpers.os, "fchmod", raising=False)+ target = tmp_path / ".env"++ helpers._atomic_write_secret(target, "KEY=value\n")++ assert target.read_text(encoding="utf-8") == "KEY=value\n"