From 1d6d09bdedf07bfd21b420e35fefca7765d29de2 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Tue, 19 Dec 2023 16:35:55 -0800 Subject: [PATCH] fix spawn and vfs messaging caps --- modules/tester/test_runner/src/lib.rs | 16 ++++++++-------- modules/tester/tester/src/lib.rs | 12 ++++++++++-- src/kernel/mod.rs | 1 + src/kernel/standard_host.rs | 16 ++-------------- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/modules/tester/test_runner/src/lib.rs b/modules/tester/test_runner/src/lib.rs index e9456eb7..d544d900 100644 --- a/modules/tester/test_runner/src/lib.rs +++ b/modules/tester/test_runner/src/lib.rs @@ -42,7 +42,7 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { let response = Request::new() .target(make_vfs_address(&our)?) .ipc(serde_json::to_vec(&kt::VfsRequest { - path: "/tester:uqbar/pkg".into(), + path: "/tester:uqbar/tests".into(), action: kt::VfsAction::ReadDir, })?) .send_and_await_response(test_timeout)? @@ -54,18 +54,18 @@ fn handle_message(our: &Address) -> anyhow::Result<()> { let kt::VfsResponse::ReadDir(children) = serde_json::from_slice(&vfs_ipc)? else { + wit::print_to_terminal( + 0, + &format!( + "{:?}", + serde_json::from_slice::(&vfs_ipc)?, + ), + ); panic!("") }; - let mut children: HashSet<_> = children.into_iter().collect(); - children.remove("/manifest.json"); - children.remove("/metadata.json"); - children.remove("/tester.wasm"); - children.remove("/test_runner.wasm"); wit::print_to_terminal(0, &format!("test_runner: running {:?}...", children)); - // todo: are children returned as absolute paths. - for child in &children { let child_process_id = match spawn( None, diff --git a/modules/tester/tester/src/lib.rs b/modules/tester/tester/src/lib.rs index 56623c62..495c49eb 100644 --- a/modules/tester/tester/src/lib.rs +++ b/modules/tester/tester/src/lib.rs @@ -31,7 +31,6 @@ fn handle_message( _messages: &mut Messages, node_names: &mut Vec, ) -> anyhow::Result<()> { - println!("handle_message"); let Ok(message) = await_message() else { return Ok(()); }; @@ -113,11 +112,20 @@ fn init(our: Address) { // orchestrate tests using external scripts // -> must give drive cap to rpc + let _ = Request::new() + .target(make_vfs_address(&our).unwrap()) + .ipc(serde_json::to_vec(&kt::VfsRequest { + path: "/tester:uqbar/tests".into(), + action: kt::VfsAction::CreateDrive, + }).unwrap()) + .send_and_await_response(5) + .unwrap() + .unwrap(); let drive_cap = get_capability( &make_vfs_address(&our).unwrap(), &serde_json::to_string(&serde_json::json!({ "kind": "write", - "drive": "/tester:uqbar/pkg", + "drive": "/tester:uqbar/tests", })) .expect("couldn't serialize"), ) diff --git a/src/kernel/mod.rs b/src/kernel/mod.rs index 4b995a64..de7a57a1 100644 --- a/src/kernel/mod.rs +++ b/src/kernel/mod.rs @@ -886,6 +886,7 @@ pub async fn kernel( // kernel and filesystem can ALWAYS message any local process if kernel_message.source.process != *KERNEL_PROCESS_ID && kernel_message.source.process != *STATE_PROCESS_ID + && kernel_message.source.process != *VFS_PROCESS_ID { let Some(persisted_source) = process_map.get(&kernel_message.source.process) else { continue diff --git a/src/kernel/standard_host.rs b/src/kernel/standard_host.rs index 8b1d5a43..0bf39396 100644 --- a/src/kernel/standard_host.rs +++ b/src/kernel/standard_host.rs @@ -185,18 +185,6 @@ impl StandardHost for process::ProcessWasi { node: self.process.metadata.our.node.clone(), process: VFS_PROCESS_ID.en_wit(), }; - // TODO: note, drive could just be your basic process maybe. - let path = format!( - "/{}/{}/{}", - self.process.metadata.our.process.to_string(), - self.process.metadata.our.process.package(), - wasm_path - ); - // let our_drive_name = [ - // self.process.metadata.our.process.package(), - // self.process.metadata.our.process.publisher(), - // ] - // .join(":"); let Ok(Ok((_, hash_response))) = process::send_and_await_response( self, None, @@ -205,7 +193,7 @@ impl StandardHost for process::ProcessWasi { inherit: false, expects_response: Some(5), ipc: serde_json::to_vec(&t::VfsRequest { - path: path.clone(), + path: wasm_path.clone(), action: t::VfsAction::Read, }) .unwrap(), @@ -260,7 +248,7 @@ impl StandardHost for process::ProcessWasi { expects_response: Some(5), // TODO evaluate ipc: serde_json::to_vec(&t::KernelCommand::InitializeProcess { id: new_process_id.clone(), - wasm_bytes_handle: path, + wasm_bytes_handle: wasm_path, on_exit: t::OnExit::de_wit(on_exit), initial_capabilities: match capabilities { wit::Capabilities::None => HashSet::new(),