"""Unit tests for OpenClaw CLI.""" import tempfile from pathlib import Path from typer.testing import CliRunner from openclaw.cli.main import app runner = CliRunner() class TestCLI: def test_init_creates_config(self): with tempfile.TemporaryDirectory() as tmpdir: config_path = Path(tmpdir) / "test_config.yaml" result = runner.invoke(app, ["init", "--path", str(config_path)]) assert result.exit_code == 0 assert config_path.exists() def test_init_fails_on_existing_config(self): with tempfile.TemporaryDirectory() as tmpdir: config_path = Path(tmpdir) / "test_config.yaml" runner.invoke(app, ["init", "--path", str(config_path)]) result = runner.invoke(app, ["init", "--path", str(config_path)]) assert result.exit_code == 1 def test_run(self): result = runner.invoke(app, ["run", "--mode", "simulation"]) assert result.exit_code == 0 def test_status(self): result = runner.invoke(app, ["status"]) assert result.exit_code == 0 assert "trader-001" in result.output def test_config_show(self): result = runner.invoke(app, ["config", "show"]) # May fail without config, but command should exist assert result.exit_code in [0, 1]