Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions crates/ironclaw_architecture/tests/reborn_dependency_boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ fn reborn_host_runtime_services_do_not_expose_lower_substrate_handles() {
let services =
std::fs::read_to_string(root.join("crates/ironclaw_host_runtime/src/services.rs"))
.expect("host runtime services.rs must be readable");
let scripts = std::fs::read_to_string(root.join("crates/ironclaw_scripts/src/lib.rs"))
.expect("script runtime lib.rs must be readable");
let scripts_manifest = std::fs::read_to_string(root.join("crates/ironclaw_scripts/Cargo.toml"))
.expect("script runtime Cargo.toml must be readable");
let mcp = std::fs::read_to_string(root.join("crates/ironclaw_mcp/src/lib.rs"))
.expect("MCP runtime lib.rs must be readable");
let mcp_manifest = std::fs::read_to_string(root.join("crates/ironclaw_mcp/Cargo.toml"))
.expect("MCP runtime Cargo.toml must be readable");

let forbidden_lib_exports = [
"RuntimeDispatchProcessExecutor",
Expand Down Expand Up @@ -182,6 +190,39 @@ fn reborn_host_runtime_services_do_not_expose_lower_substrate_handles() {
"HostRuntimeServices must not expose lower substrate escape hatch `{pattern}`; keep dispatcher/capability/process handles private to the host-runtime crate"
);
}

let forbidden_script_lane_surface = [
"RuntimeAdapter",
"pub struct ScriptRuntimeAdapter",
"pub fn script_error_kind",
];
for pattern in forbidden_script_lane_surface {
assert!(
!scripts.contains(pattern),
"ironclaw_scripts must not expose host-runtime dispatcher composition surface `{pattern}`; compose script dispatch adapters inside ironclaw_host_runtime"
);
}

assert!(
!scripts_manifest.contains("ironclaw_dispatcher"),
"ironclaw_scripts must not depend on ironclaw_dispatcher; script dispatcher adapters are host-runtime-private composition"
);

let forbidden_mcp_lane_surface = [
"RuntimeAdapter",
"pub struct McpRuntimeAdapter",
"pub fn mcp_error_kind",
];
for pattern in forbidden_mcp_lane_surface {
assert!(
!mcp.contains(pattern),
"ironclaw_mcp must not expose host-runtime dispatcher composition surface `{pattern}`; compose MCP dispatch adapters inside ironclaw_host_runtime"
);
}
assert!(
!mcp_manifest.contains("ironclaw_dispatcher"),
"ironclaw_mcp must not depend on ironclaw_dispatcher; MCP dispatcher adapters are host-runtime-private composition"
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/ironclaw_host_runtime/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,7 +1666,7 @@ struct ScriptRuntimeAdapter {
}

impl ScriptRuntimeAdapter {
pub fn from_executor(executor: Arc<dyn ScriptExecutor>) -> Self {
fn from_executor(executor: Arc<dyn ScriptExecutor>) -> Self {
Self { executor }
}
}
Expand Down Expand Up @@ -1716,7 +1716,7 @@ struct McpRuntimeAdapter {
}

impl McpRuntimeAdapter {
pub fn from_executor(executor: Arc<dyn McpExecutor>) -> Self {
fn from_executor(executor: Arc<dyn McpExecutor>) -> Self {
Self { executor }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,64 @@ async fn host_runtime_services_installs_builtin_obligation_handler_with_audit_si
assert_eq!(records[0].action.target.as_deref(), Some("script.echo"));
}

#[tokio::test]
async fn host_runtime_services_maps_script_exit_failure_through_private_adapter() {
let script_runtime = Arc::new(ScriptRuntime::new(
ScriptRuntimeConfig::for_testing(),
ExitFailureScriptBackend,
));
let services = HostRuntimeServices::new(
Arc::new(registry_with_manifest(SCRIPT_MANIFEST)),
Arc::new(LocalFilesystem::new()),
Arc::new(InMemoryResourceGovernor::new()),
Arc::new(ObligatingAuthorizer::new(Vec::new())),
ProcessServices::in_memory(),
CapabilitySurfaceVersion::new("surface-v1").unwrap(),
)
.with_script_runtime(script_runtime);

let outcome = services
.host_runtime_for_local_testing()
.invoke_capability(RuntimeCapabilityRequest::new(
execution_context_with_dispatch_grant(script_capability_id()),
script_capability_id(),
ResourceEstimate::default(),
json!({"message": "fail through services"}),
trust_decision_with_dispatch_authority(),
))
.await
.unwrap();

assert_failed_outcome(outcome, RuntimeFailureKind::Process);
}

#[tokio::test]
async fn host_runtime_services_maps_mcp_client_failure_through_private_adapter() {
let services = HostRuntimeServices::new(
Arc::new(registry_with_manifest(MCP_MANIFEST)),
Arc::new(LocalFilesystem::new()),
Arc::new(InMemoryResourceGovernor::new()),
Arc::new(ObligatingAuthorizer::new(Vec::new())),
ProcessServices::in_memory(),
CapabilitySurfaceVersion::new("surface-v1").unwrap(),
)
.with_mcp_runtime(Arc::new(ClientErrorMcpExecutor));

let outcome = services
.host_runtime_for_local_testing()
.invoke_capability(RuntimeCapabilityRequest::new(
execution_context_with_dispatch_grant(mcp_capability_id()),
mcp_capability_id(),
ResourceEstimate::default(),
json!({"query": "fail through services"}),
trust_decision_with_dispatch_authority(),
))
.await
.unwrap();

assert_failed_outcome(outcome, RuntimeFailureKind::Backend);
}

#[tokio::test]
async fn host_runtime_services_applies_scoped_mount_obligation_to_script_runtime() {
let scoped_mounts = mount_view(
Expand Down Expand Up @@ -5087,6 +5145,19 @@ impl ScriptExecutor for RecordingScriptExecutor {
}
}

struct ExitFailureScriptBackend;

impl ScriptBackend for ExitFailureScriptBackend {
fn execute(&self, _request: ScriptBackendRequest) -> Result<ScriptBackendOutput, String> {
Ok(ScriptBackendOutput {
exit_code: 2,
stdout: Vec::new(),
stderr: b"simulated script failure".to_vec(),
wall_clock_ms: 1,
})
}
}

struct EchoScriptBackend;

impl ScriptBackend for EchoScriptBackend {
Expand Down Expand Up @@ -5754,6 +5825,21 @@ impl TrustAwareCapabilityDispatchAuthorizer for ObligatingAuthorizer {
}
}

struct ClientErrorMcpExecutor;

#[async_trait]
impl McpExecutor for ClientErrorMcpExecutor {
async fn execute_extension_json(
&self,
_governor: &dyn ResourceGovernor,
_request: McpExecutionRequest<'_>,
) -> Result<McpExecutionResult, McpError> {
Err(McpError::Client {
reason: "simulated MCP client failure".to_string(),
})
}
}

struct PanicMcpExecutor;

#[async_trait]
Expand Down Expand Up @@ -5977,6 +6063,10 @@ fn script_capability_id() -> CapabilityId {
CapabilityId::new("script.echo").unwrap()
}

fn mcp_capability_id() -> CapabilityId {
CapabilityId::new("mcp.search").unwrap()
}

struct WasmRuntimeFixture {
runtime: DefaultHostRuntime,
governor: Arc<InMemoryResourceGovernor>,
Expand Down
3 changes: 0 additions & 3 deletions crates/ironclaw_mcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@ serde_json = "1"
thiserror = "2"

[dev-dependencies]
ironclaw_dispatcher = { path = "../ironclaw_dispatcher" }
ironclaw_events = { path = "../ironclaw_events" }
ironclaw_filesystem = { path = "../ironclaw_filesystem" }
tempfile = "3"
tokio = { version = "1", features = ["macros", "rt"] }
Loading
Loading