Files
FabledSteward/tests/plugins/docker/test_routes.py
T
bvandeusenandClaude Opus 5.5 680a6bf3b6
CI / lint (push) Successful in 3s
CI / integration (push) Successful in 57s
CI / unit (push) Failing after 1m8s
CI / publish (push) Skipped
feat(mcp): automation tools — playbooks, runs, schedules, alert actions, docker prune
MCP-6 #4970 "Automation tools: playbooks, runs, schedules, alert actions".

Viewer: list_playbooks, get_playbook (secret defaults masked), list_inventory
(variable names only), list_ansible_runs, get_ansible_run (log tail + grep),
list_schedules, wait_for_run (polls, 120s cap).

Operator: run_playbook (check mode unless check=false; a steward:confirm
playbook applies only with confirmed=true; secret variables reach the run
but are never stored, audited or returned), cancel_ansible_run, and
create/update/delete_schedule (secrets refused, check by default).

Admin: set_alert_action, and the docker plugin's prune_docker, which
previews from the disk report unless check=false (Ansible's check mode
skips the prune commands, so a check run would show nothing).

Every write is audited as "<user> via MCP" with the token id; the audit
tool's user filter includes those rows. prune_extra_vars moves to the
docker service so the page and the tool share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 08:06:15 -04:00

62 lines
2.1 KiB
Python

"""Unit tests for the docker plugin's presentation layer (no DB).
CI never renders these templates through the running app (the unit-lane app is
created with testing=True, which skips plugin loading), so a Jinja syntax error
would otherwise ship green. These tests parse every docker template and smoke
the routes module so a broken tag or import is caught in the unit lane.
"""
import pathlib
import jinja2
from plugins.docker import routes as r
_TEMPLATES = pathlib.Path(r.__file__).parent / "templates" / "docker"
def test_all_docker_templates_parse():
env = jinja2.Environment()
files = sorted(_TEMPLATES.glob("*.html"))
assert files, "no docker templates found"
for f in files:
# Raises TemplateSyntaxError on an unbalanced/typo'd tag.
env.parse(f.read_text())
def test_routes_module_exposes_new_views():
# Import-smoke + confirms the #942 view functions are defined.
for name in ("container_detail", "container_history", "swarm", "disk", "index", "rows"):
assert callable(getattr(r, name)), name
assert r.docker_bp.name == "docker"
def test_disk_prune_view_defined():
# M78 admin-gated prune action.
assert callable(r.disk_prune)
def test_container_log_views_defined():
# M79 per-container log viewer + its HTMX-polled line fragment.
assert callable(r.container_logs)
assert callable(r.container_logs_lines)
def test_human_bytes_formats_binary_units():
assert r._human_bytes(None) == "—"
assert r._human_bytes(0) == "0 B"
assert r._human_bytes(512) == "512 B"
assert r._human_bytes(1024) == "1.0 KiB"
assert r._human_bytes(1536) == "1.5 KiB"
assert r._human_bytes(1024 ** 2) == "1.0 MiB"
assert r._human_bytes(int(1.5 * 1024 ** 3)) == "1.5 GiB"
assert r._human_bytes(1024 ** 4) == "1.0 TiB"
def test_human_uptime_compact():
from datetime import datetime, timedelta, timezone
now = datetime.now(timezone.utc)
assert r._human_uptime(None) is None
assert r._human_uptime(now - timedelta(minutes=8)).endswith("m")
assert "h" in r._human_uptime(now - timedelta(hours=5, minutes=12))
assert "d" in r._human_uptime(now - timedelta(days=3, hours=4))