From bbfb17e4b18f0895e3bb3f65ec6469bd47b9b6fa Mon Sep 17 00:00:00 2001 From: Exidex <16986685+exidex@users.noreply.github.com> Date: Fri, 20 Dec 2024 17:34:03 +0100 Subject: [PATCH] Fix scenarios not working --- js/scenario_runner_cli/src/main.ts | 22 +++------------------- rust/client/src/ui/mod.rs | 2 ++ rust/common/build.rs | 2 +- rust/common/src/model.rs | 15 +++++++++++++++ rust/server/build.rs | 2 +- rust/server/src/plugins/js.rs | 10 ++++++---- 6 files changed, 28 insertions(+), 25 deletions(-) diff --git a/js/scenario_runner_cli/src/main.ts b/js/scenario_runner_cli/src/main.ts index ccaa248..01923e2 100644 --- a/js/scenario_runner_cli/src/main.ts +++ b/js/scenario_runner_cli/src/main.ts @@ -36,7 +36,6 @@ async function runScenarios(expectedPlugin: string | undefined) { const scenariosRun = path.join(scenarios, "run"); console.log("Building server") - buildServer(projectRoot) console.log("Building scenario plugins") buildScenarioPlugins(projectRoot) @@ -50,7 +49,7 @@ async function runScenarios(expectedPlugin: string | undefined) { console.log("Starting runner") - const backendProcess = spawnSync('target/debug/gauntlet', { + const backendProcess = spawnSync('cargo', ['run', '--features', 'scenario_runner'], { stdio: "inherit", cwd: projectRoot, env: Object.assign(process.env, { @@ -82,8 +81,6 @@ async function runScreenshotGen(expectedPlugin: string | undefined, expectedEntr const scenarios = path.join(projectRoot, "scenarios"); const scenariosOut = path.join(scenarios, "out"); - buildServer(projectRoot) - for (const plugin of readdirSync(scenariosOut)) { if (expectedPlugin) { if (plugin != expectedPlugin) { @@ -116,10 +113,11 @@ async function runScreenshotGen(expectedPlugin: string | undefined, expectedEntr .map(x => (x.charAt(0).toUpperCase() + x.slice(1))) .join(" "); - const frontendReturn = spawnSync('target/debug/gauntlet', { + const frontendReturn = spawnSync('cargo', ['run', '--features', 'scenario_runner'], { stdio: "inherit", cwd: projectRoot, env: Object.assign(process.env, { + RUST_BACKTRACE: "1", RUST_LOG: "gauntlet-client=INFO", GAUNTLET_SCENARIO_RUNNER_TYPE: "screenshot_gen", GAUNTLET_SCREENSHOT_GEN_IN: scenarioFile, @@ -138,20 +136,6 @@ async function runScreenshotGen(expectedPlugin: string | undefined, expectedEntr } } -function buildServer(projectRoot: string) { - const serverBuildResult = spawnSync('cargo', ['build', '--features', 'scenario_runner'], { - stdio: "inherit", - cwd: projectRoot, - env: Object.assign(process.env, { - RUST_BACKTRACE: "1" - }) - }); - - if (serverBuildResult.status !== 0) { - throw new Error(`Unable to compile server, status: ${JSON.stringify(serverBuildResult)}`); - } -} - function buildScenarioPlugins(projectRoot: string) { const scenarioPluginBuildResult = spawnSync('npm', ['run', 'build-all'], { stdio: "inherit", diff --git a/rust/client/src/ui/mod.rs b/rust/client/src/ui/mod.rs index 45b2422..d9879de 100644 --- a/rust/client/src/ui/mod.rs +++ b/rust/client/src/ui/mod.rs @@ -404,6 +404,8 @@ fn new( let gen_in = std::env::var("GAUNTLET_SCREENSHOT_GEN_IN") .expect("Unable to read GAUNTLET_SCREENSHOT_GEN_IN"); + println!("Reading scenario file at: {}", gen_in); + let gen_in = fs::read_to_string(gen_in) .expect("Unable to read file at GAUNTLET_SCREENSHOT_GEN_IN"); diff --git a/rust/common/build.rs b/rust/common/build.rs index b187d16..5ab61c5 100644 --- a/rust/common/build.rs +++ b/rust/common/build.rs @@ -558,7 +558,7 @@ fn component_model_generator() -> Result<(), Box> { output.push_str("#[derive(Debug, Serialize, Deserialize, Encode, Decode)]\n"); output.push_str("pub struct RootWidget {\n"); - output.push_str(" #[serde(default, deserialize_with = \"array_to_option\")]\n"); + output.push_str(" #[serde(default, deserialize_with = \"array_to_option\", serialize_with = \"option_to_array\")]\n"); output.push_str(" pub content: Option\n"); output.push_str("}\n"); } diff --git a/rust/common/src/model.rs b/rust/common/src/model.rs index 18fa0da..6430c5b 100644 --- a/rust/common/src/model.rs +++ b/rust/common/src/model.rs @@ -245,6 +245,21 @@ pub enum KeyboardEventOrigin { PluginView, } +fn option_to_array(value: &Option, serializer: S) -> Result +where + V: Serialize, + S: Serializer, +{ + let value = match value { + None => vec![], + Some(value) => vec![value] + }; + + let res = Vec::<&V>::serialize(&value, serializer)?; + + Ok(res) +} + fn array_to_option<'de, D, V>(deserializer: D) -> Result, D::Error> where D: Deserializer<'de>, V: Deserialize<'de> { let res = Option::>::deserialize(deserializer)?; diff --git a/rust/server/build.rs b/rust/server/build.rs index 954e2a9..dc35c4f 100644 --- a/rust/server/build.rs +++ b/rust/server/build.rs @@ -1,7 +1,7 @@ use vergen_gitcl::{CargoBuilder, Emitter, GitclBuilder}; fn main() -> Result<(), Box> { - println!("cargo:rerun-if-changed=src/db_migrations"); + println!("cargo:rerun-if-changed=db_migrations"); let gitcl = GitclBuilder::all_git()?; let cargo = CargoBuilder::default() diff --git a/rust/server/src/plugins/js.rs b/rust/server/src/plugins/js.rs index c2a7c55..e1c082b 100644 --- a/rust/server/src/plugins/js.rs +++ b/rust/server/src/plugins/js.rs @@ -257,15 +257,17 @@ pub async fn start_plugin_runtime(data: PluginRuntimeData, run_status_guard: Run let current_exe = std::env::current_exe() .context("unable to get current_exe")?; + #[cfg(not(feature = "scenario_runner"))] std::process::Command::new(current_exe) .env(PLUGIN_RUNTIME_ENV, name_str) .spawn() .context("start plugin runtime process")?; - // use only for debugging, only works if only one plugin is enabled - // std::thread::spawn(move || { - // plugin_runtime::run_plugin_runtime(name_str.to_str().unwrap().to_string()) - // }); + // use only for debugging and scenario_runner, only works if only one plugin is enabled + #[cfg(feature = "scenario_runner")] + std::thread::spawn(move || { + gauntlet_plugin_runtime::run_plugin_runtime(name_str.to_str().unwrap().to_string()) + }); let conn = listener.accept().await?;