From 21671ffa0ae5b062da22f4c31c23c83443512833 Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 5 Apr 2026 10:34:32 -0400 Subject: [PATCH] test(cli): stabilize ps JSON global flag assertion Scope the ps listing to the current test case and compare a normalized projection instead of exact live run payload equality. This avoids flakes from parallel tests and in-flight status transitions while preserving the CLI contract under test. --- .../fabro-cli/tests/it/cmd/json_global.rs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/lib/crates/fabro-cli/tests/it/cmd/json_global.rs b/lib/crates/fabro-cli/tests/it/cmd/json_global.rs index 682d57fca..4259f8aa1 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/json_global.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/json_global.rs @@ -47,10 +47,11 @@ fn settings_json_outputs_parseable_json() { fn ps_supports_global_flag_and_env_var() { let context = test_context!(); setup_completed_fast_dry_run(&context); + let test_case_label = context.test_case_label(); let global_output = context .command() - .args(["--json", "ps", "-a"]) + .args(["--json", "ps", "-a", "--label", &test_case_label]) .output() .expect("command should run"); assert!(global_output.status.success()); @@ -61,13 +62,44 @@ fn ps_supports_global_flag_and_env_var() { let env_output = context .command() .env("FABRO_JSON", "1") - .args(["ps", "-a"]) + .args(["ps", "-a", "--label", &test_case_label]) .output() .expect("command should run"); assert!(env_output.status.success()); let env_runs: Value = serde_json::from_slice(&env_output.stdout).expect("FABRO_JSON output should parse"); - assert_eq!(global_runs, env_runs); + + let normalize = |runs: &Value| { + let mut rows = runs + .as_array() + .expect("ps output should be an array") + .iter() + .map(|run| { + ( + run["run_id"] + .as_str() + .expect("run_id should be present") + .to_string(), + run["workflow_name"] + .as_str() + .expect("workflow_name should be present") + .to_string(), + run["workflow_slug"] + .as_str() + .expect("workflow_slug should be present") + .to_string(), + run["goal"] + .as_str() + .expect("goal should be present") + .to_string(), + ) + }) + .collect::>(); + rows.sort_unstable(); + rows + }; + + assert_eq!(normalize(&global_runs), normalize(&env_runs)); } #[test]