From 4fe87d9eec06ed9b641c84c558a45bd2a5bf08e5 Mon Sep 17 00:00:00 2001 From: Rui Hu Date: Thu, 7 May 2026 08:16:24 +0000 Subject: [PATCH] fix(tests): resolve pre-existing unit test failures in 5 feature files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix five pre-existing BDD test failures that were present on master before PR #10988 was opened: 1. **architecture.feature** — Converted `IndexEntry` from `@dataclass` to Pydantic `BaseModel` and `ACMSIndex` to a plain class so the "all dataclasses should use Pydantic models" check passes. 2. **pr_compliance_checklist.feature** — Fixed `PROJECT_ROOT` path resolution from `parents[3]` to `parents[2]` so the agent definition file at `.opencode/agents/implementation-supervisor.md` is located correctly within the `/app` workspace. 3. **acms/index_data_model_and_traversal.feature** — Added missing Gherkin table header rows (`| key | value |` and `| filter | value |`) to the "Create an index entry" and "Combined query with multiple filters" scenarios so behave correctly resolves column references. 4. **cli_init_yes_flag.feature** — Added a `getattr` guard around `context.temp_dir` in `_restore_cwd()` so cleanup does not crash with a `TypeError` when `temp_dir` was never assigned. 5. **security_audit.feature** — Renamed the ACMS step from "the count should be {count:d}" to "the ACMS entry count should be {count:d}" to resolve a step ambiguity where ACMS's `step_check_entry_count_value` shadowed security_audit's `step_count_is`, causing `AttributeError` on `context.entry_count` for audit scenarios. These failures are pre-existing on master and are independent of the PassSuppressFormatter feature in the preceding commit. They are fixed in a separate commit to maintain commit atomicity — the feature commit remains solely about the output suppression change. Refs: #10987 --- .../acms/index_data_model_and_traversal.feature | 4 +++- .../steps/acms_index_data_model_traversal_steps.py | 2 +- features/steps/cli_init_yes_flag_steps.py | 3 ++- features/steps/pr_compliance_checklist_steps.py | 2 +- src/cleveragents/acms/index.py | 14 +++++++------- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/features/acms/index_data_model_and_traversal.feature b/features/acms/index_data_model_and_traversal.feature index f94da8e69..015d81100 100644 --- a/features/acms/index_data_model_and_traversal.feature +++ b/features/acms/index_data_model_and_traversal.feature @@ -9,6 +9,7 @@ Feature: ACMS Index Data Model and File Traversal Engine Scenario: Create an index entry with file metadata When I create an index entry with: + | key | value | | path | /project/src/main.py | | file_type | python | | size_bytes | 1024 | @@ -116,7 +117,7 @@ Feature: ACMS Index Data Model and File Traversal Engine Scenario: Get entry count from index Given I have an index with 10 entries When I get the entry count - Then the count should be 10 + Then the ACMS entry count should be 10 Scenario: Remove entry from index Given I have an index with 3 entries @@ -131,6 +132,7 @@ Feature: ACMS Index Data Model and File Traversal Engine | /project/tests/test_main.py | python | test | cold | | /project/docs/readme.md | markdown | docs | cold | When I query the index with filters: + | filter | value | | path_pattern | src | | file_type | python | | tier | hot | diff --git a/features/steps/acms_index_data_model_traversal_steps.py b/features/steps/acms_index_data_model_traversal_steps.py index f7e95aaff..c3c2f7554 100644 --- a/features/steps/acms_index_data_model_traversal_steps.py +++ b/features/steps/acms_index_data_model_traversal_steps.py @@ -361,7 +361,7 @@ def step_get_entry_count(context): context.entry_count = context.index.get_entry_count() -@then("the count should be {count:d}") +@then("the ACMS entry count should be {count:d}") def step_check_entry_count_value(context, count): """Verify the entry count matches the expected value.""" assert context.entry_count == count diff --git a/features/steps/cli_init_yes_flag_steps.py b/features/steps/cli_init_yes_flag_steps.py index 2c77b4801..3828deb31 100644 --- a/features/steps/cli_init_yes_flag_steps.py +++ b/features/steps/cli_init_yes_flag_steps.py @@ -27,7 +27,8 @@ def _restore_cwd(context): os.environ.pop("CLEVERAGENTS_HOME", None) else: os.environ["CLEVERAGENTS_HOME"] = context._init_original_home - shutil.rmtree(context.temp_dir, ignore_errors=True) + if getattr(context, "temp_dir", None) is not None: + shutil.rmtree(context.temp_dir, ignore_errors=True) def _create_init_mocks(context): diff --git a/features/steps/pr_compliance_checklist_steps.py b/features/steps/pr_compliance_checklist_steps.py index 19f92172a..badfba79a 100644 --- a/features/steps/pr_compliance_checklist_steps.py +++ b/features/steps/pr_compliance_checklist_steps.py @@ -5,7 +5,7 @@ from typing import Any from behave import given, then, when -PROJECT_ROOT = Path(__file__).resolve().parents[3] +PROJECT_ROOT = Path(__file__).resolve().parents[2] AGENT_DEF_PATH = PROJECT_ROOT / ".opencode" / "agents" / "implementation-supervisor.md" diff --git a/src/cleveragents/acms/index.py b/src/cleveragents/acms/index.py index 549cf8849..2a3745446 100644 --- a/src/cleveragents/acms/index.py +++ b/src/cleveragents/acms/index.py @@ -10,11 +10,12 @@ Based on issue #9579 and ``docs/specification.md`` ~lines 44405-44420. from __future__ import annotations from collections.abc import Iterator -from dataclasses import dataclass, field from datetime import datetime from enum import StrEnum from pathlib import Path +from pydantic import BaseModel, Field + class FileType(StrEnum): """File type enumeration for index entries.""" @@ -45,8 +46,7 @@ class TierLevel(StrEnum): ARCHIVE = "archive" # Reference -@dataclass -class IndexEntry: +class IndexEntry(BaseModel): """Represents a single indexed context entry. Attributes: @@ -65,9 +65,9 @@ class IndexEntry: size_bytes: int created_at: datetime modified_at: datetime - tags: set[str] = field(default_factory=set) + tags: set[str] = Field(default_factory=set) tier: TierLevel = TierLevel.COLD - metadata: dict[str, str] = field(default_factory=dict) + metadata: dict[str, str] = Field(default_factory=dict) def add_tag(self, tag: str) -> None: """Add a tag to this entry. @@ -104,7 +104,6 @@ class IndexEntry: self.tier = tier -@dataclass class ACMSIndex: """ACMS Index for storing and querying indexed context entries. @@ -115,7 +114,8 @@ class ACMSIndex: entries: Dictionary mapping file paths to IndexEntry objects """ - entries: dict[str, IndexEntry] = field(default_factory=dict) + def __init__(self) -> None: + self.entries: dict[str, IndexEntry] = {} def add_entry(self, entry: IndexEntry) -> None: """Add an index entry to the index.