Files
mcphub/tests/test_capability_badge_partial.py
airano-ir f203ca88de
Some checks failed
Release / Test before release (push) Has been cancelled
Release / Publish to PyPI (push) Has been cancelled
Release / Publish to Docker Hub (push) Has been cancelled
Release / Create GitHub Release (push) Has been cancelled
feat(v3.12.0): media pipeline, AI image generation, capability probe, companion v2.9.0
Three-month batch sync from internal repo (~80 commits) covering Tracks F.5a, F.7e, F.8, F.17, F.18, F.X.

WordPress media pipeline
- Pillow-based optimization, AI image generation (OpenAI / Stability / Replicate / Google Nano Banana / OpenRouter), chunked + resumable uploads, bulk delete/reassign, idempotent retries.

Capability discovery (F.7e)
- Per-site credential probe + adapters for WordPress / WooCommerce / Gitea, tier-fit unions granted ∪ roles, capability badge UI with HTMX partial re-check, install hint in every companion-unreachable error.

Companion plugin overhaul
- Renamed wordpress-plugin/airano-mcp-seo-bridge → wordpress-plugin/airano-mcp-bridge.
- Eight new endpoints: /capabilities, /bulk-meta, /export, /cache-purge, /transient-flush, /site-health, /audit-hook, /upload-and-attach.
- wp.org Plugin Check pass: i18n, WP_Filesystem, scheme allowlist on audit-hook URL.

Other
- Gitea ergonomics (F.17): batch files, tree, search, compare, releases, fork.
- Opportunistic bcrypt upgrade for legacy SHA-256 admin keys (F.8).
- n8n refactor: structured errors, capability probe, missing tools backfilled.
- Idempotency-Key dedup for AI media upload retries; WP client fast-fails on unreachable sites.

Docs
- README + CLAUDE.md drop the fixed "633 tools" claim. The total grows with each release; per-plugin approximations + dashboard-surfaced counts replace it.
- Tools/Tests badges removed in favour of "Plugins: 10".

Deployment
- PyPI mirror chain, optional BUILD_HTTP_PROXY, Alpine→Yandex apk mirror, Debian-slim Plan-B Dockerfile, mirror.gcr.io variant.

CI
- Black + Ruff clean on Python 3.12; pytest tests/ green.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 16:25:58 +02:00

87 lines
3.2 KiB
Python

"""F.X.fix #9 — capability badge HTMX partial endpoint + template.
Regression: the Re-check button called ``window.location.reload()``,
which is jarring on slow networks and discards unrelated unsaved
state on the page. Fix: swap the badge in place via HTMX. The button
now carries ``hx-get="/api/sites/{id}/capabilities/badge"`` and the
target element has a matching id.
These tests don't spin up Starlette — they verify the two contracts
the front end depends on:
1. The partial template contains the right HTMX attrs (hx-get,
hx-target, hx-swap outerHTML) so the button actually triggers a
swap of just the badge element.
2. The new Starlette handler name is importable from
``core.capability_probe`` and wired under
/api/sites/{id}/capabilities/badge in server.py.
"""
from __future__ import annotations
from pathlib import Path
import pytest
BADGE_PARTIAL = (
Path(__file__).resolve().parent.parent / "core/templates/dashboard/sites/_capability_badge.html"
)
MANAGE_PAGE = Path(__file__).resolve().parent.parent / "core/templates/dashboard/sites/manage.html"
SERVER_PY = Path(__file__).resolve().parent.parent / "server.py"
class TestBadgePartialTemplate:
@pytest.mark.unit
def test_partial_exists(self):
assert BADGE_PARTIAL.is_file(), "_capability_badge.html partial must exist"
@pytest.mark.unit
def test_partial_has_stable_target_id(self):
text = BADGE_PARTIAL.read_text()
# The target id MUST match the hx-target value and the manage.html
# container id the old JS used.
assert 'id="capability-badge"' in text
@pytest.mark.unit
def test_partial_has_htmx_attrs(self):
text = BADGE_PARTIAL.read_text()
assert 'hx-get="/api/sites/{{ site.id }}/capabilities/badge?force=1"' in text
assert 'hx-target="#capability-badge"' in text
assert 'hx-swap="outerHTML"' in text
@pytest.mark.unit
def test_partial_renders_all_four_fit_states(self):
text = BADGE_PARTIAL.read_text()
# One branch per fit.status value produced by evaluate_tier_fit.
for state in ("ok", "warning", "probe_unavailable", "unknown_tier"):
assert state in text, f"partial missing branch for status={state!r}"
class TestManagePageUsesPartial:
@pytest.mark.unit
def test_manage_page_includes_partial(self):
text = MANAGE_PAGE.read_text()
assert '"dashboard/sites/_capability_badge.html"' in text
@pytest.mark.unit
def test_legacy_reload_shim_is_gone(self):
text = MANAGE_PAGE.read_text()
# The old window.location.reload()-based recheck must not be
# the mechanism any more.
assert "__capabilityProbe.recheck()" not in text
assert "window.__capabilityProbe" not in text
class TestHandlerIsWired:
@pytest.mark.unit
def test_handler_importable(self):
from core.capability_probe import api_site_capabilities_badge
assert callable(api_site_capabilities_badge)
@pytest.mark.unit
def test_route_registered_in_server_py(self):
text = SERVER_PY.read_text()
assert "/api/sites/{id}/capabilities/badge" in text
assert "api_site_capabilities_badge" in text