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

+22 -7
View File
@@ -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