BUG-HUNT: [boundary] Empty string for depth not handled in ContextRequest #1937

Open
opened 2026-04-03 00:18:27 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/crp-context-request-validate-depth-empty-string
  • Commit Message: fix(crp): reject empty and whitespace-only string values for ContextRequest.depth
  • Milestone: v3.4.0
  • Parent Epic: #935

Background and Context

The ContextRequest model in src/cleveragents/domain/models/acms/crp.py accepts a DetailDepth type for its depth field, which may be either an integer or a named level string (e.g., 'SIGNATURES'). The validate_depth field validator currently only guards against negative integers — it does not validate string values at all. This means an empty string ("") or a whitespace-only string (" ") can be passed as a depth value without raising a ValueError, which will propagate silently into DetailLevelMap.resolve and produce confusing downstream failures rather than a clear, early rejection at the model boundary.

Per CONTRIBUTING.md's Argument Validation and Fail-Fast guidelines, all public model validators must reject invalid inputs immediately at the boundary where they enter.

Current Behavior

ContextRequest(depth="") and ContextRequest(depth=" ") are accepted without error. The empty/whitespace string is stored and later passed to DetailLevelMap.resolve, which may raise an obscure error far from the source.

Expected Behavior

ContextRequest(depth="") and ContextRequest(depth=" ") should raise a ValueError with a clear message: "depth must not be an empty or whitespace-only string".

Acceptance Criteria

  • ContextRequest(depth="") raises ValueError with a descriptive message
  • ContextRequest(depth=" ") raises ValueError with a descriptive message
  • ContextRequest(depth="SIGNATURES") continues to be accepted without error
  • ContextRequest(depth=3) continues to be accepted without error
  • ContextRequest(depth=0) continues to be accepted without error
  • ContextRequest(depth=-1) continues to raise ValueError (existing behaviour preserved)
  • All nox stages pass
  • Coverage >= 97%

Supporting Information

  • File: src/cleveragents/domain/models/acms/crp.py
  • Class/Method: ContextRequest.validate_depth (lines 299–309)
  • Suggested fix:
@field_validator("depth")
@classmethod
def validate_depth(
    cls: type[ContextRequest],
    v: DetailDepth,
) -> DetailDepth:
    """Ensure integer depths are non-negative and string depths are not empty."""
    if isinstance(v, int):
        if v < 0:
            raise ValueError("depth must be non-negative when specified as an integer")
    elif isinstance(v, str):
        if not v.strip():
            raise ValueError("depth must not be an empty or whitespace-only string")
    return v
  • Related: Similar boundary fix applied in #1851 (AnalyzerRegistry.supported_extensions) and #1764 (validate_turtle_file)

Subtasks

  • Update ContextRequest.validate_depth in src/cleveragents/domain/models/acms/crp.py to reject empty/whitespace-only strings
  • Tests (Behave): Add scenarios for empty string and whitespace-only string depth values in features/ (unit level)
  • Tests (Robot): Add integration-level scenario asserting ContextRequest rejects invalid string depths
  • Verify coverage >= 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (fix(crp): reject empty and whitespace-only string values for ContextRequest.depth), followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (fix/crp-context-request-validate-depth-empty-string).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage >= 97%.

Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/crp-context-request-validate-depth-empty-string` - **Commit Message**: `fix(crp): reject empty and whitespace-only string values for ContextRequest.depth` - **Milestone**: v3.4.0 - **Parent Epic**: #935 ## Background and Context The `ContextRequest` model in `src/cleveragents/domain/models/acms/crp.py` accepts a `DetailDepth` type for its `depth` field, which may be either an integer or a named level string (e.g., `'SIGNATURES'`). The `validate_depth` field validator currently only guards against negative integers — it does not validate string values at all. This means an empty string (`""`) or a whitespace-only string (`" "`) can be passed as a depth value without raising a `ValueError`, which will propagate silently into `DetailLevelMap.resolve` and produce confusing downstream failures rather than a clear, early rejection at the model boundary. Per CONTRIBUTING.md's Argument Validation and Fail-Fast guidelines, all public model validators must reject invalid inputs immediately at the boundary where they enter. ## Current Behavior `ContextRequest(depth="")` and `ContextRequest(depth=" ")` are accepted without error. The empty/whitespace string is stored and later passed to `DetailLevelMap.resolve`, which may raise an obscure error far from the source. ## Expected Behavior `ContextRequest(depth="")` and `ContextRequest(depth=" ")` should raise a `ValueError` with a clear message: `"depth must not be an empty or whitespace-only string"`. ## Acceptance Criteria - [ ] `ContextRequest(depth="")` raises `ValueError` with a descriptive message - [ ] `ContextRequest(depth=" ")` raises `ValueError` with a descriptive message - [ ] `ContextRequest(depth="SIGNATURES")` continues to be accepted without error - [ ] `ContextRequest(depth=3)` continues to be accepted without error - [ ] `ContextRequest(depth=0)` continues to be accepted without error - [ ] `ContextRequest(depth=-1)` continues to raise `ValueError` (existing behaviour preserved) - [ ] All nox stages pass - [ ] Coverage >= 97% ## Supporting Information - **File**: `src/cleveragents/domain/models/acms/crp.py` - **Class/Method**: `ContextRequest.validate_depth` (lines 299–309) - **Suggested fix**: ```python @field_validator("depth") @classmethod def validate_depth( cls: type[ContextRequest], v: DetailDepth, ) -> DetailDepth: """Ensure integer depths are non-negative and string depths are not empty.""" if isinstance(v, int): if v < 0: raise ValueError("depth must be non-negative when specified as an integer") elif isinstance(v, str): if not v.strip(): raise ValueError("depth must not be an empty or whitespace-only string") return v ``` - **Related**: Similar boundary fix applied in #1851 (`AnalyzerRegistry.supported_extensions`) and #1764 (`validate_turtle_file`) ## Subtasks - [ ] Update `ContextRequest.validate_depth` in `src/cleveragents/domain/models/acms/crp.py` to reject empty/whitespace-only strings - [ ] Tests (Behave): Add scenarios for empty string and whitespace-only string depth values in `features/` (unit level) - [ ] Tests (Robot): Add integration-level scenario asserting `ContextRequest` rejects invalid string depths - [ ] Verify coverage >= 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`fix(crp): reject empty and whitespace-only string values for ContextRequest.depth`), followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`fix/crp-context-request-validate-depth-empty-string`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - Coverage >= 97%. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: ca-new-issue-creator
freemo added this to the v3.4.0 milestone 2026-04-03 00:18:51 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • MoSCoW: MoSCoW/Should Have — bug or error handling improvement.

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **MoSCoW**: MoSCoW/Should Have — bug or error handling improvement. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
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.

Reference
cleveragents/cleveragents-core#1937
No description provided.