diff --git a/features/steps/acms_context_list_add_cli_steps.py b/features/steps/acms_context_list_add_cli_steps.py index d659f1cf1..10f90d2d4 100644 --- a/features/steps/acms_context_list_add_cli_steps.py +++ b/features/steps/acms_context_list_add_cli_steps.py @@ -693,6 +693,16 @@ def step_output_files_added_count(context: Context, count: int) -> None: @then("the JSON output should contain entries with:") def step_json_entries_with_values(context: Context) -> None: """Verify JSON entries contain specific values.""" + import json as _json + + if not hasattr(context, "json_output"): + raw = getattr(context, "last_command_output", "") + try: + context.json_output = _json.loads(raw) + except (_json.JSONDecodeError, ValueError) as e: + raise AssertionError( + f"Output is not valid JSON: {e}\nOutput: {raw}" + ) from e entries = context.json_output.get("entries", context.json_output) for row in context.table: field = row["field"] diff --git a/features/steps/cli_output_formats_steps.py b/features/steps/cli_output_formats_steps.py index 92c981c50..024c43dfc 100644 --- a/features/steps/cli_output_formats_steps.py +++ b/features/steps/cli_output_formats_steps.py @@ -239,16 +239,19 @@ def step_save_yaml_keys(context: Context) -> None: def step_output_valid_json(context: Context) -> None: # Support both context.result (CLI output format tests) and # context.last_command_output (ACMS context CLI tests) - if not hasattr(context, "result"): - # ACMS context CLI test path - raw = getattr(context, "last_command_output", "") + last_cmd_output = getattr(context, "last_command_output", "") + if last_cmd_output: + # ACMS context CLI test path: last_command_output takes priority try: - context.json_output = json.loads(raw) + context.json_output = json.loads(last_cmd_output) except json.JSONDecodeError as e: raise AssertionError( - f"Output is not valid JSON: {e}\nOutput: {raw}" + f"Output is not valid JSON: {e}\nOutput: {last_cmd_output}" ) from e return + if not hasattr(context, "result"): + # No output captured at all + raise AssertionError("No CLI output captured in context") assert context.result.exit_code == 0, ( f"CLI exited with {context.result.exit_code}: {context.result.output}" ) diff --git a/src/cleveragents/cli/commands/context.py b/src/cleveragents/cli/commands/context.py index 7adc2fc68..5d7db7191 100644 --- a/src/cleveragents/cli/commands/context.py +++ b/src/cleveragents/cli/commands/context.py @@ -9,6 +9,7 @@ Deprecated alias: ``agents context `` (emits deprecation warning) from __future__ import annotations +import json as _json from pathlib import Path from typing import TYPE_CHECKING, Annotated, Any @@ -243,8 +244,6 @@ def context_add( Context files are the source files that the AI will read and understand when creating or modifying code. """ - import json as _json - from cleveragents.application.container import get_container from cleveragents.application.services.context_service import ContextService from cleveragents.application.services.project_service import ProjectService @@ -449,8 +448,6 @@ def context_list( Or list named contexts in a directory. """ - import json as _json - if context_dir is not None: # List named contexts in the given directory ctx_base = context_dir