feat(backend): BackendStatus enum, quiet status(), is_backend_ready()
tracker-policy-pr / check-pr (pull_request) Successful in 11s
test / integration-docker (pull_request) Successful in 17s
lint / lint (push) Failing after 54s
test / unit (pull_request) Failing after 1m33s
test / integration-firecracker (pull_request) Successful in 3m17s
test / coverage (pull_request) Has been skipped
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Successful in 11s
test / integration-docker (pull_request) Successful in 17s
lint / lint (push) Failing after 54s
test / unit (pull_request) Failing after 1m33s
test / integration-firecracker (pull_request) Successful in 3m17s
test / coverage (pull_request) Has been skipped
test / publish-infra (pull_request) Has been skipped
Add a module-level BackendStatus(IntEnum) with READY=0 to replace magic 0 comparisons. Extend BottleBackend.status() with a quiet parameter: quiet=False (default) prints diagnostics; quiet=True returns the code silently for programmatic checks. Add is_backend_available() (cheap PATH check, alias for has_backend) and is_backend_ready(name, *, quiet=False) (full status() check) to the backend package for callers that need to distinguish availability from readiness. Update tests/_backend.py guards to use is_backend_ready(quiet=False) so diagnostic output is printed during test discovery, giving the operator a concrete reason for each skip rather than a bare "prerequisites unavailable" message. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+21
-11
@@ -1,9 +1,11 @@
|
||||
"""Backend selection + capability-aware skip guards for the integration suite.
|
||||
"""Backend selection + readiness-aware skip guards for the integration suite.
|
||||
|
||||
Each integration test targets the backend named by ``BOT_BOTTLE_BACKEND``
|
||||
(default ``docker``) and skips on that backend's own readiness check —
|
||||
``bot_bottle.backend.has_backend`` (the same probe behind
|
||||
``./cli.py backend status``), not an unrelated "is Docker installed" test.
|
||||
(default ``docker``) and gates on that backend's full readiness check —
|
||||
``is_backend_ready()`` (equivalent to ``./cli.py backend status``), not just
|
||||
a binary-on-PATH probe. When the backend is not ready, diagnostic output is
|
||||
printed during test discovery so the operator sees a concrete reason for each
|
||||
skip.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -11,7 +13,7 @@ from __future__ import annotations
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from bot_bottle.backend import has_backend
|
||||
from bot_bottle.backend import is_backend_available, is_backend_ready
|
||||
|
||||
# Default when ``BOT_BOTTLE_BACKEND`` is unset. Docker preserves the historical
|
||||
# Docker-backed CI path (and mirrors the pin in ``test_sandbox_escape``).
|
||||
@@ -30,13 +32,16 @@ def selected_backend() -> str:
|
||||
|
||||
def skip_unless_backend(backend: str):
|
||||
"""Skip a backend-specific test unless the selected backend matches AND
|
||||
that backend is available on the host.
|
||||
that backend is fully ready.
|
||||
|
||||
Docker-implementation tests (``DockerBroker``, ``DockerGateway``,
|
||||
``backend.docker.*``) use ``skip_unless_backend("docker")`` so they no-op
|
||||
under a run targeting a different backend instead of testing Docker
|
||||
internals that run doesn't exercise — the guard reads
|
||||
``BOT_BOTTLE_BACKEND`` rather than "is Docker installed".
|
||||
|
||||
When the backend is not ready, ``status()`` output is printed so the
|
||||
operator sees a concrete diagnostic for each skipped test module.
|
||||
"""
|
||||
sel = selected_backend()
|
||||
if sel != backend:
|
||||
@@ -44,18 +49,23 @@ def skip_unless_backend(backend: str):
|
||||
f"backend {backend!r} not selected (BOT_BOTTLE_BACKEND={sel})"
|
||||
)
|
||||
return unittest.skipUnless(
|
||||
has_backend(backend), f"{backend} backend prerequisites unavailable"
|
||||
is_backend_ready(backend, quiet=False),
|
||||
f"{backend} backend not ready",
|
||||
)
|
||||
|
||||
|
||||
def skip_unless_selected_backend_available():
|
||||
"""Skip a backend-agnostic test unless the *selected* backend is available.
|
||||
"""Skip a backend-agnostic test unless the *selected* backend is fully ready.
|
||||
|
||||
The test then runs through whichever backend ``BOT_BOTTLE_BACKEND`` names,
|
||||
gated on that backend's real prerequisites (e.g. Linux + KVM for
|
||||
Firecracker) rather than unrelated Docker availability.
|
||||
gated on that backend's full status() check (e.g. daemon reachable, TAP
|
||||
pool present for Firecracker) rather than just a binary-on-PATH probe.
|
||||
|
||||
When the backend is not ready, ``status()`` output is printed so the
|
||||
operator sees a concrete diagnostic for each skipped test module.
|
||||
"""
|
||||
backend = selected_backend()
|
||||
return unittest.skipUnless(
|
||||
has_backend(backend), f"selected backend {backend!r} prerequisites unavailable"
|
||||
is_backend_ready(backend, quiet=False),
|
||||
f"selected backend {backend!r} not ready",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user