refactor: move the plugin SDK to its independent repository (issue #15)
ci/woodpecker/push/main Pipeline was successful
ci/woodpecker/pr/main Pipeline was successful

Implements ADR-0072 and the SDK physical migration tracked by issue #15:

- remove crates/marqdo-plugin-sdk, tests/sdk-plugin and the CLI-side
  check_plugin_sdk.py; the public cflmy/marqdo-plugin-sdk repository now owns
  the SDK workspace, lock, fixture, docs, AGENTS rules and CI definition.
- SDK consumes marqdo-plugin-abi at the exact CLI contract rev
  2585915e16906dac75f8571bed02e7f6f868c6bc; no path/submodule/copied contract.
- CLI does not depend on the SDK and must not re-add it as a workspace member
  or copy; dependency/architecture gates enforce this.
- docs: ADR-0072, CURRENT responsibility map/dependency graph, ADR-0071
  amendment, indexes, README, spec/plugin-abi, CI and developer entries.
- evidence: clean-clone SDK build/tests and real frozen 3.0.0-rc.4 CLI
  invocation (Int 42; tampered digest rejected).

CLI workspace: 631 passed / 0 failed / 0 ignored; fmt/clippy/docs/architecture/
dependency gates green.

Refs #15, #13
This commit is contained in:
cflmy committed 2026-11-26 19:48:24 +08:00
1 parent 2585915e16
commit 3ab4aaa861
35 files changed
+272 -1454

No files matched your search

+8 -17
View File
@@ -50,7 +50,6 @@ 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",
@@ -240,22 +239,14 @@ def check_workspace(metadata: dict) -> list[str]:
f"dependency `{forbidden}`"
)
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]}"
)
# 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)"
)
# CLT Tool / package identity is a product concern; the CLI is the only
# crate allowed to combine engine + native host + package.
-164
View File
@@ -1,164 +0,0 @@
#!/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())
+9 -5
View File
@@ -82,7 +82,6 @@ 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"]
@@ -185,10 +184,15 @@ class DependencyBoundaryTests(unittest.TestCase):
"must not carry execution-side dependency `libloading`",
)
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_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_undocumented_workspace_crate_is_rejected(self) -> None: