diff --git a/features/plan_explain.feature b/features/plan_explain.feature index 1332eb511..93ff86d81 100644 --- a/features/plan_explain.feature +++ b/features/plan_explain.feature @@ -107,12 +107,12 @@ Feature: Plan explain and decision tree CLI commands # plan tree - json format # ------------------------------------------------------------------ - @tdd_issue @tdd_issue_4254 @tdd_expected_fail + @tdd_issue @tdd_issue_4254 Scenario: Tree with json format Given a set of test decisions forming a tree When I format the tree as json - Then the json tree output should be valid json - And the json tree output should contain "decision_id" + Then the json tree output should be a valid json envelope + And the json tree output should contain "command" # ------------------------------------------------------------------ # plan tree - yaml format diff --git a/features/steps/plan_explain_cli_coverage_steps.py b/features/steps/plan_explain_cli_coverage_steps.py index 31a79cee7..2b70b95bd 100644 --- a/features/steps/plan_explain_cli_coverage_steps.py +++ b/features/steps/plan_explain_cli_coverage_steps.py @@ -815,8 +815,12 @@ def step_pec_output_valid_json_envelope(context: Context) -> None: f"Expected envelope keys {_ENVELOPE_KEYS}, got {set(parsed.keys())}" ) data = parsed["data"] - assert isinstance(data, dict), f"Expected envelope data to be a dict, got {type(data)}" - assert "plan_id" in data, f"Expected 'plan_id' in envelope data, got {set(data.keys())}" + assert isinstance(data, dict), ( + f"Expected envelope data to be a dict, got {type(data)}" + ) + assert "plan_id" in data, ( + f"Expected 'plan_id' in envelope data, got {set(data.keys())}" + ) @then("pec the tree should exclude the superseded grandchild") diff --git a/features/steps/plan_explain_steps.py b/features/steps/plan_explain_steps.py index f27416a56..dd6651c8c 100644 --- a/features/steps/plan_explain_steps.py +++ b/features/steps/plan_explain_steps.py @@ -405,6 +405,18 @@ def step_tree_json_valid(context: Context) -> None: assert isinstance(parsed, list), "Expected a JSON array" +@then("the json tree output should be a valid json envelope") +def step_tree_json_valid_envelope(context: Context) -> None: + parsed = json.loads(context.pe_tree_json) + assert isinstance(parsed, dict), ( + f"Expected a JSON object (envelope), got {type(parsed)}" + ) + _envelope_keys = {"command", "status", "exit_code", "data", "timing", "messages"} + assert _envelope_keys.issubset(parsed.keys()), ( + f"Expected envelope keys {_envelope_keys}, got {set(parsed.keys())}" + ) + + @then('the json tree output should contain "{text}"') def step_tree_json_contains(context: Context, text: str) -> None: assert text in context.pe_tree_json, f"Expected '{text}' in tree JSON"