refactor: keep the plugin SDK in the CLI workspace (revert split)
ci/woodpecker/push/main Pipeline was successful

The pre-stable line prioritizes atomic ABI/header/spec/SDK/loader changes over
a premature repository boundary. ADR-0073 supersedes ADR-0072:

- restore crates/marqdo-plugin-sdk as a contract-only CLI workspace crate
  (marqdo-plugin-abi + serde; no loader/host/worker dependency);
- restore tests/sdk-plugin and tools/ci/check_plugin_sdk.py, including the real
  CLI invocation and tampered-digest negative case;
- restore workspace/lock/architecture/dependency/docs/CI references; the SDK is
  a reviewed workspace member again and must not become a remote repo, mirror
  or submodule in this stage;
- ADR-0072 and the old issue #15 evidence are marked superseded; ADR-0073 and
  the split-revert evidence record the decision and the deleted remote repo;
- logical ADR-0071 boundaries are unchanged.

Workspace: 636 passed / 0 failed / 2 ignored; fmt, clippy, docs, architecture,
dependency, SDK gate and engine differential all PASS.

Refs #13, #15
This commit is contained in:
cflmy committed 2026-11-26 21:21:41 +08:00
1 parent 89acb709c6
commit 98d256f5a2
34 files changed
+1661 -85

No files matched your search

+17 -8
View File
@@ -50,6 +50,7 @@ WORKSPACE_CRATES = {
"marqdo-sandbox": "native host support: OS isolation probe and strict launch",
"marqdo-foreign": "native host support: controlled one-shot foreign kernels (F-A)",
"marqdo-plugin-abi": "public contract: C ABI types, wire envelope and protocol errors",
"marqdo-plugin-sdk": "public contract consumer: third-party plugin development helpers",
"marqdo-worker-ipc": "shared plumbing: one bounded worker frame transport",
"marqdo-provider-worker": "shipped worker: provider helper process",
"marqdo-package": "product support: project manifest, lock and dependency resolution",
@@ -239,14 +240,22 @@ def check_workspace(metadata: dict) -> list[str]:
f"dependency `{forbidden}`"
)
# ADR-0072: the SDK is an independent repository. The CLI workspace must
# not carry it again; a new member here would be an undocumented layer and
# would resurrect a second contract-consumer copy.
if "marqdo-plugin-sdk" in members:
problems.append(
"marqdo-plugin-sdk must not be a CLI workspace member; the SDK is the "
"independent repository pinned to a contract revision (ADR-0072)"
)
sdk = "marqdo-plugin-sdk"
if sdk in graph:
closure = reachable(graph, sdk, BUILD_KINDS)
for forbidden in (
"libloading",
"marqdo-worker-ipc",
"marqdo-host",
"marqdo-sandbox",
"marqdo-cli",
"marqdo-provider-worker",
):
if forbidden in closure:
problems.append(
f"plugin SDK reaches execution-side dependency `{forbidden}`: "
f"{closure[forbidden]}"
)
# CLT Tool / package identity is a product concern; the CLI is the only
# crate allowed to combine engine + native host + package.
+164
View File
@@ -0,0 +1,164 @@
#!/usr/bin/env python3
"""Real third-party plugin SDK consumption gate (issue #13 §6.3, S04-S05).
Builds the fixture in ``tests/sdk-plugin`` with only the public Rust SDK, creates
the host-specific ``plugin.yaml``, then lets a real built CLI load and invoke it
with explicit trust and an explicit plugin grant. A tampered digest must fail
closed. No mock host, no direct Rust call into plugin internals.
Usage:
python3 tools/ci/check_plugin_sdk.py [--offline]
"""
from __future__ import annotations
import argparse
import hashlib
import platform
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
FIXTURE = REPO_ROOT / "tests" / "sdk-plugin"
CALL_DOC = FIXTURE / "call.mq.md"
class GateError(Exception):
pass
def cargo() -> str:
path = shutil.which("cargo")
if path is None:
raise GateError("cargo is not on PATH")
return path
def run(command: list[str], *, check: bool = True) -> subprocess.CompletedProcess:
result = subprocess.run(
command, cwd=REPO_ROOT, capture_output=True, text=True, check=False
)
if check and result.returncode != 0:
raise GateError(
f"`{' '.join(command)}` failed with {result.returncode}:\n"
f"{result.stdout}\n{result.stderr}"
)
return result
def host_triple() -> str:
result = run(["rustc", "-vV"])
for line in result.stdout.splitlines():
if line.startswith("host: "):
return line[len("host: ") :].strip()
raise GateError("rustc -vV did not report a host triple")
def artifact_name() -> str:
system = platform.system()
if system == "Darwin":
return "libmarqdo_sdk_plugin_fixture.dylib"
if system == "Windows":
return "marqdo_sdk_plugin_fixture.dll"
return "libmarqdo_sdk_plugin_fixture.so"
def write_manifest(
directory: Path,
digest: str,
triple: str,
artifact: str,
*,
tamper: bool = False,
) -> None:
effective = "0" * 64 if tamper else digest
manifest = f"""plugin:
name: sdk.demo
version: 0.1.0
abi: "^1.0"
kind: native
exports:
- name: sdk.add
signature: "($a: Int, $b: Int) -> Int"
- name: sdk.echo
signature: "($text: Text) -> Text"
artifacts:
- target: {triple}
file: {artifact}
sha256: "{effective}"
"""
(directory / "plugin.yaml").write_text(manifest, encoding="utf-8")
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--offline", action="store_true")
parser.add_argument(
"--sdk-revision",
default=None,
help="informational: exact CLI/SDK source revision under test",
)
arguments = parser.parse_args()
offline = ["--offline"] if arguments.offline else []
try:
run([cargo(), "build", "--locked", "-p", "marqdo-cli", *offline])
run([cargo(), "build", "--locked", "--manifest-path", str(FIXTURE / "Cargo.toml"), *offline])
name = artifact_name()
built = FIXTURE / "target" / "debug" / name
if not built.is_file():
raise GateError(f"SDK fixture artifact not found: {built}")
triple = host_triple()
binary = REPO_ROOT / "target" / "debug" / "marqdo"
if not binary.is_file():
raise GateError(f"CLI binary not found: {binary}")
with tempfile.TemporaryDirectory(prefix="marqdo-sdk-plugin-") as raw:
directory = Path(raw)
artifact = "plugin" + Path(name).suffix
shutil.copyfile(built, directory / artifact)
digest = hashlib.sha256((directory / artifact).read_bytes()).hexdigest()
command = [
str(binary),
"call",
str(CALL_DOC),
"main",
"--plugin",
str(directory),
"--trust-native-plugin",
"--allow-plugin",
"sdk.demo",
]
write_manifest(directory, digest, triple, artifact)
positive = run(command, check=False)
if positive.returncode != 0 or positive.stdout.strip() != "42":
raise GateError(
"real CLI could not invoke the SDK plugin: "
f"exit={positive.returncode} stdout={positive.stdout!r} "
f"stderr={positive.stderr!r}"
)
print("PASS sdk-plugin-real-invocation (Int 42)")
write_manifest(directory, digest, triple, artifact, tamper=True)
negative = run(command, check=False)
if negative.returncode == 0:
raise GateError("tampered plugin artifact digest was accepted")
combined = negative.stdout + negative.stderr
if "sha256" not in combined.lower() and "artifact" not in combined.lower():
raise GateError(
"tampered artifact failed without an artifact/sha256 diagnostic: "
+ combined
)
print("PASS sdk-plugin-tampered-digest-rejected")
except GateError as error:
print(f"FAIL plugin-sdk: {error}", file=sys.stderr)
return 1
print("PASS plugin-sdk")
return 0
if __name__ == "__main__":
sys.exit(main())
+5 -9
View File
@@ -82,6 +82,7 @@ def valid_workspace_edges() -> dict[str, list[str]]:
"marqdo-span",
]
edges["marqdo-plugin-abi"] = ["marqdo-value"]
edges["marqdo-plugin-sdk"] = ["marqdo-plugin-abi"]
edges["marqdo-worker-ipc"] = []
edges["marqdo-sandbox"] = []
edges["marqdo-foreign"] = ["marqdo-worker-ipc"]
@@ -184,15 +185,10 @@ class DependencyBoundaryTests(unittest.TestCase):
"must not carry execution-side dependency `libloading`",
)
def test_sdk_reappearing_as_workspace_member_is_rejected(self) -> None:
edges = valid_workspace_edges()
edges["marqdo-plugin-sdk"] = ["marqdo-plugin-abi"]
workspace = metadata(edges, members=set(gate.WORKSPACE_CRATES) | {"marqdo-plugin-sdk"})
consumer = metadata(valid_consumer_edges(), members={"marqdo-embedding-consumer"})
problems = gate.evaluate(workspace, consumer)
self.assertTrue(
any("must not be a CLI workspace member" in problem for problem in problems),
problems,
def test_sdk_host_edge_is_rejected(self) -> None:
self.assert_rejected(
lambda edges: edges["marqdo-plugin-sdk"].append("marqdo-host"),
"plugin SDK reaches execution-side dependency `marqdo-host`",
)
def test_undocumented_workspace_crate_is_rejected(self) -> None: