a48e4a5b6a
The template catalog is now Example 1-4: one stage, two stages (handoff), feedback loop (runner-owned limits, retries, timeout) and human decision (type=human approve/revise/abort with notify hooks). All read-only or leave changes uncommitted; none commits, pushes or deploys. A brand-new database (schema created by this Open) gets the examples once at server start, bound to the configured default model and harness. A server_settings marker records the decision, so removed examples never come back and existing installs are marked without any pipeline being added or rewritten.
135 lines
6.9 KiB
Python
135 lines
6.9 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"
|
|
examples = {"Example 1: one stage", "Example 2: two stages", "Example 3: feedback loop", "Example 4: human decision"}
|
|
seeded = {item["name"] for item in rpc("list")["pipelines"]}
|
|
assert seeded == examples, f"Fresh database must hold only the examples: {seeded}"
|
|
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 == {"one-stage", "two-stages", "feedback-loop", "human-decision"}, keys
|
|
# Exercise every example using only draft and validation
|
|
# commands: never run a model or launch an editor.
|
|
drafts = {}
|
|
for key in sorted(keys):
|
|
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["one-stage"]
|
|
assert len(rpc("list")["pipelines"]) == len(examples), "Draft creation must not publish"
|
|
rpc("submit", draft["path"], "--yes")
|
|
published = rpc("show", "Starter one-stage")
|
|
assert published["version"] == 1
|
|
archive = root / "definitions.zip"
|
|
rpc("export", "Starter one-stage", "--output", str(archive))
|
|
result = rpc("import", str(archive), "--all", "--yes")
|
|
assert not result["imported"], "Identical import must not republish"
|
|
assert rpc("show", "Starter one-stage")["version"] == 1
|
|
assert Path(draft["path"]).is_file(), "Published draft must remain"
|
|
finally:
|
|
stop(process)
|
|
process = start(log)
|
|
try:
|
|
assert rpc("show", "Starter one-stage")["source"] == published["source"], "Definition lost on restart"
|
|
after = rpc("list")["pipelines"]
|
|
assert len(after) == len(examples) + 1 and all(item["version"] == 1 for item in after), "Restart re-seeded examples"
|
|
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, DB seeded with only the four examples, four catalog templates drafted and validated with configured defaults, explicit scratch publication, ZIP identical import, restart persistence. Not an installation option; no inference or notifications.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|