From 721eaa92264b0a1dbe3c2795fc6b1032339eb49b Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Fri, 3 Jan 2025 00:21:12 -0600 Subject: [PATCH 1/3] chore: allow unauthenticated workflow exection --- crates/cli/src/workflows.rs | 31 ++++++++++++++++++++----------- crates/cli_bin/tests/workflows.rs | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/crates/cli/src/workflows.rs b/crates/cli/src/workflows.rs index ae66fa278..86d4c6384 100644 --- a/crates/cli/src/workflows.rs +++ b/crates/cli/src/workflows.rs @@ -1,7 +1,7 @@ use crate::updater::{SupportedApp, Updater}; use anyhow::Result; use console::style; -use log::debug; +use log::{debug, info}; use marzano_auth::env::{get_grit_api_url, ENV_VAR_GRIT_API_URL, ENV_VAR_GRIT_AUTH_TOKEN}; use marzano_auth::info::AuthInfo; use marzano_gritmodule::config::REPO_CONFIG_DIR_NAME; @@ -107,17 +107,20 @@ where ); } - let auth = updater.get_valid_auth().await.map_err(|_| { - anyhow::anyhow!( + let auth = updater.get_valid_auth().await; + if auth.is_err() { + log::warn!( "No valid authentication token found, please run {}", style("grit auth login").bold().red() - ) - })?; + ); + } - if let Some(username) = auth.get_user_name()? { - if !arg.input.contains_key(GRIT_VCS_USER_NAME) { - arg.input - .insert(GRIT_VCS_USER_NAME.to_string(), username.into()); + if let Ok(ref auth) = auth { + if let Some(username) = auth.get_user_name()? { + if !arg.input.contains_key(GRIT_VCS_USER_NAME) { + arg.input + .insert(GRIT_VCS_USER_NAME.to_string(), username.into()); + } } } @@ -157,11 +160,17 @@ where let mut final_child = child .env(ENV_VAR_GRIT_API_URL, get_grit_api_url()) - .env(ENV_VAR_GRIT_AUTH_TOKEN, auth.access_token) .env(ENV_GRIT_WORKSPACE_ROOT, root) .arg("--file") .arg(&tempfile_path) - .kill_on_drop(true) + .kill_on_drop(true); + + let mut final_child = if let Ok(auth) = auth { + final_child.env(ENV_VAR_GRIT_AUTH_TOKEN, auth.access_token) + } else { + final_child + }; + let mut final_child = final_child .stdout(Stdio::piped()) .stderr(Stdio::piped()) .spawn() diff --git a/crates/cli_bin/tests/workflows.rs b/crates/cli_bin/tests/workflows.rs index d74753339..c96a545c8 100644 --- a/crates/cli_bin/tests/workflows.rs +++ b/crates/cli_bin/tests/workflows.rs @@ -132,3 +132,27 @@ fn applies_user_workflows() -> Result<()> { Ok(()) } + +#[test] +fn run_workflow_args() -> Result<()> { + let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?; + + let mut cmd = get_test_cmd()?; + cmd.arg("apply") + .arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js") + .current_dir(temp_fixtures_root); + + let output = cmd.output()?; + println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?); + println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?); + + assert!( + output.status.success(), + "Command didn't finish successfully" + ); + + let stdout = String::from_utf8(output.stdout)?; + assert!(stdout.contains("Running hello workflow"),); + + Ok(()) +} From 78b877cbca3280661d9e35bbbbb06c74d2f4deef Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Fri, 3 Jan 2025 00:24:00 -0600 Subject: [PATCH 2/3] TDD time --- crates/cli/src/workflows.rs | 2 +- crates/cli_bin/tests/workflows.rs | 33 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/cli/src/workflows.rs b/crates/cli/src/workflows.rs index 86d4c6384..1f3017797 100644 --- a/crates/cli/src/workflows.rs +++ b/crates/cli/src/workflows.rs @@ -1,7 +1,7 @@ use crate::updater::{SupportedApp, Updater}; use anyhow::Result; use console::style; -use log::{debug, info}; +use log::debug; use marzano_auth::env::{get_grit_api_url, ENV_VAR_GRIT_API_URL, ENV_VAR_GRIT_AUTH_TOKEN}; use marzano_auth::info::AuthInfo; use marzano_gritmodule::config::REPO_CONFIG_DIR_NAME; diff --git a/crates/cli_bin/tests/workflows.rs b/crates/cli_bin/tests/workflows.rs index c96a545c8..97137bb7a 100644 --- a/crates/cli_bin/tests/workflows.rs +++ b/crates/cli_bin/tests/workflows.rs @@ -134,12 +134,14 @@ fn applies_user_workflows() -> Result<()> { } #[test] -fn run_workflow_args() -> Result<()> { +fn run_workflow_input() -> Result<()> { let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?; let mut cmd = get_test_cmd()?; cmd.arg("apply") .arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js") + .arg("--input") + .arg("{\"query\": \"John\"}") .current_dir(temp_fixtures_root); let output = cmd.output()?; @@ -154,5 +156,34 @@ fn run_workflow_args() -> Result<()> { let stdout = String::from_utf8(output.stdout)?; assert!(stdout.contains("Running hello workflow"),); + assert!(stdout.contains("John as the query")); + + Ok(()) +} + +#[test] +fn run_workflow_arg_input() -> Result<()> { + let (_temp_dir, temp_fixtures_root) = get_fixture("grit_modules", true)?; + + let mut cmd = get_test_cmd()?; + cmd.arg("apply") + .arg("https://storage.googleapis.com/grit-workflows-dev-workflow_definitions/test/hello.js") + .arg("--query=John") + .current_dir(temp_fixtures_root); + + let output = cmd.output()?; + println!("stdout: {:?}", String::from_utf8(output.stdout.clone())?); + println!("stderr: {:?}", String::from_utf8(output.stderr.clone())?); + + assert!( + output.status.success(), + "Command didn't finish successfully" + ); + + let stdout = String::from_utf8(output.stdout)?; + assert!(stdout.contains("Running hello workflow"),); + + assert!(stdout.contains("John as the query")); + Ok(()) } From 70e883ca6aa08fb9f0423a756aa78ae618d96772 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Fri, 3 Jan 2025 01:01:40 -0600 Subject: [PATCH 3/3] attempt --- crates/cli/src/commands/apply_migration.rs | 27 ++++++++++++++++++++++ crates/cli/src/commands/plumbing.rs | 1 + 2 files changed, 28 insertions(+) diff --git a/crates/cli/src/commands/apply_migration.rs b/crates/cli/src/commands/apply_migration.rs index 0097b3977..48b58b838 100644 --- a/crates/cli/src/commands/apply_migration.rs +++ b/crates/cli/src/commands/apply_migration.rs @@ -38,6 +38,9 @@ pub struct ApplyMigrationArgs { /// Print verbose output #[clap(long)] pub(crate) verbose: bool, + // Capture remaining arguments + #[arg(trailing_var_arg = true, allow_hyphen_values = true, index = 2)] + pub(crate) inputs: Vec, } impl ApplyMigrationArgs { @@ -104,3 +107,27 @@ pub(crate) async fn run_apply_migration( Ok(workflow_status.clone()) } + +#[cfg(test)] +mod tests { + use super::*; + use anyhow::Result; + use clap::{Arg, ArgAction, Command, FromArgMatches}; + + #[test] + fn test_arg_parsing() -> Result<()> { + let args = ApplyMigrationArgs::augment_args(Command::new("test")); + + let matches = + args.get_matches_from(vec!["test", "--watch", "--test", "bob", "--suzy=queue"]); + + let apply_args = ApplyMigrationArgs::from_arg_matches(&matches)?; + + println!("{:?}", apply_args); + + // assert_eq!(payload.get("test").unwrap().as_str().unwrap(), "bob"); + // assert_eq!(payload.get("suzy").unwrap().as_str().unwrap(), "queue"); + + Ok(()) + } +} diff --git a/crates/cli/src/commands/plumbing.rs b/crates/cli/src/commands/plumbing.rs index 163a22131..73c549cbd 100644 --- a/crates/cli/src/commands/plumbing.rs +++ b/crates/cli/src/commands/plumbing.rs @@ -372,6 +372,7 @@ pub(crate) async fn run_plumbing( workflow_id: None, verbose: true, watch: false, + inputs: vec![], }, emitter, execution_id.clone(),