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

+6 -5
View File
@@ -5,7 +5,7 @@ works" claim. Unknown/newer protocol versions fail closed.
| Contract | Version used here | Required by |
|---|---|---|
| Marqdo Core CLI | `3.0.0-beta.1` (frozen binary SHA recorded in `evidence/`) | all |
| Marqdo Core CLI | `3.0.0-rc.3` candidate (frozen binary SHA recorded in `evidence/`) | all |
| Language semantics | RFC-LANG-0002 / ADR-0052 (one Markdown→program mapping) | `.mq.md` fixtures |
| Markdown profile | `marqdo.md.v1` | all documents |
| Plugin ABI | C ABI v1 (`MQ_ABI_MAJOR=1`, host target triple recorded in `plugin/build/plugin.yaml`) | `plugin/` |
@@ -14,8 +14,8 @@ works" claim. Unknown/newer protocol versions fail closed.
| Foreign kernel descriptor | `kernel.json` v1 (`wire_version: 1`) | `kernel/` |
| Resource provider manifest | `marqdo.provider` schema v2, `transport: worker`, `abi: c-abi-1` | `provider/` |
| Resource provider worker protocol | ADR-0035 framed JSON (host ↔ helper) + C ABI v1 (helper ↔ library) | `provider/` |
| Analysis | Analysis v2 (`marqdo check --emit`) | `tool/` |
| Trace | Trace v2 (`marqdo run --trace-file`) | `tool/` |
| Analysis | current Analysis (`marqdo check --emit`) | `tool/` |
| Observation | current `marqdo.observation` (`run --output jsonl`, `run --observation-file`) | `tool/`, `tests/reference_apps.py` |
| CLI Tool Protocol | v1 (`marqdo.cli-tool`, schema_version 1) | `tool/` |
## Platform matrix
@@ -37,8 +37,9 @@ the committed manifests contain zero digests and are templates only.
consumer never resolves a branch or "latest".
* The plugin/provider manifests are matched against the static descriptor and
the loaded artifact; a changed byte fails before the entry function runs.
* Analysis/Trace evidence is consumed as public JSON only; no private Rust IR
is linked or copied.
* Analysis/Observation evidence is consumed as public JSON only; no private
Rust IR is linked or copied. The retired Analysis v2/v3 switch, Trace and
Execution Events formats are rejected, not adapted.
## Grants and failure behaviour
+1 -1
View File
@@ -21,5 +21,5 @@ The package uses the existing blocking socket timeout. Closing a reader stops
future reads. Interrupting an in-flight read requires a later resource protocol.
```sh
marqdo call marqdo-net/demo.mq.md request --arg 'url="http://127.0.0.1:8080/"' --allow-net 127.0.0.1 --json
marqdo call marqdo-net/demo.mq.md request --arg 'url="http://127.0.0.1:8080/"' --allow-net 127.0.0.1 --output json
```
+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 = []
+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
+20 -20
View File
@@ -1,16 +1,17 @@
#!/usr/bin/env python3
"""Independent Marqdo CLI Tool (Tool Protocol v1).
"""Independent Marqdo CLI Tool (current CLI Tool protocol).
Consumes only public contracts: `$MARQDO_BIN check <doc> --emit <analysis>`
(Analysis v2) and optionally `$MARQDO_BIN run <doc> --trace-file <trace>`
(Trace v2). It links no Rust crate and reads no CLI source tree.
(current Analysis) and optionally `$MARQDO_BIN run <doc> --observation-file
<snapshot>` (current Observation). It links no Rust crate and reads no CLI
source tree.
Usage:
marqdo inspect-ext <document.mq.md> [--trace]
marqdo inspect-ext <document.mq.md> [--observe]
Prints one deterministic JSON object:
{"schema":"ext.inspect.v1","document":...,"functions":[...],
"function_digest":"sha256:...", "trace": {...}|null}
"function_digest":"sha256:...", "observation": {...}|null}
"""
import hashlib
import json
@@ -30,9 +31,9 @@ def fail(message, code=2):
def main(argv):
args = [arg for arg in argv[1:] if not arg.startswith("--")]
want_trace = "--trace" in argv[1:]
want_trace = "--observe" in argv[1:]
if len(args) != 1:
return fail("usage: marqdo inspect-ext <document.mq.md> [--trace]")
return fail("usage: marqdo inspect-ext <document.mq.md> [--observe]")
bin_path = os.environ.get("MARQDO_BIN")
if not bin_path:
return fail("MARQDO_BIN is not set; install through `marqdo tool install`")
@@ -42,7 +43,7 @@ def main(argv):
with tempfile.TemporaryDirectory(prefix="ext-inspect-") as tmp:
analysis_path = Path(tmp) / "analysis.json"
check = subprocess.run(
[bin_path, "check", str(document), "--emit", str(analysis_path), "--json"],
[bin_path, "check", str(document), "--emit", str(analysis_path)],
capture_output=True,
text=True,
)
@@ -81,31 +82,30 @@ def main(argv):
).hexdigest(),
"functions": functions,
"function_digest": "sha256:" + digest.hexdigest(),
"trace": None,
"observation": None,
}
if want_trace:
trace_path = Path(tmp) / "trace.json"
observation_path = Path(tmp) / "observation.json"
run = subprocess.run(
[
bin_path,
"run",
str(document),
"--trace-file",
str(trace_path),
"--json",
"--observation-file",
str(observation_path),
],
capture_output=True,
text=True,
)
if trace_path.is_file():
trace = json.loads(trace_path.read_text(encoding="utf-8"))
payload["trace"] = {
"schema": trace.get("schema"),
"schema_version": trace.get("schema_version"),
"events": len(trace.get("events", [])),
if observation_path.is_file():
observation = json.loads(observation_path.read_text(encoding="utf-8"))
payload["observation"] = {
"schema": observation.get("schema"),
"schema_version": observation.get("schema_version"),
"events": len(observation.get("events", [])),
}
elif run.returncode != 0:
payload["trace"] = {"error": run.stderr.strip()[:500]}
payload["observation"] = {"error": run.stderr.strip()[:500]}
print(json.dumps(payload, ensure_ascii=False, sort_keys=True))
return 0
+2 -6
View File
@@ -2,12 +2,8 @@
"schema": "marqdo.cli-tool",
"schema_version": 1,
"name": "inspect-ext",
"version": "0.1.0",
"version": "0.2.0",
"command": "inspect-ext",
"entrypoint": "inspect_ext.py",
"compatibility": {
"marqdo": ">=3.0.0-beta.1,<4.0.0",
"analysis": [2],
"trace": [2]
}
"requires": {"api_revision": 1, "analysis": 3, "observation": 1}
}