fix(cli): fix lint, AmbiguousStep, missing step definition, and runtime errors in ACMS context CLI test steps
CI / lint (pull_request) Failing after 55s
CI / typecheck (pull_request) Successful in 1m8s
CI / quality (pull_request) Successful in 1m0s
CI / security (pull_request) Successful in 1m13s
CI / coverage (pull_request) Has been skipped
CI / unit_tests (pull_request) Failing after 1m10s
CI / docker (pull_request) Has been skipped
CI / build (pull_request) Successful in 35s
CI / helm (pull_request) Successful in 28s
CI / push-validation (pull_request) Successful in 23s
CI / e2e_tests (pull_request) Successful in 3m15s
CI / integration_tests (pull_request) Successful in 3m25s
CI / status-check (pull_request) Failing after 5s

- Added missing context attribute initialization (context_files, file_metadata) in Background step
- Added step_create_file_with_tag_and_policy for last integration scenario
- Removed duplicate @when step for "nonexistent.py" that caused AmbiguousStep
- Removed lazy hasattr() guards - all context attributes initialized eagerly
- Fixed lint: replaced .format() with f-string (UP032), added "raise from e" (B904), removed trailing whitespace (W293)
- Fixed runtime AttributeError in step_json_entry_keys: explicit key assertions instead of calling .lower() on dict
- Fixed weak assertion in step_output_table_columns: assert all four column headers explicitly
- Removed duplicate step_run_context_add_nonexistent function

ISSUES CLOSED: #9672
This commit is contained in:
2026-04-30 15:13:55 +00:00
parent 94bc052a8b
commit 87dc1f07c4
@@ -22,6 +22,8 @@ def step_create_temp_project(context: Context) -> None:
context.added_files: list[str] = []
context.last_command_output = ""
context.last_command_exit_code = 0
context.context_files: list[str] = []
context.file_metadata: dict[str, dict[str, Any]] = {}
@given("the ACMS context service is initialized")
@@ -44,6 +46,17 @@ def step_create_context_entries(context: Context) -> None:
context.context_entries.append(entry)
@given('a file "{file_path}" exists with --tag "{tag}" and --policy "{policy}"')
def step_create_file_with_tag_and_policy(
context: Context, file_path: str, tag: str, policy: str
) -> None:
"""Create a test file with associated metadata."""
full_path = context.project_dir / file_path
full_path.parent.mkdir(parents=True, exist_ok=True)
full_path.write_text(f"# Test file: {file_path}\n")
context.file_metadata[file_path] = {"tag": tag, "policy": policy}
@given('a file "{file_path}" exists')
def step_create_file(context: Context, file_path: str) -> None:
"""Create a test file."""
@@ -57,7 +70,7 @@ def step_create_directory_with_files(context: Context, dir_path: str) -> None:
"""Create a directory with multiple files."""
dir_full_path = context.project_dir / dir_path
dir_full_path.mkdir(parents=True, exist_ok=True)
for row in context.table:
file_path = dir_full_path / row["file"]
file_path.parent.mkdir(parents=True, exist_ok=True)
@@ -76,8 +89,6 @@ def step_create_multiple_files(context: Context) -> None:
@given('"{file_path}" is already in context')
def step_file_in_context(context: Context, file_path: str) -> None:
"""Mark a file as already in context."""
if not hasattr(context, "context_files"):
context.context_files = []
context.context_files.append(file_path)
@@ -89,7 +100,7 @@ def step_run_context_list(context: Context) -> None:
context.last_command_output = "No files in context."
else:
# Create table output
lines = ["Context Files ({} total)".format(len(context.context_entries))]
lines = [f"Context Files ({len(context.context_entries)} total)"]
lines.append("File Path | Type | Size | Added")
for entry in context.context_entries:
path = Path(entry["path"]).name
@@ -129,17 +140,17 @@ def step_run_context_list_help(context: Context) -> None:
def step_run_context_add(context: Context, file_path: str) -> None:
"""Run context add command."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_output = f"Error: Path does not exist: {full_path}"
context.last_command_exit_code = 1
return
if hasattr(context, "context_files") and file_path in context.context_files:
context.last_command_output = f"File already in context: {file_path}"
context.last_command_exit_code = 0
return
context.added_files.append(file_path)
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
context.last_command_exit_code = 0
@@ -149,12 +160,12 @@ def step_run_context_add(context: Context, file_path: str) -> None:
def step_run_context_add_recursive(context: Context, file_path: str) -> None:
"""Run context add with recursive flag."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_output = f"Error: Path does not exist: {full_path}"
context.last_command_exit_code = 1
return
if full_path.is_dir():
# Count files in directory
files = list(full_path.rglob("*"))
@@ -164,7 +175,7 @@ def step_run_context_add_recursive(context: Context, file_path: str) -> None:
else:
context.added_files.append(file_path)
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
context.last_command_exit_code = 0
@@ -172,11 +183,11 @@ def step_run_context_add_recursive(context: Context, file_path: str) -> None:
def step_run_context_add_no_recursive(context: Context, file_path: str) -> None:
"""Run context add without recursive flag."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_exit_code = 1
return
context.added_files.append(file_path)
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
context.last_command_exit_code = 0
@@ -186,14 +197,11 @@ def step_run_context_add_no_recursive(context: Context, file_path: str) -> None:
def step_run_context_add_with_tag(context: Context, file_path: str, tag: str) -> None:
"""Run context add with tag."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_exit_code = 1
return
if not hasattr(context, "file_metadata"):
context.file_metadata = {}
context.file_metadata[file_path] = {"tag": tag}
context.added_files.append(file_path)
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
@@ -204,17 +212,14 @@ def step_run_context_add_with_tag(context: Context, file_path: str, tag: str) ->
def step_run_context_add_with_policy(context: Context, file_path: str, policy: str) -> None:
"""Run context add with policy."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_exit_code = 1
return
if not hasattr(context, "file_metadata"):
context.file_metadata = {}
if file_path not in context.file_metadata:
context.file_metadata[file_path] = {}
context.file_metadata[file_path]["policy"] = policy
context.added_files.append(file_path)
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
@@ -227,14 +232,14 @@ def step_run_context_add_with_tag_and_policy(
) -> None:
"""Run context add with both tag and policy."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_exit_code = 1
return
if not hasattr(context, "file_metadata"):
context.file_metadata = {}
context.file_metadata[file_path] = {"tag": tag, "policy": policy}
context.added_files.append(file_path)
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
@@ -246,17 +251,17 @@ def step_run_context_add_multiple(context: Context, file_path: str, file_path2:
"""Run context add with multiple files."""
files = [file_path, file_path2, file_path3]
added_count = 0
for f in files:
full_path = context.project_dir / f
if full_path.exists():
context.added_files.append(f)
added_count += 1
if added_count == 0:
context.last_command_exit_code = 1
return
context.last_command_output = f"✓ Added {added_count} file(s) to context"
context.last_command_exit_code = 0
@@ -279,11 +284,11 @@ def step_run_context_add_help(context: Context) -> None:
def step_run_context_add_with_format(context: Context, file_path: str, format_type: str) -> None:
"""Run context add with format."""
full_path = context.project_dir / file_path
if not full_path.exists():
context.last_command_exit_code = 1
return
if format_type == "json":
output = {
"status": "success",
@@ -293,7 +298,7 @@ def step_run_context_add_with_format(context: Context, file_path: str, format_ty
context.last_command_output = json.dumps(output, indent=2)
else:
context.last_command_output = f"✓ Added 1 file(s) to context:\n{file_path}"
context.added_files.append(file_path)
context.last_command_exit_code = 0
@@ -331,7 +336,10 @@ def step_output_no_files(context: Context) -> None:
@then("the output should display a table with columns: File Path, Type, Size, Added")
def step_output_table_columns(context: Context) -> None:
"""Verify output contains table columns."""
assert "File Path" in context.last_command_output or "file" in context.last_command_output.lower()
assert "File Path" in context.last_command_output
assert "Type" in context.last_command_output
assert "Size" in context.last_command_output
assert "Added" in context.last_command_output
@then('the table should contain "{text}"')
@@ -346,7 +354,7 @@ def step_output_valid_json(context: Context) -> None:
try:
context.json_output = json.loads(context.last_command_output)
except json.JSONDecodeError as e:
raise AssertionError(f"Output is not valid JSON: {e}")
raise AssertionError(f"Output is not valid JSON: {e}") from e
@then("the JSON output should contain an array of context entries")
@@ -361,7 +369,10 @@ def step_json_entry_keys(context: Context) -> None:
entries = context.json_output.get("entries", context.json_output)
if entries:
for entry in entries:
assert "path" in entry or "file" in entry.lower()
assert "path" in entry
assert "tier" in entry
assert "size" in entry
assert "last_accessed" in entry
@then("the output should display a table")
@@ -443,10 +454,3 @@ def step_run_context_add_no_args(context: Context) -> None:
"""Run context add without arguments."""
context.last_command_output = "Error: Missing argument 'PATHS'"
context.last_command_exit_code = 1
@when("I run context add \"nonexistent.py\"")
def step_run_context_add_nonexistent(context: Context) -> None:
"""Run context add with nonexistent file."""
context.last_command_output = "Error: Path does not exist: nonexistent.py"
context.last_command_exit_code = 1