UAT: ErrorPatternService.record_failure() missing fail-fast argument validation — violates spec code standards #3732

Open
opened 2026-04-05 22:20:45 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/error-pattern-service-argument-validation
  • Commit Message: fix(services): add fail-fast argument validation to ErrorPatternService.record_failure()
  • Milestone: (none — backlog)
  • Parent Epic: #394

Background

The specification (CONTRIBUTING.md) requires: "All public and protected methods must validate their arguments as the first step of execution (fail-fast). This includes checks for value ranges, nulls, expected types, and empty strings/collections."

ErrorPatternService.record_failure() in src/cleveragents/application/services/error_pattern_service.py does not validate its pattern_text or failure_description arguments before use. Passing an empty string or whitespace-only string will silently create a pattern with an empty/blank text, which will then match incorrectly against future context lookups.

Affected File

  • src/cleveragents/application/services/error_pattern_service.py

Code Location

ErrorPatternService.record_failure() (lines ~20-55):

def record_failure(
    self,
    pattern_text: str,
    failure_description: str,
    preventive_checks: tuple[str, ...] = (),
    keywords: tuple[str, ...] = (),
) -> ErrorPattern:
    """Record a new failure or update frequency of an existing pattern."""
    # Check if similar pattern already exists
    existing = self._find_existing_pattern(pattern_text)
    ...

No validation of pattern_text or failure_description before use.

Steps to Reproduce

  1. Instantiate ErrorPatternService()
  2. Call service.record_failure("", "some failure") — no exception raised
  3. Call service.record_failure(" ", "some failure") — no exception raised (whitespace-only)
  4. Call service.record_failure("valid pattern", "") — no exception raised

Expected Behaviour

record_failure() should raise ValidationError (from cleveragents.core.exceptions) immediately when:

  • pattern_text is empty or whitespace-only
  • failure_description is empty or whitespace-only

Actual Behaviour

No validation is performed. Empty/blank patterns are silently created, corrupting the error pattern database.

Subtasks

  • Add fail-fast validation at the start of record_failure() for pattern_text and failure_description
  • Add Behave scenario verifying ValidationError is raised for empty pattern_text
  • Add Behave scenario verifying ValidationError is raised for empty failure_description
  • Verify nox -e unit_tests passes

Definition of Done

  • record_failure() raises ValidationError for empty/whitespace pattern_text or failure_description
  • Behave tests cover the validation cases
  • nox -e unit_tests passes
  • PR merged

Backlog note: This issue was discovered during autonomous operation
on milestone v3.6.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.


Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/error-pattern-service-argument-validation` - **Commit Message**: `fix(services): add fail-fast argument validation to ErrorPatternService.record_failure()` - **Milestone**: *(none — backlog)* - **Parent Epic**: #394 ## Background The specification (CONTRIBUTING.md) requires: *"All public and protected methods must validate their arguments as the first step of execution (fail-fast). This includes checks for value ranges, nulls, expected types, and empty strings/collections."* `ErrorPatternService.record_failure()` in `src/cleveragents/application/services/error_pattern_service.py` does **not** validate its `pattern_text` or `failure_description` arguments before use. Passing an empty string or whitespace-only string will silently create a pattern with an empty/blank text, which will then match incorrectly against future context lookups. ## Affected File - `src/cleveragents/application/services/error_pattern_service.py` ## Code Location `ErrorPatternService.record_failure()` (lines ~20-55): ```python def record_failure( self, pattern_text: str, failure_description: str, preventive_checks: tuple[str, ...] = (), keywords: tuple[str, ...] = (), ) -> ErrorPattern: """Record a new failure or update frequency of an existing pattern.""" # Check if similar pattern already exists existing = self._find_existing_pattern(pattern_text) ... ``` No validation of `pattern_text` or `failure_description` before use. ## Steps to Reproduce 1. Instantiate `ErrorPatternService()` 2. Call `service.record_failure("", "some failure")` — no exception raised 3. Call `service.record_failure(" ", "some failure")` — no exception raised (whitespace-only) 4. Call `service.record_failure("valid pattern", "")` — no exception raised ## Expected Behaviour `record_failure()` should raise `ValidationError` (from `cleveragents.core.exceptions`) immediately when: - `pattern_text` is empty or whitespace-only - `failure_description` is empty or whitespace-only ## Actual Behaviour No validation is performed. Empty/blank patterns are silently created, corrupting the error pattern database. ## Subtasks - [ ] Add fail-fast validation at the start of `record_failure()` for `pattern_text` and `failure_description` - [ ] Add Behave scenario verifying `ValidationError` is raised for empty `pattern_text` - [ ] Add Behave scenario verifying `ValidationError` is raised for empty `failure_description` - [ ] Verify `nox -e unit_tests` passes ## Definition of Done - `record_failure()` raises `ValidationError` for empty/whitespace `pattern_text` or `failure_description` - Behave tests cover the validation cases - `nox -e unit_tests` passes - PR merged > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.6.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Blocks
#394 Epic: Decision Framework
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#3732
No description provided.