BUG-HUNT: [boundary] Whitespace-only path not handled in validate_turtle_file #1764

Open
opened 2026-04-02 23:45:29 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/boundary-validate-turtle-file-whitespace-path
  • Commit Message: fix(acms): raise ValueError for whitespace-only path in validate_turtle_file
  • Milestone: v3.7.0
  • Parent Epic: #1669

Background and Context

The validate_turtle_file function in src/cleveragents/domain/models/acms/_turtle_validation.py guards against an empty path by checking if not path, but this check does not catch paths that consist entirely of whitespace characters (e.g., " " or "\t\n"). Such a path would pass the guard, be handed to Path(path), and then fail with a FileNotFoundError or silently produce unexpected behaviour downstream rather than the semantically correct ValueError.

Current Behavior

# Lines 153-154 of _turtle_validation.py
if not path:
    raise ValueError("Path must not be empty")

Calling validate_turtle_file(" ") does not raise a ValueError; instead the call proceeds to Path(" ").exists(), which returns False, and a FileNotFoundError is raised — an incorrect exception type for what is fundamentally an invalid-input condition.

Expected Behavior

validate_turtle_file should raise a ValueError with a clear message whenever the supplied path is empty or consists only of whitespace, before any filesystem interaction occurs.

Acceptance Criteria

  • validate_turtle_file("") raises ValueError.
  • validate_turtle_file(" ") raises ValueError.
  • validate_turtle_file("\t\n") raises ValueError.
  • validate_turtle_file(Path(" ")) raises ValueError.
  • All existing passing tests continue to pass.
  • The docstring for validate_turtle_file is updated to document the whitespace case.

Supporting Information

Suggested fix:

def validate_turtle_file(path: str | Path) -> list[str]:
    if not path or not str(path).strip():
        raise ValueError("Path must not be empty or contain only whitespace")
    p = Path(path)
    if not p.exists():
        raise FileNotFoundError(f"Turtle file not found: {p}")
    content = p.read_text(encoding="utf-8")
    return validate_turtle(content)

Severity: Low — unlikely in production but represents a boundary-condition gap that violates the principle of failing fast with the correct exception type.

Location: src/cleveragents/domain/models/acms/_turtle_validation.py, function validate_turtle_file, lines 153–154.

Subtasks

  • Update validate_turtle_file to strip the path string and raise ValueError for whitespace-only input
  • Update the function docstring to document the whitespace-path case
  • Tests (Behave): Add Gherkin scenarios covering whitespace-only path inputs ("", " ", "\t\n", Path(" "))
  • Tests (Robot): Add integration-level test for the whitespace-path guard
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Run nox (all default sessions) and 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(acms): raise ValueError for whitespace-only path in validate_turtle_file), followed by a blank line, then additional lines providing relevant implementation details.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (fix/boundary-validate-turtle-file-whitespace-path).
  • 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/boundary-validate-turtle-file-whitespace-path` - **Commit Message**: `fix(acms): raise ValueError for whitespace-only path in validate_turtle_file` - **Milestone**: v3.7.0 - **Parent Epic**: #1669 ## Background and Context The `validate_turtle_file` function in `src/cleveragents/domain/models/acms/_turtle_validation.py` guards against an empty path by checking `if not path`, but this check does not catch paths that consist entirely of whitespace characters (e.g., `" "` or `"\t\n"`). Such a path would pass the guard, be handed to `Path(path)`, and then fail with a `FileNotFoundError` or silently produce unexpected behaviour downstream rather than the semantically correct `ValueError`. ## Current Behavior ```python # Lines 153-154 of _turtle_validation.py if not path: raise ValueError("Path must not be empty") ``` Calling `validate_turtle_file(" ")` does **not** raise a `ValueError`; instead the call proceeds to `Path(" ").exists()`, which returns `False`, and a `FileNotFoundError` is raised — an incorrect exception type for what is fundamentally an invalid-input condition. ## Expected Behavior `validate_turtle_file` should raise a `ValueError` with a clear message whenever the supplied path is empty **or** consists only of whitespace, before any filesystem interaction occurs. ## Acceptance Criteria - `validate_turtle_file("")` raises `ValueError`. - `validate_turtle_file(" ")` raises `ValueError`. - `validate_turtle_file("\t\n")` raises `ValueError`. - `validate_turtle_file(Path(" "))` raises `ValueError`. - All existing passing tests continue to pass. - The docstring for `validate_turtle_file` is updated to document the whitespace case. ## Supporting Information **Suggested fix:** ```python def validate_turtle_file(path: str | Path) -> list[str]: if not path or not str(path).strip(): raise ValueError("Path must not be empty or contain only whitespace") p = Path(path) if not p.exists(): raise FileNotFoundError(f"Turtle file not found: {p}") content = p.read_text(encoding="utf-8") return validate_turtle(content) ``` **Severity:** Low — unlikely in production but represents a boundary-condition gap that violates the principle of failing fast with the correct exception type. **Location:** `src/cleveragents/domain/models/acms/_turtle_validation.py`, function `validate_turtle_file`, lines 153–154. ## Subtasks - [ ] Update `validate_turtle_file` to strip the path string and raise `ValueError` for whitespace-only input - [ ] Update the function docstring to document the whitespace-path case - [ ] Tests (Behave): Add Gherkin scenarios covering whitespace-only path inputs (`""`, `" "`, `"\t\n"`, `Path(" ")`) - [ ] Tests (Robot): Add integration-level test for the whitespace-path guard - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions) and 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(acms): raise ValueError for whitespace-only path in validate_turtle_file`), followed by a blank line, then additional lines providing relevant implementation details. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`fix/boundary-validate-turtle-file-whitespace-path`). - 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.7.0 milestone 2026-04-02 23:45:51 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • MoSCoW: MoSCoW/Should Have — bug or spec compliance issue.

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

Issue triaged by project owner: - **State**: Verified - **MoSCoW**: MoSCoW/Should Have — bug or spec compliance issue. --- **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.

Blocks
#1669 Bug Hunting Session
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#1764
No description provided.