Files
FabledSteward/tests/plugins/docker/test_service.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

30 lines
1.2 KiB
Python

"""Unit tests for the docker plugin's shared query helpers (no DB)."""
from plugins.docker import service as svc
def test_escape_like_makes_wildcards_literal():
# A log search for "100%" or "user_id" must match those characters, not
# treat them as LIKE wildcards.
assert svc.escape_like("100%") == "100\\%"
assert svc.escape_like("user_id") == "user\\_id"
assert svc.escape_like("C:\\temp") == "C:\\\\temp"
assert svc.escape_like("plain text") == "plain text"
def test_bucket_keeps_short_series_and_averages_long_ones():
assert svc.bucket([1.0, 2.0, 3.0]) == [1.0, 2.0, 3.0]
out = svc.bucket([float(i) for i in range(400)], target=40)
assert len(out) == 40
assert out[0] == sum(range(10)) / 10
def test_prune_extra_vars_mapping():
"""The prune buttons drive one playbook via prune_target; only 'images'
widens to ALL unused images (docker image prune -a), system stays -f."""
assert svc.prune_extra_vars("containers") == {"prune_target": "containers"}
assert svc.prune_extra_vars("images") == {
"prune_target": "images", "prune_all_images": True,
}
# System prune stays conservative — no prune_all_images key.
assert svc.prune_extra_vars("system") == {"prune_target": "system"}