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
+20
-20
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user