feat(host): add provider package manifest v1
- Add a marqdo.provider schema v1 loader (schema/version/ABI/platform library) and StdHost::register_provider_package, reusing the C ABI adapter and shared kind/name checks (ADR-0037). - Add a compiled-provider + provider.json installation test; language use still requires project mode and allow_resource_provider. - Update ADR/spec/status/README/changelog and evidence; no registry, signature or CLI install is claimed. Gate: fmt, clippy -D warnings, 437 tests passed.
This commit is contained in:
1 parent
5e5c3a84d9
commit
974102dfc3
11 files changed
+274
-5
No files matched your search
@@ -21,7 +21,7 @@ use crate::context::ExecutionContext;
|
||||
use crate::fs::ProjectFs;
|
||||
use crate::handles::{contains_plugin_handle, PluginHandleTable};
|
||||
use crate::plugin_worker::WorkerPlugin;
|
||||
use crate::provider_c::CResourceProvider;
|
||||
use crate::provider_c::{load_package, CResourceProvider};
|
||||
use crate::provider_worker::WorkerResourceProvider;
|
||||
use crate::resource::{ResourceProvider, ResourceRead, ResourceTable, SharedResourceProvider};
|
||||
use crate::trace::{EffectTrace, SemanticEvent, TraceBudget, TraceEntry, TraceState};
|
||||
@@ -602,6 +602,17 @@ impl StdHost {
|
||||
self.register_provider_checked(Box::new(provider))
|
||||
}
|
||||
|
||||
/// Register a trusted C ABI provider from a `marqdo.provider` manifest
|
||||
/// (ADR-0037). The manifest is host-side installation metadata; language
|
||||
/// imports cannot install or authorize a provider.
|
||||
pub fn register_provider_package(
|
||||
&mut self,
|
||||
manifest_path: &std::path::Path,
|
||||
) -> Result<(), RuntimeError> {
|
||||
let provider = load_package(manifest_path)?;
|
||||
self.register_provider_checked(Box::new(provider))
|
||||
}
|
||||
|
||||
/// Register a trusted worker-process resource provider (ADR-0035).
|
||||
///
|
||||
/// The helper speaks framed JSON over stdin/stdout and is **not** an OS
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
//! and is explicitly not a sandbox; only explicitly trusted adapters may be
|
||||
//! registered.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::ffi::{c_char, CString};
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use libloading::Library;
|
||||
use marqdo_span::Span;
|
||||
@@ -23,6 +24,83 @@ type WriteFn = unsafe extern "C" fn(u64, *const u8, u32, *mut u32) -> i32;
|
||||
type CloseFn = unsafe extern "C" fn(u64) -> i32;
|
||||
type LastErrorFn = unsafe extern "C" fn(*mut c_char, u32) -> i32;
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
struct ProviderPackage {
|
||||
schema: String,
|
||||
schema_version: u32,
|
||||
name: String,
|
||||
kinds: Vec<String>,
|
||||
abi: String,
|
||||
#[serde(default)]
|
||||
library: BTreeMap<String, String>,
|
||||
}
|
||||
|
||||
/// Load a C ABI provider from its package manifest (ADR-0037).
|
||||
pub(crate) fn load_package(manifest_path: &Path) -> Result<CResourceProvider, RuntimeError> {
|
||||
let bytes = std::fs::read(manifest_path).map_err(|error| {
|
||||
RuntimeError::new(
|
||||
ErrorCategory::ResourceUnsupported,
|
||||
None,
|
||||
format!(
|
||||
"cannot read provider manifest {}: {error}",
|
||||
manifest_path.display()
|
||||
),
|
||||
)
|
||||
})?;
|
||||
let package: ProviderPackage = serde_json::from_slice(&bytes).map_err(|error| {
|
||||
RuntimeError::new(
|
||||
ErrorCategory::ResourceUnsupported,
|
||||
None,
|
||||
format!(
|
||||
"invalid provider manifest {}: {error}",
|
||||
manifest_path.display()
|
||||
),
|
||||
)
|
||||
})?;
|
||||
if package.schema != "marqdo.provider" || package.schema_version != 1 {
|
||||
return Err(provider_error(
|
||||
&package.name,
|
||||
"manifest schema must be marqdo.provider version 1",
|
||||
));
|
||||
}
|
||||
if package.abi != "c-abi-1" {
|
||||
return Err(provider_error(
|
||||
&package.name,
|
||||
&format!(
|
||||
"unsupported provider ABI `{}` (expected c-abi-1)",
|
||||
package.abi
|
||||
),
|
||||
));
|
||||
}
|
||||
let platform = if cfg!(target_os = "linux") {
|
||||
"linux"
|
||||
} else if cfg!(target_os = "macos") {
|
||||
"macos"
|
||||
} else if cfg!(target_os = "windows") {
|
||||
"windows"
|
||||
} else {
|
||||
"default"
|
||||
};
|
||||
let library_name = package
|
||||
.library
|
||||
.get(platform)
|
||||
.or_else(|| package.library.get("default"))
|
||||
.ok_or_else(|| {
|
||||
provider_error(
|
||||
&package.name,
|
||||
&format!("manifest has no `{platform}` or `default` library entry"),
|
||||
)
|
||||
})?;
|
||||
let base = manifest_path.parent().unwrap_or_else(|| Path::new("."));
|
||||
let library = PathBuf::from(library_name);
|
||||
let library = if library.is_absolute() {
|
||||
library
|
||||
} else {
|
||||
base.join(library)
|
||||
};
|
||||
CResourceProvider::open(&package.name, &package.kinds, &library)
|
||||
}
|
||||
|
||||
pub(crate) struct CResourceProvider {
|
||||
name: String,
|
||||
kinds: Vec<String>,
|
||||
|
||||
@@ -194,3 +194,48 @@ fn c_abi_version_mismatch_and_modes_fail_closed() {
|
||||
assert_eq!(error.category, ErrorCategory::PermissionDenied);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_package_manifest_installs_a_c_abi_library() {
|
||||
if !cc_available() {
|
||||
eprintln!("skipping C provider test: cc is unavailable");
|
||||
return;
|
||||
}
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let library = build_provider(dir.path());
|
||||
let manifest = dir.path().join("provider.json");
|
||||
let platform = if cfg!(target_os = "linux") {
|
||||
"linux"
|
||||
} else if cfg!(target_os = "macos") {
|
||||
"macos"
|
||||
} else {
|
||||
"default"
|
||||
};
|
||||
std::fs::write(
|
||||
&manifest,
|
||||
serde_json::json!({
|
||||
"schema": "marqdo.provider",
|
||||
"schema_version": 1,
|
||||
"name": "cabi",
|
||||
"kinds": ["cabi.sensor"],
|
||||
"abi": "c-abi-1",
|
||||
"library": { platform: library.file_name().unwrap().to_string_lossy() }
|
||||
})
|
||||
.to_string(),
|
||||
)
|
||||
.unwrap();
|
||||
let project = tempfile::tempdir().unwrap();
|
||||
let mut host = StdHost::new(
|
||||
SandboxMode::Project,
|
||||
Capabilities::project().allow_resource_provider("cabi"),
|
||||
project.path(),
|
||||
);
|
||||
host.register_provider_package(&manifest).unwrap();
|
||||
let ctx = context();
|
||||
let handle = handle(
|
||||
host.resource_open("cabi.sensor", "s", &["read".to_string()], &ctx)
|
||||
.unwrap(),
|
||||
);
|
||||
let read = host.resource_read(handle, 2, &ctx).unwrap();
|
||||
assert_eq!(read.bytes, b"c-");
|
||||
}
|
||||
Reference in new issue
Block a user