feat(m0.6-r6): release examples, public schemas and cross-platform CI
- add runnable examples for an unknown-name Tool, multi-export plugin, external kernel provider and same-name multi-version packages - add JSON Schemas for Analysis v1, Trace v1 and Tool v1 and validate them in CI - extend CI with protocol/consumer smoke tests and a Windows/macOS cargo check - add --kernel provider descriptors and R6 example integration tests - document the examples and update M0.6 status
This commit is contained in:
1 parent
54c7b43d15
commit
4ce37afb39
31 files changed
+537
-5
No files matched your search
@@ -40,6 +40,8 @@ pub struct SandboxSettings {
|
||||
pub trust_native_plugin: bool,
|
||||
/// Optional Trace v1 output path.
|
||||
pub trace_file: Option<PathBuf>,
|
||||
/// External foreign-kernel descriptor paths.
|
||||
pub kernels: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl SandboxSettings {
|
||||
@@ -698,6 +700,16 @@ pub fn execute(
|
||||
if let Some(timeout) = settings.timeout {
|
||||
host.budget.deadline = Some(Instant::now() + Duration::from_secs(timeout));
|
||||
}
|
||||
for kernel_path in &settings.kernels {
|
||||
if let Err(error) = load_kernel_descriptor(&mut host, kernel_path) {
|
||||
if json {
|
||||
output::print_json(&json!({"success": false, "error": error}));
|
||||
} else {
|
||||
eprintln!("error: {error}");
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
for plugin_path in &settings.plugins {
|
||||
if let Err(message) =
|
||||
load_plugin_into_host(&mut host, plugin_path, settings.trust_native_plugin)
|
||||
@@ -822,6 +834,36 @@ pub fn execute(
|
||||
}
|
||||
}
|
||||
|
||||
fn load_kernel_descriptor(host: &mut StdHost, path: &Path) -> Result<(), String> {
|
||||
let text = std::fs::read_to_string(path).map_err(|error| {
|
||||
format!(
|
||||
"cannot read kernel descriptor `{}`: {error}",
|
||||
path.display()
|
||||
)
|
||||
})?;
|
||||
let mut descriptor: marqdo_foreign::KernelDescriptor = serde_json::from_str(&text)
|
||||
.map_err(|error| format!("invalid kernel descriptor `{}`: {error}", path.display()))?;
|
||||
if descriptor.builtin {
|
||||
return Err("external kernel descriptors must not set `builtin: true`".to_string());
|
||||
}
|
||||
if descriptor.entrypoint.is_relative() {
|
||||
let base = path.parent().unwrap_or_else(|| Path::new("."));
|
||||
descriptor.entrypoint = base.join(&descriptor.entrypoint);
|
||||
}
|
||||
descriptor.entrypoint = descriptor
|
||||
.entrypoint
|
||||
.canonicalize()
|
||||
.map_err(|error| format!("cannot open kernel provider: {error}"))?;
|
||||
if !descriptor.entrypoint.is_file() {
|
||||
return Err(format!(
|
||||
"kernel provider executable `{}` does not exist",
|
||||
descriptor.entrypoint.display()
|
||||
));
|
||||
}
|
||||
host.register_kernel(descriptor)
|
||||
.map_err(|error| format!("{}: {}", error.code(), error.message))
|
||||
}
|
||||
|
||||
fn load_plugin_into_host(
|
||||
host: &mut StdHost,
|
||||
path: &Path,
|
||||
|
||||
@@ -101,6 +101,9 @@ struct SandboxArgs {
|
||||
/// Write a versioned Trace v1 file for this run.
|
||||
#[arg(long = "trace-file", value_name = "PATH")]
|
||||
trace_file: Option<PathBuf>,
|
||||
/// Register an external foreign-kernel provider (repeatable).
|
||||
#[arg(long = "kernel", value_name = "PATH")]
|
||||
kernel: Vec<PathBuf>,
|
||||
/// Explicitly trust in-process native plugin loading (unsafe by nature).
|
||||
#[arg(long = "trust-native-plugin")]
|
||||
trust_native_plugin: bool,
|
||||
@@ -121,6 +124,7 @@ impl SandboxArgs {
|
||||
plugins: self.plugin.clone(),
|
||||
trust_native_plugin: self.trust_native_plugin,
|
||||
trace_file: self.trace_file.clone(),
|
||||
kernels: self.kernel.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
//! R6 integration examples that do not require an official external repo.
|
||||
#![cfg(unix)]
|
||||
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Output};
|
||||
|
||||
fn repo() -> &'static Path {
|
||||
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn cli(args: &[&str]) -> Output {
|
||||
Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(args)
|
||||
.current_dir(repo())
|
||||
.output()
|
||||
.expect("run marqdo")
|
||||
}
|
||||
|
||||
fn stderr(output: &Output) -> String {
|
||||
String::from_utf8_lossy(&output.stderr).to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_version_packages_run_without_an_implicit_override() {
|
||||
let output = cli(&["run", "examples/packages-multi-version/index.mq.md"]);
|
||||
assert_eq!(output.status.code(), Some(0), "{}", stderr(&output));
|
||||
assert_eq!(String::from_utf8_lossy(&output.stdout), "1\n2\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn external_kernel_provider_runs_without_core_changes() {
|
||||
let output = cli(&[
|
||||
"run",
|
||||
"examples/kernel-mock/demo.mq.md",
|
||||
"--kernel",
|
||||
"examples/kernel-mock/kernel.json",
|
||||
"--allow-foreign",
|
||||
]);
|
||||
assert_eq!(output.status.code(), Some(0), "{}", stderr(&output));
|
||||
assert_eq!(String::from_utf8_lossy(&output.stdout), "42\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unknown_tool_name_installs_and_dispatches() {
|
||||
let home = std::env::temp_dir().join(format!(
|
||||
"marqdo-r6-tool-home-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos()
|
||||
));
|
||||
let install = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["tool", "install", "examples/tool-unknown-name/tool.json"])
|
||||
.env("MARQDO_TOOL_HOME", &home)
|
||||
.current_dir(repo())
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(install.status.code(), Some(0), "{}", stderr(&install));
|
||||
let run = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["benchmark", "run", "."])
|
||||
.env("MARQDO_TOOL_HOME", &home)
|
||||
.current_dir(repo())
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(run.status.code(), Some(0), "{}", stderr(&run));
|
||||
assert!(String::from_utf8_lossy(&run.stdout).contains("arg=run"));
|
||||
let remove = Command::new(env!("CARGO_BIN_EXE_marqdo"))
|
||||
.args(["tool", "remove", "benchmark"])
|
||||
.env("MARQDO_TOOL_HOME", &home)
|
||||
.current_dir(repo())
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(remove.status.code(), Some(0), "{}", stderr(&remove));
|
||||
let _ = std::fs::remove_dir_all(home);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_schemas_are_valid_json_and_versioned() {
|
||||
for name in ["analysis-v1", "trace-v1", "tool-v1"] {
|
||||
let path = repo()
|
||||
.join("spec/schemas")
|
||||
.join(format!("{name}.schema.json"));
|
||||
let schema: serde_json::Value =
|
||||
serde_json::from_slice(&std::fs::read(&path).unwrap()).unwrap();
|
||||
assert_eq!(
|
||||
schema["$schema"],
|
||||
"https://json-schema.org/draft/2020-12/schema"
|
||||
);
|
||||
assert!(schema["title"].is_string());
|
||||
assert!(schema["type"].as_str() == Some("object"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user