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
+6
-5
@@ -5,7 +5,7 @@ works" claim. Unknown/newer protocol versions fail closed.
|
|||||||
|
|
||||||
| Contract | Version used here | Required by |
|
| 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 |
|
| Language semantics | RFC-LANG-0002 / ADR-0052 (one Markdown→program mapping) | `.mq.md` fixtures |
|
||||||
| Markdown profile | `marqdo.md.v1` | all documents |
|
| 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/` |
|
| 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/` |
|
| 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 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/` |
|
| Resource provider worker protocol | ADR-0035 framed JSON (host ↔ helper) + C ABI v1 (helper ↔ library) | `provider/` |
|
||||||
| Analysis | Analysis v2 (`marqdo check --emit`) | `tool/` |
|
| Analysis | current Analysis (`marqdo check --emit`) | `tool/` |
|
||||||
| Trace | Trace v2 (`marqdo run --trace-file`) | `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/` |
|
| CLI Tool Protocol | v1 (`marqdo.cli-tool`, schema_version 1) | `tool/` |
|
||||||
|
|
||||||
## Platform matrix
|
## Platform matrix
|
||||||
@@ -37,8 +37,9 @@ the committed manifests contain zero digests and are templates only.
|
|||||||
consumer never resolves a branch or "latest".
|
consumer never resolves a branch or "latest".
|
||||||
* The plugin/provider manifests are matched against the static descriptor and
|
* The plugin/provider manifests are matched against the static descriptor and
|
||||||
the loaded artifact; a changed byte fails before the entry function runs.
|
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
|
* Analysis/Observation evidence is consumed as public JSON only; no private
|
||||||
is linked or copied.
|
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
|
## Grants and failure behaviour
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
future reads. Interrupting an in-flight read requires a later resource protocol.
|
||||||
|
|
||||||
```sh
|
```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
@@ -29,8 +29,17 @@ def args(cli, source, function, url, *, grant=True, **extra):
|
|||||||
|
|
||||||
|
|
||||||
def typed_value(result):
|
def typed_value(result):
|
||||||
|
"""Read the explicit return of one current Observation snapshot."""
|
||||||
assert result.returncode == 0, result.stderr or result.stdout
|
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):
|
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=""):
|
def request(cli, respond, *, tls=None, env=None, method="GET", body=""):
|
||||||
with server(respond, tls=tls) as url:
|
with server(respond, tls=tls) as url:
|
||||||
cmd = args(cli, NET, "request", url + "/demo?q=ready", method=method, body=body)
|
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)
|
text=True, timeout=20)
|
||||||
return typed_value(result)
|
return typed_value(result)
|
||||||
|
|
||||||
@@ -174,7 +183,7 @@ def denied(cli):
|
|||||||
run = subprocess.run(args(cli, NET, "request", url, grant=False),
|
run = subprocess.run(args(cli, NET, "request", url, grant=False),
|
||||||
capture_output=True, text=True, timeout=10)
|
capture_output=True, text=True, timeout=10)
|
||||||
assert run.returncode == 1 and "permission.denied" in run.stderr, run
|
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)
|
capture_output=True, text=True, timeout=10)
|
||||||
assert_result(typed_value(injected), ok=False, code="http.url")
|
assert_result(typed_value(injected), ok=False, code="http.url")
|
||||||
listener.setblocking(False)
|
listener.setblocking(False)
|
||||||
@@ -232,7 +241,7 @@ def live_sse(cli):
|
|||||||
assert connection.recv(1) == b"", "client did not close after the second event"
|
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:
|
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()
|
output = bytearray()
|
||||||
terminal = None
|
terminal = None
|
||||||
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=diagnostics) as process:
|
with subprocess.Popen(command, stdout=subprocess.PIPE, stderr=diagnostics) as process:
|
||||||
@@ -275,7 +284,7 @@ def agent(cli):
|
|||||||
def ask(url, tools):
|
def ask(url, tools):
|
||||||
command = args(cli, project / "index.mq.md", "ask", url,
|
command = args(cli, project / "index.mq.md", "ask", url,
|
||||||
query="How many?", tools=tools)
|
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))
|
capture_output=True, text=True, timeout=20))
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
|
|||||||
+22
-7
@@ -53,6 +53,20 @@ class Case:
|
|||||||
error_codes: list[str] = field(default_factory=list)
|
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:
|
class Runner:
|
||||||
def __init__(self, cli: Path) -> None:
|
def __init__(self, cli: Path) -> None:
|
||||||
self.cli = cli
|
self.cli = cli
|
||||||
@@ -298,13 +312,14 @@ class Runner:
|
|||||||
str(build / "provider.json"),
|
str(build / "provider.json"),
|
||||||
"--allow-provider",
|
"--allow-provider",
|
||||||
"demo.sensor",
|
"demo.sensor",
|
||||||
"--json",
|
"--output",
|
||||||
|
"json",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
self.finish(case, result, 0)
|
self.finish(case, result, 0)
|
||||||
if case.status == "PASS":
|
if case.status == "PASS":
|
||||||
payload = json.loads(result.stdout)
|
value = completed_value(result.stdout)
|
||||||
if payload.get("value") != {"type": "int", "decimal": "5"}:
|
if value != {"type": "int", "decimal": "5"}:
|
||||||
case.status = "FAIL"
|
case.status = "FAIL"
|
||||||
case.detail = f"unexpected provider value: {result.stdout[:500]}"
|
case.detail = f"unexpected provider value: {result.stdout[:500]}"
|
||||||
|
|
||||||
@@ -404,7 +419,7 @@ class Runner:
|
|||||||
|
|
||||||
def check_tool(self) -> None:
|
def check_tool(self) -> None:
|
||||||
case = self.case(
|
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-"))
|
home = Path(tempfile.mkdtemp(prefix="ext-tool-home-"))
|
||||||
try:
|
try:
|
||||||
@@ -487,11 +502,11 @@ class Runner:
|
|||||||
)
|
)
|
||||||
check = self.run(["check", "index.mq.md"], cwd=consumer)
|
check = self.run(["check", "index.mq.md"], cwd=consumer)
|
||||||
ok = self.finish(case, check, 0)
|
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)
|
ok = ok and self.finish(case, run, 0)
|
||||||
if ok:
|
if ok:
|
||||||
payload = json.loads(run.stdout)
|
value = completed_value(run.stdout)
|
||||||
if payload.get("value") != {"type": "int", "decimal": "18"}:
|
if value != {"type": "int", "decimal": "18"}:
|
||||||
case.status = "FAIL"
|
case.status = "FAIL"
|
||||||
case.detail = f"unexpected consumer value: {run.stdout[:500]}"
|
case.detail = f"unexpected consumer value: {run.stdout[:500]}"
|
||||||
ok = False
|
ok = False
|
||||||
|
|||||||
+20
-20
@@ -1,16 +1,17 @@
|
|||||||
#!/usr/bin/env python3
|
#!/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>`
|
Consumes only public contracts: `$MARQDO_BIN check <doc> --emit <analysis>`
|
||||||
(Analysis v2) and optionally `$MARQDO_BIN run <doc> --trace-file <trace>`
|
(current Analysis) and optionally `$MARQDO_BIN run <doc> --observation-file
|
||||||
(Trace v2). It links no Rust crate and reads no CLI source tree.
|
<snapshot>` (current Observation). It links no Rust crate and reads no CLI
|
||||||
|
source tree.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
marqdo inspect-ext <document.mq.md> [--trace]
|
marqdo inspect-ext <document.mq.md> [--observe]
|
||||||
|
|
||||||
Prints one deterministic JSON object:
|
Prints one deterministic JSON object:
|
||||||
{"schema":"ext.inspect.v1","document":...,"functions":[...],
|
{"schema":"ext.inspect.v1","document":...,"functions":[...],
|
||||||
"function_digest":"sha256:...", "trace": {...}|null}
|
"function_digest":"sha256:...", "observation": {...}|null}
|
||||||
"""
|
"""
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
@@ -30,9 +31,9 @@ def fail(message, code=2):
|
|||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
args = [arg for arg in argv[1:] if not arg.startswith("--")]
|
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:
|
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")
|
bin_path = os.environ.get("MARQDO_BIN")
|
||||||
if not bin_path:
|
if not bin_path:
|
||||||
return fail("MARQDO_BIN is not set; install through `marqdo tool install`")
|
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:
|
with tempfile.TemporaryDirectory(prefix="ext-inspect-") as tmp:
|
||||||
analysis_path = Path(tmp) / "analysis.json"
|
analysis_path = Path(tmp) / "analysis.json"
|
||||||
check = subprocess.run(
|
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,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
@@ -81,31 +82,30 @@ def main(argv):
|
|||||||
).hexdigest(),
|
).hexdigest(),
|
||||||
"functions": functions,
|
"functions": functions,
|
||||||
"function_digest": "sha256:" + digest.hexdigest(),
|
"function_digest": "sha256:" + digest.hexdigest(),
|
||||||
"trace": None,
|
"observation": None,
|
||||||
}
|
}
|
||||||
if want_trace:
|
if want_trace:
|
||||||
trace_path = Path(tmp) / "trace.json"
|
observation_path = Path(tmp) / "observation.json"
|
||||||
run = subprocess.run(
|
run = subprocess.run(
|
||||||
[
|
[
|
||||||
bin_path,
|
bin_path,
|
||||||
"run",
|
"run",
|
||||||
str(document),
|
str(document),
|
||||||
"--trace-file",
|
"--observation-file",
|
||||||
str(trace_path),
|
str(observation_path),
|
||||||
"--json",
|
|
||||||
],
|
],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
)
|
)
|
||||||
if trace_path.is_file():
|
if observation_path.is_file():
|
||||||
trace = json.loads(trace_path.read_text(encoding="utf-8"))
|
observation = json.loads(observation_path.read_text(encoding="utf-8"))
|
||||||
payload["trace"] = {
|
payload["observation"] = {
|
||||||
"schema": trace.get("schema"),
|
"schema": observation.get("schema"),
|
||||||
"schema_version": trace.get("schema_version"),
|
"schema_version": observation.get("schema_version"),
|
||||||
"events": len(trace.get("events", [])),
|
"events": len(observation.get("events", [])),
|
||||||
}
|
}
|
||||||
elif run.returncode != 0:
|
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))
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True))
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
+2
-6
@@ -2,12 +2,8 @@
|
|||||||
"schema": "marqdo.cli-tool",
|
"schema": "marqdo.cli-tool",
|
||||||
"schema_version": 1,
|
"schema_version": 1,
|
||||||
"name": "inspect-ext",
|
"name": "inspect-ext",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"command": "inspect-ext",
|
"command": "inspect-ext",
|
||||||
"entrypoint": "inspect_ext.py",
|
"entrypoint": "inspect_ext.py",
|
||||||
"compatibility": {
|
"requires": {"api_revision": 1, "analysis": 3, "observation": 1}
|
||||||
"marqdo": ">=3.0.0-beta.1,<4.0.0",
|
|
||||||
"analysis": [2],
|
|
||||||
"trace": [2]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user