feat: add 'health' alias for 'health-check' command (fixes #136)

- Register 'health' as an alias for 'health-check' to support both command names
- Update documentation to use canonical 'health-check' with notes about 'health' alias
- Add tests to verify both commands work correctly

This ensures backward compatibility for users who expect 'aiui health' to work
while maintaining 'health-check' as the canonical command name.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
This commit is contained in:
MervinPraisonandClaude committed 2026-06-23 09:47:46 +00:00
1 parent 6b565c7210
commit 1e81b32f1d
5 files changed
+130 -7

No files matched your search

+3 -3
View File
@@ -163,10 +163,10 @@ HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
```bash
# Quick health check
aiui health --server http://localhost:8082
aiui health-check --server http://localhost:8082
# Detailed per-feature health
aiui health --server http://localhost:8082 --detailed
# Detailed per-feature health
aiui health-check --server http://localhost:8082 --detailed
# Full diagnostic (7 checks)
aiui doctor --server http://localhost:8082
+5 -2
View File
@@ -276,10 +276,13 @@ aiui features list # List all registered features
aiui features status # Feature health summary
```
### `aiui health`
### `aiui health-check`
Check server health. Can also be invoked as `aiui health` for convenience.
```bash
aiui health [--detailed] # Check server health
aiui health-check [--detailed] # Check server health
aiui health [--detailed] # Alias for health-check
```
### `aiui session-ext`
+1 -1
View File
@@ -101,6 +101,6 @@ If something isn't working:
```bash
aiui doctor # Check server health
aiui health --detailed # Detailed health check
aiui health-check --detailed # Detailed health check (alias: aiui health)
aiui test all # Run all integration tests
```
+21 -1
View File
@@ -1799,7 +1799,7 @@ def sessions_messages(
# ---------------------------------------------------------------------------
# Subcommand: health
# ---------------------------------------------------------------------------
@app.command()
@app.command("health-check")
def health_check(
server: str = typer.Option(
"http://127.0.0.1:8000",
@@ -1859,6 +1859,26 @@ def health_check(
console.print(f"[yellow]⚠️[/yellow] Could not fetch feature health: {e}")
# Register "health" as an alias for health-check (backward compatibility)
@app.command("health")
def health(
server: str = typer.Option(
"http://127.0.0.1:8000",
"--server",
"-s",
help="Server URL",
),
detailed: bool = typer.Option(
False,
"--detailed",
"-d",
help="Show per-feature health",
),
) -> None:
"""Check server health (alias for health-check)."""
health_check(server=server, detailed=detailed)
# ---------------------------------------------------------------------------
# Subcommands: provider
# ---------------------------------------------------------------------------
+100
View File
@@ -0,0 +1,100 @@
"""Test that both health-check and health commands work."""
import json
from unittest.mock import MagicMock, patch
from typer.testing import CliRunner
from praisonaiui.cli import app
runner = CliRunner()
def test_health_check_command_exists():
"""Test that health-check command is registered."""
result = runner.invoke(app, ["health-check", "--help"])
assert result.exit_code == 0
assert "Check server health" in result.stdout
def test_health_alias_exists():
"""Test that health alias is registered."""
result = runner.invoke(app, ["health", "--help"])
assert result.exit_code == 0
assert "Check server health" in result.stdout
@patch("urllib.request.urlopen")
def test_health_check_command_works(mock_urlopen):
"""Test that health-check command works correctly."""
mock_response = MagicMock()
mock_response.read.return_value = json.dumps({
"status": "healthy",
"timestamp": "2026-06-23T12:00:00"
}).encode()
mock_response.__enter__.return_value = mock_response
mock_response.__exit__.return_value = None
mock_urlopen.return_value = mock_response
result = runner.invoke(app, ["health-check", "--server", "http://127.0.0.1:8000"])
assert result.exit_code == 0
assert "healthy" in result.stdout.lower()
@patch("urllib.request.urlopen")
def test_health_alias_works(mock_urlopen):
"""Test that health alias works correctly."""
mock_response = MagicMock()
mock_response.read.return_value = json.dumps({
"status": "healthy",
"timestamp": "2026-06-23T12:00:00"
}).encode()
mock_response.__enter__.return_value = mock_response
mock_response.__exit__.return_value = None
mock_urlopen.return_value = mock_response
result = runner.invoke(app, ["health", "--server", "http://127.0.0.1:8000"])
assert result.exit_code == 0
assert "healthy" in result.stdout.lower()
@patch("urllib.request.urlopen")
@patch("praisonaiui.cli._api_get")
def test_health_detailed_works(mock_api_get, mock_urlopen):
"""Test that both commands work with --detailed flag."""
# Mock health check response
mock_response = MagicMock()
mock_response.read.return_value = json.dumps({
"status": "healthy",
"timestamp": "2026-06-23T12:00:00"
}).encode()
mock_response.__enter__.return_value = mock_response
mock_response.__exit__.return_value = None
mock_urlopen.return_value = mock_response
# Mock features response
mock_api_get.return_value = {
"features": [
{"name": "test_feature", "health": {"healthy": True, "detail": "ok"}}
]
}
# Test health-check with --detailed
result1 = runner.invoke(app, ["health-check", "--server", "http://127.0.0.1:8000", "--detailed"])
assert result1.exit_code == 0
assert "healthy" in result1.stdout.lower()
assert "test_feature" in result1.stdout
# Test health alias with --detailed
result2 = runner.invoke(app, ["health", "--server", "http://127.0.0.1:8000", "--detailed"])
assert result2.exit_code == 0
assert "healthy" in result2.stdout.lower()
assert "test_feature" in result2.stdout
def test_help_shows_both_commands():
"""Test that main help shows both health commands."""
result = runner.invoke(app, ["--help"])
assert result.exit_code == 0
# At least one health-related command should be shown
assert "health" in result.stdout.lower()