Task 0.5 of clean-analyst-bootstrap. Greenfield rewrite — no fallback, no aliases. Existing dev environments lose their cached PAT and must re-authenticate. Env var renames (hard cutover): - DA_CONFIG_DIR -> AGNES_CONFIG_DIR - DA_SERVER -> AGNES_SERVER - DA_SERVER_URL -> AGNES_SERVER_URL (test-only stale ref, not in spec) - DA_NO_UPDATE_CHECK -> AGNES_NO_UPDATE_CHECK - DA_LOCAL_DIR -> AGNES_LOCAL_DIR - DA_TOKEN -> AGNES_TOKEN - DA_STREAM_RETRIES -> AGNES_STREAM_RETRIES Config dir rename: ~/.config/da/ -> ~/.config/agnes/ (across code, comments, docstrings, error messages, install templates, dev scripts). Stale `da X` references in CLI source (and adjacent app/, tests/): swept docstrings, comments, help text, and error messages where the verb survives the rewrite (init, pull, push, catalog, status, diagnose, auth, admin, skills, query, schema, describe, explore, disk-info, snapshot, login, logout, whoami, server, setup) and replaced `da X` with `agnes X`. Intentionally kept `da sync`, `da fetch`, `da analyst`, `da metrics` — those verbs are removed in later tasks; the legacy strings will be detected by `_LEGACY_STRINGS` (added in Task 2). Test fixes: - TestCLIVersion now asserts output starts with `agnes ` (was `da `). Test results: 2675 passed, 25 skipped (full pytest run, excluding 9 pre-existing test_db.py / test_user_management.py / test_e2e_extract.py / test_cli_binary_rename.py failures unrelated to this rename).
107 lines
4.1 KiB
Python
107 lines
4.1 KiB
Python
"""Tests for agnes server subcommands (delegate to subprocess)."""
|
|
|
|
import subprocess
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock, call
|
|
|
|
from typer.testing import CliRunner
|
|
from cli.main import app
|
|
|
|
runner = CliRunner()
|
|
|
|
|
|
def _subprocess_result(returncode=0):
|
|
r = MagicMock()
|
|
r.returncode = returncode
|
|
return r
|
|
|
|
|
|
class TestServerStatus:
|
|
def test_server_status_runs_docker_compose_ps(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "status"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "docker compose ps" in cmd
|
|
|
|
def test_server_status_nonzero_exit(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(1)):
|
|
result = runner.invoke(app, ["server", "status"])
|
|
assert result.exit_code != 0
|
|
|
|
|
|
class TestServerLogs:
|
|
def test_server_logs_default_service(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "logs"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "docker compose logs" in cmd
|
|
assert "app" in cmd
|
|
|
|
def test_server_logs_custom_service(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "logs", "scheduler"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "scheduler" in cmd
|
|
|
|
def test_server_logs_with_tail(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "logs", "--tail", "50"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "50" in cmd
|
|
|
|
|
|
class TestServerRestart:
|
|
def test_server_restart_default_service(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "restart"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "docker compose restart" in cmd
|
|
assert "app" in cmd
|
|
assert "Restarted" in result.output
|
|
|
|
def test_server_restart_named_service(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "restart", "scheduler"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "scheduler" in cmd
|
|
|
|
|
|
class TestServerDeploy:
|
|
def test_server_deploy_production(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "deploy"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "kamal deploy" in cmd
|
|
|
|
def test_server_deploy_staging(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "deploy", "--staging"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "staging" in cmd
|
|
|
|
|
|
class TestServerRollback:
|
|
def test_server_rollback(self):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "rollback"])
|
|
assert result.exit_code == 0
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "rollback" in cmd
|
|
|
|
|
|
class TestServerBackup:
|
|
def test_server_backup(self, tmp_path):
|
|
with patch("cli.commands.server.subprocess.run", return_value=_subprocess_result(0)) as mock_run:
|
|
result = runner.invoke(app, ["server", "backup", "--output", str(tmp_path)])
|
|
assert result.exit_code == 0
|
|
assert "Backup saved" in result.output
|
|
cmd = mock_run.call_args[0][0]
|
|
assert "docker compose cp" in cmd
|