test: reorganize suite into unit/integration/canaries directories
Replace the hand-maintained INTEGRATION_NAMES classifier (and the
bespoke run_tests.py around it) with a directory-driven split:
tests/unit/ unit tests, always run
tests/integration/ Docker-dependent, skip cleanly without Docker
tests/canaries/ upstream-regression checks, opt-in via
CLAUDE_BOTTLE_RUN_CANARIES=1
The pinned-pipelock-image check moves to the canary suite — it tests
upstream packaging, not our code, so it shouldn't gate every dev push.
A scheduled canaries.yml workflow runs it weekly.
The manifest-runtime tests collapse the four assertRaises cases for
distinct 'runtime' values into one subTest loop and drop the
error-message-wording assertions; the contract is "any value is
rejected", not "the error literally contains 'auto-detect'".
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
"""Integration: full sidecar smoke test. Boots a pipelock container the
|
||||
same way cli.py does (docker create + docker cp YAML + docker start),
|
||||
then probes /health."""
|
||||
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
from claude_bottle.backend.docker.pipelock import (
|
||||
PIPELOCK_IMAGE,
|
||||
DockerPipelockProxy,
|
||||
)
|
||||
from tests._docker import skip_unless_docker
|
||||
from tests.fixtures import fixture_minimal
|
||||
|
||||
|
||||
@skip_unless_docker()
|
||||
class TestPipelockSidecarSmoke(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.name = f"cb-test-pipelock-smoke-{os.getpid()}"
|
||||
self.work_dir = Path(tempfile.mkdtemp())
|
||||
|
||||
def tearDown(self):
|
||||
subprocess.run(
|
||||
["docker", "rm", "-f", self.name],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
shutil.rmtree(self.work_dir, ignore_errors=True)
|
||||
|
||||
@unittest.skipIf(
|
||||
os.environ.get("GITEA_ACTIONS") == "true",
|
||||
"skipped under act_runner: published port is on the host's "
|
||||
"loopback, not reachable from the job container's 127.0.0.1",
|
||||
)
|
||||
def test_smoke(self):
|
||||
yaml_path = self.work_dir / "pipelock.yaml"
|
||||
DockerPipelockProxy().prepare(fixture_minimal().bottles["dev"], "demo", yaml_path)
|
||||
|
||||
create = subprocess.run(
|
||||
[
|
||||
"docker", "create",
|
||||
"--name", self.name,
|
||||
"-p", "0:8888",
|
||||
PIPELOCK_IMAGE,
|
||||
"run", "--config", "/etc/pipelock.yaml",
|
||||
"--listen", "0.0.0.0:8888",
|
||||
],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(0, create.returncode, f"docker create failed: {create.stderr}")
|
||||
|
||||
# Guard against /etc/pipelock/ regressions: the path must be
|
||||
# /etc/pipelock.yaml, since the image is distroless.
|
||||
cp = subprocess.run(
|
||||
["docker", "cp", str(yaml_path), f"{self.name}:/etc/pipelock.yaml"],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(0, cp.returncode, f"docker cp failed: {cp.stderr}")
|
||||
|
||||
start = subprocess.run(
|
||||
["docker", "start", self.name],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
self.assertEqual(0, start.returncode,
|
||||
f"docker start failed; check argv 'run --listen 0.0.0.0:8888'")
|
||||
|
||||
port_result = subprocess.run(
|
||||
["docker", "port", self.name, "8888"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
first_line = (port_result.stdout or "").splitlines()[0] if port_result.stdout else ""
|
||||
host_port = first_line.rsplit(":", 1)[-1] if first_line else ""
|
||||
self.assertTrue(host_port, "could not determine published port")
|
||||
|
||||
health_url = f"http://127.0.0.1:{host_port}/health"
|
||||
body = ""
|
||||
for _ in range(15):
|
||||
try:
|
||||
with urllib.request.urlopen(health_url, timeout=2) as resp:
|
||||
body = resp.read().decode("utf-8")
|
||||
break
|
||||
except (urllib.error.URLError, urllib.error.HTTPError, ConnectionError):
|
||||
time.sleep(1)
|
||||
|
||||
self.assertIn('"status":"healthy"', body, "health body status:healthy")
|
||||
self.assertRegex(body, r'"version":"[0-9]+\.[0-9]+\.[0-9]+"',
|
||||
"health body has version field")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user