oclaw/tests/test_bootstrap_env.py
oliver 420abac9f1 refactor: root-package imports (svc/runtime/interfaces) and fix PYTHONPATH
- Rename platform/ to svc/ to avoid shadowing stdlib platform.
- Replace from oclaw.* with from svc/runtime/interfaces; update -m CLI paths.
- tests/conftest: prepend repo root to sys.path (no parent-folder package name).
- CI: paths and offline_eval script under repo root.
- Ops scripts: PYTHONPATH must be repo root for python -m runtime.* (fixes gateway/WhatsApp sidecar startup).
- Fix default oclaw.json path in tabular/file attachment limits; stabilize attachment test config.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-13 14:51:17 +08:00

48 lines
1.5 KiB
Python

from __future__ import annotations
import os
from pathlib import Path
import pytest
from svc.config import bootstrap_env as be
@pytest.fixture(autouse=True)
def _reset_bootstrap_flag():
be._LOADED = False
yield
be._LOADED = False
def test_load_system_env_reads_only_local_system_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(be, "_project_root", lambda: tmp_path)
loc = tmp_path / "_local"
loc.mkdir(parents=True, exist_ok=True)
(loc / "system.env").write_text("X=only_file\nY=z\n", encoding="utf-8")
monkeypatch.delenv("X", raising=False)
monkeypatch.delenv("Y", raising=False)
loaded = be.load_system_env(force=True)
assert len(loaded) == 1
assert os.environ["X"] == "only_file"
assert os.environ["Y"] == "z"
def test_load_system_env_does_not_override_process_env(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(be, "_project_root", lambda: tmp_path)
loc = tmp_path / "_local"
loc.mkdir(parents=True, exist_ok=True)
(loc / "system.env").write_text("X=from_file\n", encoding="utf-8")
monkeypatch.setenv("X", "from_shell")
be.load_system_env(force=True)
assert os.environ["X"] == "from_shell"
def test_load_system_env_missing_file_noop(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(be, "_project_root", lambda: tmp_path)
(tmp_path / "_local").mkdir(parents=True, exist_ok=True)
loaded = be.load_system_env(force=True)
assert loaded == []