conformance: consume the current Analysis, Observation and CLI Tool contracts

This commit is contained in:
cflmy committed 2026-11-24 18:31:45 +08:00
1 parent a728d215c9
commit 015ff8ac15
6 files changed
+65 -44

No files matched your search

+14 -5
View File
@@ -29,8 +29,17 @@ def args(cli, source, function, url, *, grant=True, **extra):
def typed_value(result):
"""Read the explicit return of one current Observation snapshot."""
assert result.returncode == 0, result.stderr or result.stdout
return unpack(json.loads(result.stdout)["value"])
document = json.loads(result.stdout)
assert document.get("schema") == "marqdo.observation", document
terminal = [
event
for event in document["events"]
if event["kind"] in ("run.completed", "run.failed", "run.rejected")
]
assert len(terminal) == 1 and terminal[0]["kind"] == "run.completed", terminal
return unpack(terminal[0]["payload"]["value"])
def unpack(value):
@@ -108,7 +117,7 @@ def server(respond, *, tls=None, expect_tls_refusal=False, request_count=1):
def request(cli, respond, *, tls=None, env=None, method="GET", body=""):
with server(respond, tls=tls) as url:
cmd = args(cli, NET, "request", url + "/demo?q=ready", method=method, body=body)
result = subprocess.run(cmd + ["--json"], env=env, capture_output=True,
result = subprocess.run(cmd + ["--output", "json"], env=env, capture_output=True,
text=True, timeout=20)
return typed_value(result)
@@ -174,7 +183,7 @@ def denied(cli):
run = subprocess.run(args(cli, NET, "request", url, grant=False),
capture_output=True, text=True, timeout=10)
assert run.returncode == 1 and "permission.denied" in run.stderr, run
injected = subprocess.run(args(cli, NET, "request", url + "/a\r\nb") + ["--json"],
injected = subprocess.run(args(cli, NET, "request", url + "/a\r\nb") + ["--output", "json"],
capture_output=True, text=True, timeout=10)
assert_result(typed_value(injected), ok=False, code="http.url")
listener.setblocking(False)
@@ -232,7 +241,7 @@ def live_sse(cli):
assert connection.recv(1) == b"", "client did not close after the second event"
with server(respond) as url, tempfile.TemporaryFile(mode="w+t") as diagnostics:
command = args(cli, NET, "events", url) + ["--event-stream", "jsonl"]
command = args(cli, NET, "events", url) + ["--output", "jsonl"]
output = bytearray()
terminal = None
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=diagnostics) as process:
@@ -275,7 +284,7 @@ def agent(cli):
def ask(url, tools):
command = args(cli, project / "index.mq.md", "ask", url,
query="How many?", tools=tools)
return typed_value(subprocess.run(command + ["--json"], cwd=project,
return typed_value(subprocess.run(command + ["--output", "json"], cwd=project,
capture_output=True, text=True, timeout=20))
calls = []