mirror of
https://github.com/fabro-sh/fabro.git
synced 2026-09-17 23:52:34 +00:00
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.
This commit is contained in:
parent
0787b4fac8
commit
21671ffa0a
1 changed files with 35 additions and 3 deletions
|
|
@ -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::<Vec<_>>();
|
||||
rows.sort_unstable();
|
||||
rows
|
||||
};
|
||||
|
||||
assert_eq!(normalize(&global_runs), normalize(&env_runs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue