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>
This commit is contained in:
120
tests/plugins/wordpress/test_media_error_taxonomy.py
Normal file
120
tests/plugins/wordpress/test_media_error_taxonomy.py
Normal file
@@ -0,0 +1,120 @@
|
||||
"""F.5a.6.2 — Error-code taxonomy stability test.
|
||||
|
||||
Walks every raise-site in the media stack, extracts the literal error
|
||||
code, and asserts each one is in the documented
|
||||
:data:`core.media_error_codes.MEDIA_ERROR_CODES` set (or matches the
|
||||
dynamic ``WP_<status>`` pattern).
|
||||
|
||||
If this test fails, you're either:
|
||||
- Introducing a new code — add it to ``MEDIA_ERROR_CODES`` *and*
|
||||
``docs/media-error-codes.md``, or
|
||||
- Removing a documented code — make sure it's actually unused and drop
|
||||
it from both the set and the docs.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from core.media_error_codes import MEDIA_ERROR_CODES, is_valid_code
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[3]
|
||||
|
||||
# Files to scan for error-code literals.
|
||||
SCANNED_FILES = [
|
||||
"plugins/wordpress/handlers/_media_security.py",
|
||||
"plugins/wordpress/handlers/_media_core.py",
|
||||
"plugins/wordpress/handlers/media.py",
|
||||
"plugins/wordpress/handlers/media_attach.py",
|
||||
"plugins/wordpress/handlers/media_chunked.py",
|
||||
"plugins/wordpress/handlers/ai_media.py",
|
||||
"core/upload_sessions.py",
|
||||
"core/tool_rate_limiter.py",
|
||||
"plugins/ai_image/providers/base.py",
|
||||
"plugins/ai_image/providers/openai.py",
|
||||
"plugins/ai_image/providers/stability.py",
|
||||
"plugins/ai_image/providers/replicate.py",
|
||||
"plugins/ai_image/registry.py",
|
||||
]
|
||||
|
||||
# Literal raise-site patterns. Multiline to span wrapped calls.
|
||||
_RAISE_RE = re.compile(
|
||||
r'raise\s+(?:UploadError|UploadSessionError|ProviderError)\s*\(\s*"([A-Z][A-Z0-9_]+)"',
|
||||
re.MULTILINE,
|
||||
)
|
||||
# Formatted (f-string) codes like f"WP_{response.status}" — we assert the
|
||||
# pattern prefix is a valid dynamic code.
|
||||
_FSTRING_RE = re.compile(
|
||||
r"raise\s+(?:UploadError|UploadSessionError|ProviderError)\s*\(\s*" r'f"([A-Z_]+)\{',
|
||||
re.MULTILINE,
|
||||
)
|
||||
# Hard-coded error_code dict literals like {"error_code": "INTERNAL", ...}
|
||||
_ERROR_CODE_RE = re.compile(r'"error_code"\s*:\s*"([A-Z][A-Z0-9_]+)"')
|
||||
|
||||
|
||||
def _collect_codes() -> tuple[set[str], set[str]]:
|
||||
literal_codes: set[str] = set()
|
||||
fstring_prefixes: set[str] = set()
|
||||
for rel in SCANNED_FILES:
|
||||
path = REPO_ROOT / rel
|
||||
text = path.read_text(encoding="utf-8")
|
||||
literal_codes.update(_RAISE_RE.findall(text))
|
||||
literal_codes.update(_ERROR_CODE_RE.findall(text))
|
||||
fstring_prefixes.update(_FSTRING_RE.findall(text))
|
||||
return literal_codes, fstring_prefixes
|
||||
|
||||
|
||||
def test_every_raise_site_uses_documented_code():
|
||||
literal_codes, fstring_prefixes = _collect_codes()
|
||||
assert literal_codes, "taxonomy test found no raise sites — scanner broken?"
|
||||
|
||||
undocumented = {c for c in literal_codes if not is_valid_code(c)}
|
||||
assert not undocumented, (
|
||||
f"Undocumented error codes in raise sites: {sorted(undocumented)}. "
|
||||
f"Add them to core.media_error_codes.MEDIA_ERROR_CODES and "
|
||||
f"docs/media-error-codes.md, or remove the raise site."
|
||||
)
|
||||
|
||||
# f-string codes must have a documented prefix (e.g. "WP_" for WP_{status}
|
||||
# or "COMPANION_" for COMPANION_{status} from the F.5a.7 upload-chunk route).
|
||||
allowed_prefixes = {"WP_", "COMPANION_"}
|
||||
for prefix in fstring_prefixes:
|
||||
assert prefix in allowed_prefixes, (
|
||||
f"Unknown dynamic error-code prefix '{prefix}'. "
|
||||
f"Allowed prefixes: {sorted(allowed_prefixes)} (see is_valid_code)."
|
||||
)
|
||||
|
||||
|
||||
def test_documented_codes_are_all_used():
|
||||
"""Stability guard: every documented code has at least one raise/use site.
|
||||
|
||||
Prevents the documented set from drifting with dead entries. A small
|
||||
allow-list exists for codes that are reserved for upcoming work.
|
||||
"""
|
||||
literal_codes, _ = _collect_codes()
|
||||
reserved: set[str] = set() # None currently reserved.
|
||||
unused = MEDIA_ERROR_CODES - literal_codes - reserved
|
||||
# WP_<status> is dynamic; its fixed siblings (WP_413, WP_AUTH, WP_BAD_RESPONSE)
|
||||
# must be explicitly raised.
|
||||
assert not unused, (
|
||||
f"Documented codes with no raise site: {sorted(unused)}. "
|
||||
"Either wire them up, move to the 'reserved' set, or remove them."
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("code", sorted(MEDIA_ERROR_CODES))
|
||||
def test_is_valid_code_accepts_documented(code):
|
||||
assert is_valid_code(code)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("code", ["WP_400", "WP_500", "WP_418"])
|
||||
def test_is_valid_code_accepts_dynamic_wp_status(code):
|
||||
assert is_valid_code(code)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("code", ["UNKNOWN", "wp_413", "WP_", "WP_X", "WP_41"])
|
||||
def test_is_valid_code_rejects_others(code):
|
||||
assert not is_valid_code(code)
|
||||
Reference in New Issue
Block a user