diff --git a/crates/marqdo-host/tests/c_provider.rs b/crates/marqdo-host/tests/c_provider.rs index b59e49f..203d7a9 100644 --- a/crates/marqdo-host/tests/c_provider.rs +++ b/crates/marqdo-host/tests/c_provider.rs @@ -26,7 +26,7 @@ fn cc_available() -> bool { .unwrap_or(false) } -fn build_provider(dir: &Path) -> PathBuf { +fn build_provider_with_version(dir: &Path, version: u32) -> PathBuf { let source = dir.join("provider.c"); std::fs::write( &source, @@ -39,7 +39,10 @@ static const char DATA[] = "c-abi"; static size_t position = 0; static uint64_t next_token = 1; -uint32_t marqdo_resource_provider_abi_version(void) { return 1u; } +#ifndef PROVIDER_VERSION +#define PROVIDER_VERSION 1u +#endif +uint32_t marqdo_resource_provider_abi_version(void) { return PROVIDER_VERSION; } int32_t marqdo_resource_open(const char *kind, const char *descriptor, const char *rights_csv, uint64_t *out_token) { @@ -85,7 +88,13 @@ int32_t marqdo_resource_last_error(char *buffer, uint32_t capacity) { }; let library = dir.join(format!("libecho_provider.{extension}")); let status = Command::new("cc") - .args(["-shared", "-fPIC", "-O2", "-o"]) + .args([ + "-shared", + "-fPIC", + "-O2", + &format!("-DPROVIDER_VERSION={version}"), + "-o", + ]) .arg(&library) .arg(&source) .status() @@ -94,6 +103,10 @@ int32_t marqdo_resource_last_error(char *buffer, uint32_t capacity) { library } +fn build_provider(dir: &Path) -> PathBuf { + build_provider_with_version(dir, 1) +} + #[test] fn c_abi_provider_round_trips() { if !cc_available() { @@ -146,3 +159,38 @@ fn c_abi_provider_loading_fails_closed() { .unwrap_err(); assert_eq!(error.category, ErrorCategory::KernelUnavailable); } + +#[test] +fn c_abi_version_mismatch_and_modes_fail_closed() { + if !cc_available() { + eprintln!("skipping C provider test: cc is unavailable"); + return; + } + let dir = tempfile::tempdir().unwrap(); + let wrong = build_provider_with_version(dir.path(), 2); + let project = tempfile::tempdir().unwrap(); + let mut host = StdHost::new( + SandboxMode::Project, + Capabilities::project().allow_resource_provider("cabi"), + project.path(), + ); + let error = host + .register_c_resource_provider("cabi", &["cabi.sensor"], &wrong) + .unwrap_err(); + assert_eq!(error.category, ErrorCategory::ResourceUnsupported); + + let good = build_provider(dir.path()); + for mode in [SandboxMode::Pure, SandboxMode::Strict] { + let mut host = StdHost::new( + mode, + Capabilities::project().allow_resource_provider("cabi"), + project.path(), + ); + host.register_c_resource_provider("cabi", &["cabi.sensor"], &good) + .unwrap(); + let error = host + .resource_open("cabi.sensor", "s", &["read".to_string()], &context()) + .unwrap_err(); + assert_eq!(error.category, ErrorCategory::PermissionDenied); + } +} diff --git a/docs/evidence/2026-11-20-c-provider.md b/docs/evidence/2026-11-20-c-provider.md index 050a780..d905668 100644 --- a/docs/evidence/2026-11-20-c-provider.md +++ b/docs/evidence/2026-11-20-c-provider.md @@ -33,7 +33,9 @@ token enter a language `Value`, wire frame or trace. grant; 3. `resource.open/read/write/close` round-trips `c-`/`abi`, `write=3`, second close `resource.closed`; -4. a missing library path fails with `kernel.unavailable`. +4. a missing library path fails with `kernel.unavailable`; +5. a library reporting ABI version 2 fails with `resource.unsupported`; +6. pure/strict refuse the C provider kind with `permission.denied`. No Rust runtime/`HostOp`/parser change was needed; language code still sees the same `resource.*` surface. diff --git a/tests/README.md b/tests/README.md index 9148927..e401f2c 100644 --- a/tests/README.md +++ b/tests/README.md @@ -179,8 +179,8 @@ grant/pure/strict/DNS refusal) and RFC-CM CM-A09 C ABI provider (ADR-0036) is pinned by `crates/marqdo-host/tests/c_provider.rs`, which compiles a small C shared -library, registers it, round-trips `resource.*` and checks missing-library -fail-closed behavior. +library, registers it, round-trips `resource.*`, checks missing-library, +wrong-ABI-version and pure/strict fail-closed behavior. RFC-CM CM-A09 worker provider transport (ADR-0035) is pinned by `crates/marqdo-host/tests/worker_provider.rs`: a Python helper is spawned,