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,81 @@
|
||||
"""Integration: cli.py start --dry-run renders the planned shape and
|
||||
does not create any docker resources. Confirms the preflight contract
|
||||
from PRD 0001 (allowlist line in the plan, no docker side effects)."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from tests._docker import skip_unless_docker
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
@skip_unless_docker()
|
||||
class TestDryRunPlan(unittest.TestCase):
|
||||
def test_dry_run(self):
|
||||
work_dir = Path(tempfile.mkdtemp())
|
||||
try:
|
||||
manifest = work_dir / "claude-bottle.json"
|
||||
manifest.write_text(json.dumps({
|
||||
"bottles": {"dev": {"egress": {"allowlist": ["example.org"]}}},
|
||||
"agents": {
|
||||
"demo": {"skills": [], "prompt": "", "bottle": "dev"},
|
||||
},
|
||||
}))
|
||||
|
||||
nets_before = self._count_claude_bottle_networks()
|
||||
ctrs_before = self._count_claude_bottle_containers()
|
||||
|
||||
env = os.environ.copy()
|
||||
env["HOME"] = str(work_dir)
|
||||
env["CLAUDE_BOTTLE_DRY_RUN"] = "1"
|
||||
result = subprocess.run(
|
||||
[sys.executable, str(REPO_ROOT / "cli.py"), "start", "demo"],
|
||||
cwd=work_dir,
|
||||
env=env,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
out = result.stdout + result.stderr
|
||||
|
||||
self.assertIn("egress", out, "preflight: egress line present")
|
||||
# 7 baked defaults + 1 bottle entry = 8.
|
||||
self.assertRegex(out, r"8 hosts allowed", "preflight: bottle entry counted")
|
||||
self.assertIn("api.anthropic.com", out, "preflight: baked default shown")
|
||||
self.assertRegex(out, r"runtime\s*:\s*runc", "preflight: default runtime shown")
|
||||
self.assertIn("dry-run requested", out, "dry-run banner present")
|
||||
self.assertNotIn("/dev/tty", out, "dry-run exited before tty prompt")
|
||||
|
||||
self.assertEqual(nets_before, self._count_claude_bottle_networks(),
|
||||
"no networks created")
|
||||
self.assertEqual(ctrs_before, self._count_claude_bottle_containers(),
|
||||
"no containers created")
|
||||
finally:
|
||||
import shutil
|
||||
shutil.rmtree(work_dir, ignore_errors=True)
|
||||
|
||||
def _count_claude_bottle_networks(self) -> int:
|
||||
result = subprocess.run(
|
||||
["docker", "network", "ls", "--format", "{{.Name}}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
return sum(1 for n in result.stdout.splitlines() if n.startswith("claude-bottle"))
|
||||
|
||||
def _count_claude_bottle_containers(self) -> int:
|
||||
result = subprocess.run(
|
||||
["docker", "ps", "-a", "--format", "{{.Names}}"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
return sum(1 for n in result.stdout.splitlines() if n.startswith("claude-bottle"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Integration: the cleanup primitives the start-flow trap depends on
|
||||
are idempotent. The original orphan-network bug was a trap-ordering
|
||||
issue; the fix moved the install earlier. The trap is only safe if
|
||||
network_remove and PipelockProxy.stop are no-ops against missing
|
||||
resources."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
from claude_bottle.backend.docker.network import (
|
||||
network_create_egress,
|
||||
network_create_internal,
|
||||
network_remove,
|
||||
)
|
||||
from claude_bottle.backend.docker.pipelock import (
|
||||
DockerPipelockProxy,
|
||||
pipelock_container_name,
|
||||
)
|
||||
from tests._docker import skip_unless_docker
|
||||
|
||||
|
||||
@skip_unless_docker()
|
||||
class TestOrphanCleanup(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.slug = f"cb-test-orphan-{os.getpid()}"
|
||||
self.internal_name = ""
|
||||
self.egress_name = ""
|
||||
|
||||
def tearDown(self):
|
||||
for n in (self.internal_name, self.egress_name):
|
||||
if n:
|
||||
subprocess.run(
|
||||
["docker", "network", "rm", n],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
)
|
||||
|
||||
def test_remove_missing_is_noop(self):
|
||||
# Returning True == idempotent success.
|
||||
self.assertTrue(network_remove(f"claude-bottle-net-{self.slug}-does-not-exist"))
|
||||
|
||||
@unittest.skipIf(
|
||||
os.environ.get("GITEA_ACTIONS") == "true",
|
||||
"skipped under act_runner: docker socket mount topology breaks "
|
||||
"in-process visibility of networks created on the host daemon",
|
||||
)
|
||||
def test_create_and_remove(self):
|
||||
self.internal_name = network_create_internal(self.slug)
|
||||
self.egress_name = network_create_egress(self.slug)
|
||||
|
||||
nets = subprocess.run(
|
||||
["docker", "network", "ls", "--format", "{{.Name}}"],
|
||||
capture_output=True, text=True,
|
||||
).stdout.splitlines()
|
||||
self.assertIn(self.internal_name, nets)
|
||||
self.assertIn(self.egress_name, nets)
|
||||
|
||||
self.assertTrue(network_remove(self.internal_name))
|
||||
self.assertTrue(network_remove(self.egress_name))
|
||||
|
||||
nets_after = subprocess.run(
|
||||
["docker", "network", "ls", "--format", "{{.Name}}"],
|
||||
capture_output=True, text=True,
|
||||
).stdout.splitlines()
|
||||
self.assertNotIn(self.internal_name, nets_after)
|
||||
self.assertNotIn(self.egress_name, nets_after)
|
||||
|
||||
# Idempotent on already-removed.
|
||||
self.assertTrue(network_remove(self.internal_name))
|
||||
self.assertTrue(network_remove(self.egress_name))
|
||||
|
||||
def test_pipelock_stop_missing_sidecar(self):
|
||||
# Should not raise.
|
||||
DockerPipelockProxy().stop(pipelock_container_name(f"missing-{self.slug}"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -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