d4d45f835e
test / integration-docker (pull_request) Successful in 25s
test / unit (pull_request) Successful in 52s
lint / lint (push) Successful in 1m0s
test / integration-firecracker (pull_request) Successful in 2m5s
test / coverage (pull_request) Successful in 24s
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Successful in 6s
Review feedback: the hand-rolled `/dev/kvm` + docker-daemon capability probes duplicated logic the CLI already owns. Delegate instead. - tests/_backend.py skip guards now gate on `bot_bottle.backend.has_backend` (each backend's `is_available()` classmethod — the same probe behind `./cli.py backend status`), dropping the bespoke `Capability` probes. - Remove tests/backend_preflight.py; the docker integration job runs `./cli.py backend status --backend=docker` as its preflight (clear per-check summary, non-zero exit when unready), matching the firecracker job. The firecracker preflight reverts to its original binary/KVM checks (backend status doesn't cover those). - Unit test + docs updated to match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
62 lines
2.2 KiB
Python
62 lines
2.2 KiB
Python
"""Backend selection + capability-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.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import unittest
|
|
|
|
from bot_bottle.backend import has_backend
|
|
|
|
# Default when ``BOT_BOTTLE_BACKEND`` is unset. Docker preserves the historical
|
|
# Docker-backed CI path (and mirrors the pin in ``test_sandbox_escape``).
|
|
DEFAULT_BACKEND = "docker"
|
|
|
|
|
|
def selected_backend() -> str:
|
|
"""The backend this test run targets, from ``BOT_BOTTLE_BACKEND``.
|
|
|
|
Mirrors the CLI's env selector; unset means ``docker`` so an
|
|
unconfigured run behaves exactly as the suite did before backends were
|
|
pluggable.
|
|
"""
|
|
return os.environ.get("BOT_BOTTLE_BACKEND") or DEFAULT_BACKEND
|
|
|
|
|
|
def skip_unless_backend(backend: str):
|
|
"""Skip a backend-specific test unless the selected backend matches AND
|
|
that backend is available on the host.
|
|
|
|
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".
|
|
"""
|
|
sel = selected_backend()
|
|
if sel != backend:
|
|
return unittest.skip(
|
|
f"backend {backend!r} not selected (BOT_BOTTLE_BACKEND={sel})"
|
|
)
|
|
return unittest.skipUnless(
|
|
has_backend(backend), f"{backend} backend prerequisites unavailable"
|
|
)
|
|
|
|
|
|
def skip_unless_selected_backend_available():
|
|
"""Skip a backend-agnostic test unless the *selected* backend is available.
|
|
|
|
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.
|
|
"""
|
|
backend = selected_backend()
|
|
return unittest.skipUnless(
|
|
has_backend(backend), f"selected backend {backend!r} prerequisites unavailable"
|
|
)
|