64a31a382b
Adds pyrightconfig.json (strict, Python 3.11) covering cli.py, claude_bottle/, and tests/. Fixes the 49 strict-mode errors: - Type DockerBottle.teardown as Callable[[], None]. - ResolvedEnv default_factory uses parameterized list[str] / dict[str, str]. - Erase BottleBackend generics at the registry boundary (BottleBackend[Any, Any]) since selection is runtime-driven and callers use the unparameterized interface. - DockerBottleBackend.launch returns Generator[DockerBottle, None, None]; @contextmanager now flags Iterator returns as deprecated. - Sidestep cli.list submodule shadowing builtins.list in main()'s argv annotation via an aliased re-import in cli/__init__.py. - Cast cfg[...] results in test_pipelock_yaml at the dict[str, object] boundary. - Annotate write_fixture's fn parameter and _manifest_with_runtime's return type.
90 lines
2.7 KiB
Python
90 lines
2.7 KiB
Python
"""Manifest fixtures for the test suite. Each fixture returns a built
|
|
Manifest dataclass; callers that need the raw JSON shape (e.g. to write
|
|
to a file on disk) can build it themselves or call .from_json_obj on
|
|
a dict literal in the test."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import tempfile
|
|
from pathlib import Path
|
|
from typing import Any, Callable
|
|
|
|
from claude_bottle.manifest import Manifest
|
|
|
|
|
|
def fixture_minimal_dict() -> dict[str, Any]:
|
|
"""One bottle, one agent, no env / ssh / skills. JSON shape."""
|
|
return {
|
|
"bottles": {"dev": {}},
|
|
"agents": {
|
|
"demo": {"skills": [], "prompt": "", "bottle": "dev"},
|
|
},
|
|
}
|
|
|
|
|
|
def fixture_with_egress_dict() -> dict[str, Any]:
|
|
"""Bottle declares an egress.allowlist. JSON shape."""
|
|
return {
|
|
"bottles": {
|
|
"dev": {
|
|
"egress": {
|
|
"allowlist": ["github.com", "gitlab.com", "registry.npmjs.org"]
|
|
}
|
|
}
|
|
},
|
|
"agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}},
|
|
}
|
|
|
|
|
|
def fixture_with_ssh_dict() -> dict[str, Any]:
|
|
"""Bottle has both an IPv4-literal SSH host (CGNAT) and a hostname host,
|
|
exercising both ssrf.ip_allowlist and trusted_domains code paths. JSON shape."""
|
|
return {
|
|
"bottles": {
|
|
"dev": {
|
|
"ssh": [
|
|
{
|
|
"Host": "tailscale-gitea",
|
|
"IdentityFile": "/dev/null",
|
|
"Hostname": "100.78.141.42",
|
|
"User": "git",
|
|
"Port": 30009,
|
|
},
|
|
{
|
|
"Host": "github",
|
|
"IdentityFile": "/dev/null",
|
|
"Hostname": "github.com",
|
|
"User": "git",
|
|
"Port": 22,
|
|
},
|
|
]
|
|
}
|
|
},
|
|
"agents": {"demo": {"skills": [], "prompt": "", "bottle": "dev"}},
|
|
}
|
|
|
|
|
|
def fixture_minimal() -> Manifest:
|
|
return Manifest.from_json_obj(fixture_minimal_dict())
|
|
|
|
|
|
def fixture_with_egress() -> Manifest:
|
|
return Manifest.from_json_obj(fixture_with_egress_dict())
|
|
|
|
|
|
def fixture_with_ssh() -> Manifest:
|
|
return Manifest.from_json_obj(fixture_with_ssh_dict())
|
|
|
|
|
|
def write_fixture(fn: Callable[[], dict[str, Any]]) -> Path:
|
|
"""Write fixture JSON to a temp file; return the path. Caller must rm.
|
|
Accepts a function returning either a dict (JSON shape) or a Manifest;
|
|
only the dict form is supported here since we need to serialize."""
|
|
f = tempfile.NamedTemporaryFile(
|
|
mode="w", suffix=".json", delete=False, encoding="utf-8"
|
|
)
|
|
json.dump(fn(), f)
|
|
f.close()
|
|
return Path(f.name)
|