From 9c0e28ad97a32fce7ef4b70c7d56fffef13116f4 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Thu, 11 Jul 2024 20:56:15 -0700 Subject: [PATCH] run-tests: allow building of dependencies; update test templates --- src/new/templates/test/chat/tests.toml | 1 + .../{package_name}_test/api/tester:sys-v0.wit | 27 --- .../api/{package_name}:{publisher}-v0.wit | 27 --- .../chat/{package_name}_test/metadata.json | 6 +- src/new/templates/test/echo/tests.toml | 1 + .../{package_name}_test/api/tester:sys-v0.wit | 27 --- .../{package_name}_test:{publisher}-v0.wit | 4 + .../echo/{package_name}_test/metadata.json | 5 +- .../{package_name}_test/src/lib.rs | 2 +- src/new/templates/test/fibonacci/tests.toml | 1 + .../{package_name}_test/api/tester:sys-v0.wit | 27 --- .../api/{package_name}:{publisher}-v0.wit | 16 -- .../{package_name}_test/metadata.json | 6 +- src/run_tests/mod.rs | 164 +++++++++++++----- 14 files changed, 145 insertions(+), 169 deletions(-) delete mode 100644 src/new/templates/test/chat/{package_name}_test/api/tester:sys-v0.wit delete mode 100644 src/new/templates/test/chat/{package_name}_test/api/{package_name}:{publisher}-v0.wit delete mode 100644 src/new/templates/test/echo/{package_name}_test/api/tester:sys-v0.wit create mode 100644 src/new/templates/test/echo/{package_name}_test/api/{package_name}_test:{publisher}-v0.wit delete mode 100644 src/new/templates/test/fibonacci/{package_name}_test/api/tester:sys-v0.wit delete mode 100644 src/new/templates/test/fibonacci/{package_name}_test/api/{package_name}:{publisher}-v0.wit diff --git a/src/new/templates/test/chat/tests.toml b/src/new/templates/test/chat/tests.toml index 5b1ee6d6..c706fc49 100644 --- a/src/new/templates/test/chat/tests.toml +++ b/src/new/templates/test/chat/tests.toml @@ -5,6 +5,7 @@ runtime_build_release = false [[tests]] +dependency_package_paths = [".."] setup_packages = [ { path = "..", run = true } ] diff --git a/src/new/templates/test/chat/{package_name}_test/api/tester:sys-v0.wit b/src/new/templates/test/chat/{package_name}_test/api/tester:sys-v0.wit deleted file mode 100644 index 7fe0574b..00000000 --- a/src/new/templates/test/chat/{package_name}_test/api/tester:sys-v0.wit +++ /dev/null @@ -1,27 +0,0 @@ -interface tester { - variant request { - run(run-request), - } - - variant response { - run(result<_, fail-response>) - } - - record run-request { - input-node-names: list, - test-names: list, - test-timeout: u64, - } - - record fail-response { - test: string, - file: string, - line: u32, - column: u32, - } -} - -world tester-sys-v0 { - import tester; - include process-v0; -} diff --git a/src/new/templates/test/chat/{package_name}_test/api/{package_name}:{publisher}-v0.wit b/src/new/templates/test/chat/{package_name}_test/api/{package_name}:{publisher}-v0.wit deleted file mode 100644 index c6eb7c36..00000000 --- a/src/new/templates/test/chat/{package_name}_test/api/{package_name}:{publisher}-v0.wit +++ /dev/null @@ -1,27 +0,0 @@ -interface {package_name_kebab} { - variant request { - send(send-request), - /// history of chat with given node - history(string), - } - - variant response { - send, - history(list), - } - - record send-request { - target: string, - message: string, - } - - record chat-message { - author: string, - content: string, - } -} - -world {package_name_kebab}-{publisher_dotted_kebab}-v0 { - import {package_name_kebab}; - include process-v0; -} diff --git a/src/new/templates/test/chat/{package_name}_test/metadata.json b/src/new/templates/test/chat/{package_name}_test/metadata.json index cea44761..41269fed 100644 --- a/src/new/templates/test/chat/{package_name}_test/metadata.json +++ b/src/new/templates/test/chat/{package_name}_test/metadata.json @@ -10,7 +10,11 @@ "code_hashes": { "0.1.0": "" }, - "wit_version": 0 + "wit_version": 0, + "dependencies": [ + "{package_name}:{publisher}", + "tester:sys" + ] }, "external_url": "", "animation_url": "" diff --git a/src/new/templates/test/echo/tests.toml b/src/new/templates/test/echo/tests.toml index ceb605a7..55423eab 100644 --- a/src/new/templates/test/echo/tests.toml +++ b/src/new/templates/test/echo/tests.toml @@ -5,6 +5,7 @@ runtime_build_release = false [[tests]] +dependency_package_paths = [] setup_packages = [ { path = "..", run = true } ] diff --git a/src/new/templates/test/echo/{package_name}_test/api/tester:sys-v0.wit b/src/new/templates/test/echo/{package_name}_test/api/tester:sys-v0.wit deleted file mode 100644 index 7fe0574b..00000000 --- a/src/new/templates/test/echo/{package_name}_test/api/tester:sys-v0.wit +++ /dev/null @@ -1,27 +0,0 @@ -interface tester { - variant request { - run(run-request), - } - - variant response { - run(result<_, fail-response>) - } - - record run-request { - input-node-names: list, - test-names: list, - test-timeout: u64, - } - - record fail-response { - test: string, - file: string, - line: u32, - column: u32, - } -} - -world tester-sys-v0 { - import tester; - include process-v0; -} diff --git a/src/new/templates/test/echo/{package_name}_test/api/{package_name}_test:{publisher}-v0.wit b/src/new/templates/test/echo/{package_name}_test/api/{package_name}_test:{publisher}-v0.wit new file mode 100644 index 00000000..34ab50b7 --- /dev/null +++ b/src/new/templates/test/echo/{package_name}_test/api/{package_name}_test:{publisher}-v0.wit @@ -0,0 +1,4 @@ +world {package_name_kebab}-test-{publisher_dotted_kebab}-v0 { + import tester; + include process-v0; +} diff --git a/src/new/templates/test/echo/{package_name}_test/metadata.json b/src/new/templates/test/echo/{package_name}_test/metadata.json index cea44761..52706c6d 100644 --- a/src/new/templates/test/echo/{package_name}_test/metadata.json +++ b/src/new/templates/test/echo/{package_name}_test/metadata.json @@ -10,7 +10,10 @@ "code_hashes": { "0.1.0": "" }, - "wit_version": 0 + "wit_version": 0, + "dependencies": [ + "tester:sys" + ] }, "external_url": "", "animation_url": "" diff --git a/src/new/templates/test/echo/{package_name}_test/{package_name}_test/src/lib.rs b/src/new/templates/test/echo/{package_name}_test/{package_name}_test/src/lib.rs index 5ca609e4..bdd36456 100644 --- a/src/new/templates/test/echo/{package_name}_test/{package_name}_test/src/lib.rs +++ b/src/new/templates/test/echo/{package_name}_test/{package_name}_test/src/lib.rs @@ -10,7 +10,7 @@ mod tester_lib; wit_bindgen::generate!({ path: "target/wit", - world: "tester-sys-v0", + world: "{package_name_kebab}-test-{publisher_dotted_kebab}-v0", generate_unused_types: true, additional_derives: [PartialEq, serde::Deserialize, serde::Serialize, process_macros::SerdeJsonInto], }); diff --git a/src/new/templates/test/fibonacci/tests.toml b/src/new/templates/test/fibonacci/tests.toml index ceb605a7..29ba4576 100644 --- a/src/new/templates/test/fibonacci/tests.toml +++ b/src/new/templates/test/fibonacci/tests.toml @@ -5,6 +5,7 @@ runtime_build_release = false [[tests]] +dependency_package_paths = [".."] setup_packages = [ { path = "..", run = true } ] diff --git a/src/new/templates/test/fibonacci/{package_name}_test/api/tester:sys-v0.wit b/src/new/templates/test/fibonacci/{package_name}_test/api/tester:sys-v0.wit deleted file mode 100644 index 7fe0574b..00000000 --- a/src/new/templates/test/fibonacci/{package_name}_test/api/tester:sys-v0.wit +++ /dev/null @@ -1,27 +0,0 @@ -interface tester { - variant request { - run(run-request), - } - - variant response { - run(result<_, fail-response>) - } - - record run-request { - input-node-names: list, - test-names: list, - test-timeout: u64, - } - - record fail-response { - test: string, - file: string, - line: u32, - column: u32, - } -} - -world tester-sys-v0 { - import tester; - include process-v0; -} diff --git a/src/new/templates/test/fibonacci/{package_name}_test/api/{package_name}:{publisher}-v0.wit b/src/new/templates/test/fibonacci/{package_name}_test/api/{package_name}:{publisher}-v0.wit deleted file mode 100644 index 73615f3f..00000000 --- a/src/new/templates/test/fibonacci/{package_name}_test/api/{package_name}:{publisher}-v0.wit +++ /dev/null @@ -1,16 +0,0 @@ -interface {package_name_kebab} { - variant request { - number(u32), - numbers(tuple), - } - - variant response { - number(u64), - numbers(tuple), - } -} - -world {package_name_kebab}-{publisher_dotted_kebab}-v0 { - import {package_name_kebab}; - include process-v0; -} diff --git a/src/new/templates/test/fibonacci/{package_name}_test/metadata.json b/src/new/templates/test/fibonacci/{package_name}_test/metadata.json index cea44761..41269fed 100644 --- a/src/new/templates/test/fibonacci/{package_name}_test/metadata.json +++ b/src/new/templates/test/fibonacci/{package_name}_test/metadata.json @@ -10,7 +10,11 @@ "code_hashes": { "0.1.0": "" }, - "wit_version": 0 + "wit_version": 0, + "dependencies": [ + "{package_name}:{publisher}", + "tester:sys" + ] }, "external_url": "", "animation_url": "" diff --git a/src/run_tests/mod.rs b/src/run_tests/mod.rs index ff84b2ae..d6b80453 100644 --- a/src/run_tests/mod.rs +++ b/src/run_tests/mod.rs @@ -263,6 +263,122 @@ async fn boot_nodes( Ok(()) } +#[instrument(level = "trace", skip_all)] +async fn build_packages( + test: &Test, + test_dir_path: &Path, + detached: &bool, + persist_home: &bool, + runtime_path: &Path, +) -> Result<(Vec, Vec)> { + let setup_packages: Vec = test + .setup_packages + .iter() + .cloned() + .map(|s| { + SetupPackage { + path: test_dir_path.join(s.path).canonicalize().unwrap(), + run: s.run, + } + }) + .collect(); + let test_package_paths: Vec = test + .test_package_paths + .iter() + .cloned() + .map(|p| test_dir_path.join(p).canonicalize().unwrap()) + .collect(); + + info!("Starting node to host dependencies..."); + let port = test.nodes[0].port.clone(); + let home = PathBuf::from("/tmp/kinode-fake-node"); + let nodes = vec![Node { + port: port.clone(), + home, + fake_node_name: "fake.dev".into(), + password: None, + rpc: None, + runtime_verbosity: Some(2), + }]; + + let SetupCleanupReturn { + send_to_cleanup, + send_to_kill, + task_handles: _, + cleanup_context: _cleanup_context, + mut master_node_port, + node_cleanup_infos, + node_handles, + } = setup_cleanup(detached, persist_home).await?; + + // boot fakechain + let recv_kill_in_start_chain = send_to_kill.subscribe(); + let anvil_process = + chain::start_chain(test.fakechain_router, true, recv_kill_in_start_chain, false).await?; + + // Process each node + boot_nodes( + &nodes, + &test.fakechain_router, + &runtime_path, + &detached, + &mut master_node_port, + &anvil_process.as_ref().map(|ap| ap.id() as i32), + &vec![], + Arc::clone(&node_cleanup_infos), + &send_to_kill, + Arc::clone(&node_handles), + ).await?; + info!("Done starting node to host dependencies."); + + let url = format!("http://localhost:{port}"); + + for dependency_package_path in &test.dependency_package_paths { + let path = test_dir_path.join(&dependency_package_path).canonicalize()?; + build::execute( + &path, + false, + false, + false, + "test", + Some(url.clone()), + None, + false, + ).await?; + start_package::execute(&path, &url).await?; + } + + for setup_package in &setup_packages { + build::execute( + &setup_package.path, + false, + false, + false, + "test", + Some(url.clone()), + None, + false, + ).await?; + } + for test_package_path in &test_package_paths { + build::execute( + &test_package_path, + false, + false, + false, + "test", + Some(url.clone()), + None, + false, + ).await?; + } + + info!("Cleaning up node to host dependencies."); + let _ = send_to_cleanup.send(false); + + Ok((setup_packages, test_package_paths)) +} + #[instrument(level = "trace", skip_all)] async fn wait_until_booted( node: &PathBuf, @@ -507,47 +623,13 @@ async fn handle_test( test_dir_path: &Path, persist_home: bool, ) -> Result<()> { - let setup_packages: Vec = test - .setup_packages - .iter() - .cloned() - .map(|s| { - SetupPackage { - path: test_dir_path.join(s.path).canonicalize().unwrap(), - run: s.run, - } - }) - .collect(); - let test_package_paths: Vec = test - .test_package_paths - .iter() - .cloned() - .map(|p| test_dir_path.join(p).canonicalize().unwrap()) - .collect(); - for setup_package in &setup_packages { - build::execute( - &setup_package.path, - false, - false, - false, - "test", - None, - None, - false, - ).await?; // TODO - } - for test_package_path in &test_package_paths { - build::execute( - &test_package_path, - false, - false, - false, - "test", - None, - None, - false, - ).await?; // TODO - } + let (setup_packages, test_package_paths) = build_packages( + &test, + test_dir_path, + &detached, + &persist_home, + runtime_path, + ).await?; let SetupCleanupReturn { send_to_cleanup,