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

-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())