From ee25d82aa92874101e6eb85dccafeb56243dc3cf Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Wed, 2 Dec 2026 20:30:59 +1300 Subject: [PATCH] CLI 0.2.12: visualci test exports VISUALCI_MODE (local or ci, as the build was created) to the tests, so integrations choose per-test failures by mode rather than by whether VISUALCI_BUILD_ID is set --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- crates/visualci-cli/src/main.rs | 24 ++++++++++++++---------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 76e3d593..daf78732 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5206,7 +5206,7 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "visualci-cli" -version = "0.2.11" +version = "0.2.12" dependencies = [ "anyhow", "base64 0.22.1", @@ -5223,7 +5223,7 @@ dependencies = [ [[package]] name = "visualci-core" -version = "0.2.11" +version = "0.2.12" dependencies = [ "globset", "hex", @@ -5240,7 +5240,7 @@ dependencies = [ [[package]] name = "visualci-renderer" -version = "0.2.11" +version = "0.2.12" dependencies = [ "anyhow", "image", @@ -5255,7 +5255,7 @@ dependencies = [ [[package]] name = "visualci-wasm" -version = "0.2.11" +version = "0.2.12" dependencies = [ "image", "serde", @@ -5265,7 +5265,7 @@ dependencies = [ [[package]] name = "visualci_server" -version = "0.2.11" +version = "0.2.12" dependencies = [ "aes-gcm", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 7dd7576f..e180451b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/*", "server", "server/migration"] [workspace.package] -version = "0.2.11" +version = "0.2.12" edition = "2024" license = "Apache-2.0" repository = "https://github.com/DocSpring/visualci" diff --git a/crates/visualci-cli/src/main.rs b/crates/visualci-cli/src/main.rs index 4d2eaffb..3f4d546b 100644 --- a/crates/visualci-cli/src/main.rs +++ b/crates/visualci-cli/src/main.rs @@ -178,7 +178,8 @@ enum Command { #[command(flatten)] connection: Connection, }, - /// Run a test command inside one build: create the build, run the command with VISUALCI_BUILD_ID set (so every + /// Run a test command inside one build: create the build, run the command with VISUALCI_BUILD_ID and + /// VISUALCI_MODE (`local` or `ci`) set (so every /// test, process or worker that sends snapshots adds them to this build), then finalize it when the command ends, /// even when the tests fail or are interrupted (Ctrl-C), wait for the result and print what changed. A local run /// is a subset: what it didn't send isn't "removed". Exits with the command's status when it failed, else 0 when @@ -682,7 +683,7 @@ fn run() -> Result<()> { if let Some(message) = build.blocked_message() { eprintln!("visualci: {message}"); } - let status = run_tests(&command, &build.id, &connection)?; + let status = run_tests(&command, &build.id, if local { "local" } else { "ci" }, &connection)?; if upload { let snapshots = configured_uploads(&snapshot)?; if !snapshots.is_empty() { @@ -724,13 +725,14 @@ fn run() -> Result<()> { Ok(()) } -/// Run the test command with VISUALCI_BUILD_ID (and the connection's options, when given on the command line) in its -/// environment, and return its exit status: its code, or 128 + the signal that ended it. While it runs this process +/// Run the test command with VISUALCI_BUILD_ID and VISUALCI_MODE (`local` or `ci`, as the build was created: test +/// helpers fail a test on its changes in a local run, and leave them to review in CI) in its environment, with the +/// connection's options when given on the command line, and return its exit status: its code, or 128 + the signal that ended it. While it runs this process /// ignores Ctrl-C (the command, in the same process group, still gets it), so an interrupted run is still finalized. -fn run_tests(command: &[String], build_id: &str, connection: &Connection) -> Result { +fn run_tests(command: &[String], build_id: &str, mode: &str, connection: &Connection) -> Result { let (program, args) = command.split_first().context("give the test command after --")?; let mut child = std::process::Command::new(program); - child.args(args).env("VISUALCI_BUILD_ID", build_id); + child.args(args).env("VISUALCI_BUILD_ID", build_id).env("VISUALCI_MODE", mode); if let Some(url) = &connection.api_url { child.env("VISUALCI_API_URL", url); } @@ -1266,12 +1268,14 @@ mod tests { fn runs_the_test_command_with_the_build() { let connection = Connection { api_url: None, token: None, project: Some("acme/web".into()) }; let sh = |script: &str| vec!["sh".to_string(), "-c".to_string(), script.to_string()]; - let ok = r#"[ "$VISUALCI_BUILD_ID" = b-1 ] && [ "$VISUALCI_PROJECT" = acme/web ]"#; - assert_eq!(run_tests(&sh(ok), "b-1", &connection).unwrap(), 0); - assert_eq!(run_tests(&sh("exit 7"), "b-1", &connection).unwrap(), 7); + let ok = + r#"[ "$VISUALCI_BUILD_ID" = b-1 ] && [ "$VISUALCI_MODE" = local ] && [ "$VISUALCI_PROJECT" = acme/web ]"#; + assert_eq!(run_tests(&sh(ok), "b-1", "local", &connection).unwrap(), 0); + assert_eq!(run_tests(&sh(r#"[ "$VISUALCI_MODE" = ci ]"#), "b-1", "ci", &connection).unwrap(), 0); + assert_eq!(run_tests(&sh("exit 7"), "b-1", "local", &connection).unwrap(), 7); // Interrupted: 128 + SIGINT, and this process is still here to finalize. The command itself still stops on // Ctrl-C (an ignored SIGINT would leave it running). - assert_eq!(run_tests(&sh("kill -INT $$; sleep 5"), "b-1", &connection).unwrap(), 130); + assert_eq!(run_tests(&sh("kill -INT $$; sleep 5"), "b-1", "local", &connection).unwrap(), 130); } #[test]