Files
pipelines/scripts/smoke-first-install.py
T

131 lines
6.6 KiB
Python

#!/usr/bin/env python3
"""Developer-only source lifecycle check; not an alternative installer. No inference."""
import argparse
import json
import os
from pathlib import Path
import socket
import subprocess
import tempfile
import time
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--temp-dir", help="Parent directory for disposable test files")
args = parser.parse_args()
repo = Path(__file__).resolve().parent.parent
with tempfile.TemporaryDirectory(prefix="pipelines-first-install-", dir=args.temp_dir) as temporary:
root = Path(temporary)
env = {k: v for k, v in os.environ.items() if not k.startswith("PIPELINES_")}
env.update(GOBIN=str(root / "bin"), XDG_CONFIG_HOME=str(root / "config"),
XDG_DATA_HOME=str(root / "data"), PIPELINES_DRAFT_DIR=str(root / "drafts"),
# Syntactically valid fixture IDs bind template defaults. No
# provider is contacted and no workflow is executed.
PIPELINES_DEFAULT_MODEL="smoke-provider/smoke-model",
PIPELINES_DEFAULT_HARNESS="opencode")
subprocess.run(["go", "install", "-trimpath", "./cmd/..."], cwd=repo, env=env, check=True, timeout=180)
subprocess.run([str(root / "bin/pipelines"), "skill", "install"], cwd=repo, env=env, check=True, timeout=30)
cli = root / "bin/pipelines"
assert (root / "bin/pipelines-tui").is_file(), "TUI binary missing"
assert (root / "config/opencode/skills/pipelines/references/operations.md").is_file(), "Skill not installed"
workspace = root / "workspace"
workspace.mkdir()
def local(*command):
result = subprocess.run([str(cli), *command], cwd=workspace, env=env,
capture_output=True, text=True, timeout=30)
if result.returncode:
raise RuntimeError(
f"CLI command {command!r} exited {result.returncode}\n"
f"stdout:\n{result.stdout}\nstderr:\n{result.stderr}"
)
return result.stdout
version = json.loads(local("version", "--json"))
assert version == json.loads(local("--version", "--json"))
assert "import [FILE.zip]" in local("help")
with socket.socket() as sock:
sock.bind(("127.0.0.1", 0))
port = sock.getsockname()[1]
endpoint = f"ws://127.0.0.1:{port}/connect"
database = root / "runs.db"
def rpc(*command):
return json.loads(local("--url", endpoint, *command, "--json"))
def start(log):
process = subprocess.Popen([str(root / "bin/pipelines-server"), "-addr", f"127.0.0.1:{port}",
"-db", str(database), "-allow-authoring"],
cwd=workspace, env=env, stdout=log, stderr=log)
try:
deadline = time.monotonic() + 15
while time.monotonic() < deadline:
if process.poll() is not None:
raise RuntimeError("Test server exited; see " + str(root / "server.log"))
try:
with socket.create_connection(("127.0.0.1", port), timeout=.1):
return process
except OSError:
time.sleep(.05)
raise RuntimeError("Test server did not become ready")
except BaseException:
stop(process)
raise
def stop(process):
process.terminate()
try:
process.wait(timeout=10)
except subprocess.TimeoutExpired:
process.kill()
process.wait()
raise
with (root / "server.log").open("w") as log:
process = start(log)
try:
pong = rpc("ping")
assert pong["build"] == version, "Client/server build mismatch"
assert not rpc("list").get("pipelines"), "Fresh database must be empty"
assert not rpc("runs").get("runs"), "Fresh database must have no runs"
templates = rpc("templates")["templates"]
keys = {template["key"] for template in templates}
assert keys == {"task", "research", "summarize", "compare", "plan", "review", "three-stage", "debug"}, keys
# Exercise the five primary starters using only draft and
# validation commands: never run a model or launch an editor.
drafts = {}
for key in ("task", "research", "summarize", "compare", "plan"):
drafts[key] = rpc("new", f"Starter {key}", "Use only supplied test context",
"--template", key, "--no-open", "--yes")
rpc("validate", drafts[key]["path"])
source = Path(drafts[key]["path"]).read_text()
assert "provider=smoke-provider" in source, key
assert "model=smoke-model" in source, key
assert "harness=opencode" in source, key
draft = drafts["plan"]
assert not rpc("list").get("pipelines"), "Draft creation must not publish"
rpc("submit", draft["path"], "--yes")
published = rpc("show", "Starter plan")
assert published["version"] == 1
archive = root / "definitions.zip"
rpc("export", "Starter plan", "--output", str(archive))
result = rpc("import", str(archive), "--all", "--yes")
assert not result["imported"], "Identical import must not republish"
assert rpc("show", "Starter plan")["version"] == 1
assert Path(draft["path"]).is_file(), "Published draft must remain"
finally:
stop(process)
process = start(log)
try:
assert rpc("show", "Starter plan")["source"] == published["source"], "Definition lost on restart"
assert rpc("ping")["build"] == version
assert not rpc("runs").get("runs"), "Smoke check must not execute a workflow"
finally:
stop(process)
print("PASS developer lifecycle fixture: isolated source binaries/skill, offline version, empty DB, eight catalog templates, five generic drafts validated with configured defaults, explicit scratch publication, ZIP identical import, restart persistence. Not an installation option; no inference or notifications.")
if __name__ == "__main__":
main()