conformance: consume the current Analysis, Observation and CLI Tool contracts
This commit is contained in:
1 parent
a728d215c9
commit
015ff8ac15
6 files changed
+65
-44
No files matched your search
+14
-5
@@ -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 = []
|
||||
|
||||
+22
-7
@@ -53,6 +53,20 @@ class Case:
|
||||
error_codes: list[str] = field(default_factory=list)
|
||||
|
||||
|
||||
|
||||
def completed_value(stdout: str) -> object:
|
||||
"""Explicit return of one current Observation snapshot."""
|
||||
document = json.loads(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 terminal[0]["payload"]["value"]
|
||||
|
||||
|
||||
class Runner:
|
||||
def __init__(self, cli: Path) -> None:
|
||||
self.cli = cli
|
||||
@@ -298,13 +312,14 @@ class Runner:
|
||||
str(build / "provider.json"),
|
||||
"--allow-provider",
|
||||
"demo.sensor",
|
||||
"--json",
|
||||
"--output",
|
||||
"json",
|
||||
]
|
||||
)
|
||||
self.finish(case, result, 0)
|
||||
if case.status == "PASS":
|
||||
payload = json.loads(result.stdout)
|
||||
if payload.get("value") != {"type": "int", "decimal": "5"}:
|
||||
value = completed_value(result.stdout)
|
||||
if value != {"type": "int", "decimal": "5"}:
|
||||
case.status = "FAIL"
|
||||
case.detail = f"unexpected provider value: {result.stdout[:500]}"
|
||||
|
||||
@@ -404,7 +419,7 @@ class Runner:
|
||||
|
||||
def check_tool(self) -> None:
|
||||
case = self.case(
|
||||
"tool_analysis_consumer", "independent tool consumes Analysis v2"
|
||||
"tool_analysis_consumer", "independent tool consumes the current Analysis"
|
||||
)
|
||||
home = Path(tempfile.mkdtemp(prefix="ext-tool-home-"))
|
||||
try:
|
||||
@@ -487,11 +502,11 @@ class Runner:
|
||||
)
|
||||
check = self.run(["check", "index.mq.md"], cwd=consumer)
|
||||
ok = self.finish(case, check, 0)
|
||||
run = self.run(["run", "index.mq.md", "--json"], cwd=consumer)
|
||||
run = self.run(["run", "index.mq.md", "--output", "json"], cwd=consumer)
|
||||
ok = ok and self.finish(case, run, 0)
|
||||
if ok:
|
||||
payload = json.loads(run.stdout)
|
||||
if payload.get("value") != {"type": "int", "decimal": "18"}:
|
||||
value = completed_value(run.stdout)
|
||||
if value != {"type": "int", "decimal": "18"}:
|
||||
case.status = "FAIL"
|
||||
case.detail = f"unexpected consumer value: {run.stdout[:500]}"
|
||||
ok = False
|
||||
|
||||
Reference in new issue
Block a user