Files
wehub-resource-sync 4b6817381b
Benchmark image — build + push to ECR (any adapter) / build + push (push) Waiting to run
CI / quality (ubuntu-latest) (push) Waiting to run
CI / test (tools-runtime) (push) Waiting to run
CI / test (e2e-general) (push) Waiting to run
CI / test (cli-runtime) (push) Waiting to run
CI / test (e2e-provider-and-openclaw) (push) Waiting to run
CI / test (integrations-and-misc) (push) Waiting to run
CI / coverage-report (push) Blocked by required conditions
CI / test-kubernetes (push) Waiting to run
CI / should-run-thorough (push) Waiting to run
CI / test-thorough (cloudwatch-demo) (push) Blocked by required conditions
CI / test-thorough (flink-ecs) (push) Blocked by required conditions
CI / test-thorough (upstream-lambda) (push) Blocked by required conditions
CI / test-thorough (prefect-ecs-fargate) (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Blocked by required conditions
Release / publish-release (push) Blocked by required conditions
Release / publish-main-release (push) Blocked by required conditions
Release / prepare (push) Waiting to run
Release / verify (push) Blocked by required conditions
Release / build-python-dist (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Blocked by required conditions
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Blocked by required conditions
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Waiting to run
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Waiting to run
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

158 lines
5.7 KiB
Python

from __future__ import annotations
from pathlib import Path
import yaml
from click.testing import CliRunner
from surfaces.cli.__main__ import cli
def _patch_config_home(monkeypatch, tmp_path: Path) -> Path:
opensre_home = tmp_path / ".opensre"
monkeypatch.setattr("config.constants.OPENSRE_HOME_DIR", opensre_home)
monkeypatch.setattr("surfaces.cli.commands.config.OPENSRE_HOME_DIR", opensre_home)
return opensre_home
def test_config_show_inspects_local_file_not_env(monkeypatch, tmp_path: Path) -> None:
opensre_home = _patch_config_home(monkeypatch, tmp_path)
config_path = opensre_home / "config.yml"
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text(
yaml.safe_dump({"interactive": {"enabled": False, "layout": "classic"}}),
encoding="utf-8",
)
monkeypatch.setenv("OPENSRE_INTERACTIVE", "1")
monkeypatch.setenv("OPENSRE_LAYOUT", "pinned")
runner = CliRunner()
result = runner.invoke(cli, ["config", "show"])
assert result.exit_code == 0
assert "on-disk values" in result.output
assert "interactive:" in result.output
assert "enabled: false" in result.output
assert "layout: classic" in result.output
assert "pinned" not in result.output
def test_config_set_round_trips_layout(monkeypatch, tmp_path: Path) -> None:
opensre_home = _patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
set_result = runner.invoke(cli, ["config", "set", "interactive.layout", "pinned"])
assert set_result.exit_code == 0
assert "interactive.layout = pinned" in set_result.output
config_path = opensre_home / "config.yml"
assert config_path.exists()
data = yaml.safe_load(config_path.read_text(encoding="utf-8"))
assert data["interactive"]["layout"] == "pinned"
show_result = runner.invoke(cli, ["config", "show"])
assert show_result.exit_code == 0
assert "layout: pinned" in show_result.output
def test_config_set_round_trips_enabled(monkeypatch, tmp_path: Path) -> None:
opensre_home = _patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
set_result = runner.invoke(cli, ["config", "set", "interactive.enabled", "false"])
assert set_result.exit_code == 0
assert "interactive.enabled = False" in set_result.output
config_path = opensre_home / "config.yml"
assert config_path.exists()
data = yaml.safe_load(config_path.read_text(encoding="utf-8"))
assert data["interactive"]["enabled"] is False
def test_config_set_invalid_enabled_value_returns_helpful_error(
monkeypatch, tmp_path: Path
) -> None:
_patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
result = runner.invoke(cli, ["config", "set", "interactive.enabled", "maybe"])
assert result.exit_code != 0
assert "Invalid value for interactive.enabled" in result.output
def test_config_set_invalid_layout_value_returns_helpful_error(monkeypatch, tmp_path: Path) -> None:
_patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
result = runner.invoke(cli, ["config", "set", "interactive.layout", "fullscreen"])
assert result.exit_code != 0
assert "Invalid value for interactive.layout" in result.output
def test_config_set_malformed_file_preserves_contents(monkeypatch, tmp_path: Path) -> None:
opensre_home = _patch_config_home(monkeypatch, tmp_path)
config_path = opensre_home / "config.yml"
config_path.parent.mkdir(parents=True, exist_ok=True)
# Unclosed flow sequence — PyYAML rejects this reliably (unlike "::: ..." edge cases).
original_text = "key: [\n"
config_path.write_text(original_text, encoding="utf-8")
runner = CliRunner()
result = runner.invoke(cli, ["config", "set", "interactive.layout", "pinned"])
assert result.exit_code != 0
assert "Could not parse local config file" in result.output
assert config_path.read_text(encoding="utf-8") == original_text
def test_config_show_handles_empty_file(monkeypatch, tmp_path: Path) -> None:
opensre_home = _patch_config_home(monkeypatch, tmp_path)
config_path = opensre_home / "config.yml"
config_path.parent.mkdir(parents=True, exist_ok=True)
config_path.write_text("", encoding="utf-8")
runner = CliRunner()
result = runner.invoke(cli, ["config", "show"])
assert result.exit_code == 0
assert "on-disk values" in result.output
assert "{}" in result.output
def test_config_set_unknown_key_returns_helpful_error(monkeypatch, tmp_path: Path) -> None:
_patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
result = runner.invoke(cli, ["config", "set", "foo.bar", "value"])
assert result.exit_code != 0
assert "Unknown config key 'foo.bar'" in result.output
assert "interactive.enabled" in result.output
assert "interactive.layout" in result.output
assert "interactive.theme" in result.output
def test_config_set_round_trips_theme(monkeypatch, tmp_path: Path) -> None:
opensre_home = _patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
set_result = runner.invoke(cli, ["config", "set", "interactive.theme", "blue"])
assert set_result.exit_code == 0
assert "interactive.theme = blue" in set_result.output
config_path = opensre_home / "config.yml"
data = yaml.safe_load(config_path.read_text(encoding="utf-8"))
assert data["interactive"]["theme"] == "blue"
def test_config_set_invalid_theme_value_returns_helpful_error(monkeypatch, tmp_path: Path) -> None:
_patch_config_home(monkeypatch, tmp_path)
runner = CliRunner()
result = runner.invoke(cli, ["config", "set", "interactive.theme", "chartreuse"])
assert result.exit_code != 0
assert "Invalid value for interactive.theme" in result.output