fix(cli): fix JSON validation and step definition bugs in ACMS context CLI tests
CI / push-validation (pull_request) Successful in 54s
CI / helm (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 1m33s
CI / lint (pull_request) Failing after 1m55s
CI / typecheck (pull_request) Successful in 2m17s
CI / quality (pull_request) Successful in 2m26s
CI / security (pull_request) Successful in 2m35s
CI / coverage (pull_request) Has been skipped
CI / unit_tests (pull_request) Failing after 5m29s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 5m45s
CI / integration_tests (pull_request) Successful in 6m52s
CI / status-check (pull_request) Failing after 3s
CI / push-validation (pull_request) Successful in 54s
CI / helm (pull_request) Successful in 1m4s
CI / build (pull_request) Successful in 1m33s
CI / lint (pull_request) Failing after 1m55s
CI / typecheck (pull_request) Successful in 2m17s
CI / quality (pull_request) Successful in 2m26s
CI / security (pull_request) Successful in 2m35s
CI / coverage (pull_request) Has been skipped
CI / unit_tests (pull_request) Failing after 5m29s
CI / docker (pull_request) Has been skipped
CI / e2e_tests (pull_request) Successful in 5m45s
CI / integration_tests (pull_request) Successful in 6m52s
CI / status-check (pull_request) Failing after 3s
- Fix step_output_valid_json to check context.last_command_output first (ACMS path) before falling back to context.result envelope validation, resolving JSON validation failure in context list --format json scenario - Fix step_json_entries_with_values to parse context.last_command_output when context.json_output is not set, fixing the last integration scenario - Move import json as _json from inside function bodies to module level in context.py for cleaner style (reviewer suggestion) ISSUES CLOSED: #9585
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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}"
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ Deprecated alias: ``agents context <subcommand>`` (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
|
||||
|
||||
Reference in New Issue
Block a user