UAT: ValidationAttachmentRepository.attach() silently swaps validation_name and resource_id arguments — violates fail-fast principle #2970

Open
opened 2026-04-05 02:59:07 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/validation-attachment-repo-silent-arg-swap
  • Commit Message: fix(repositories): remove silent argument swap heuristic from ValidationAttachmentRepository.attach()
  • Milestone: v3.7.0
  • Parent Epic: #362

What Was Tested

The ValidationAttachmentRepository.attach() method in src/cleveragents/infrastructure/database/repositories.py was analyzed against the specification and CONTRIBUTING.md coding standards.

Expected Behavior (from spec and CONTRIBUTING.md)

Per CONTRIBUTING.md:

"Public and protected methods must validate arguments as the first step (fail-fast)."
"Exceptions must be allowed to propagate to the top-level execution. Errors should never be suppressed."

When validation_name and resource_id are passed in the wrong order, the method should raise a clear error, not silently correct the caller's mistake.

Actual Behavior

In src/cleveragents/infrastructure/database/repositories.py, ValidationAttachmentRepository.attach() (lines 3790–3791):

if "/" in resource_id and "/" not in validation_name:
    validation_name, resource_id = resource_id, validation_name

This heuristic silently swaps the arguments when it detects they appear to be in the wrong order (based on whether they contain a "/" character). This:

  1. Violates fail-fast: Instead of raising a ValueError for incorrect argument order, it silently "fixes" the caller's bug.
  2. Hides bugs: Callers that pass arguments in the wrong order will never know — their code is silently "corrected."
  3. Is fragile: The heuristic assumes validation names always contain "/" and resource IDs sometimes don't — but both can contain "/" (e.g., resource IDs like "git-checkout/my-repo" and validation names like "local/lint-check" both contain "/").
  4. Can produce wrong results: If both validation_name and resource_id contain "/" (the common case), the swap is never triggered even when arguments are wrong.

Steps to Reproduce

  1. Call attach(validation_name="git-checkout/my-repo", resource_id="local/lint-check", ...) (arguments swapped)
  2. Observe: The method silently swaps them and creates an attachment with the wrong association
  3. No error is raised; the caller has no indication that arguments were wrong

Code Location

  • src/cleveragents/infrastructure/database/repositories.py, ValidationAttachmentRepository.attach(), lines 3790–3791
  • Fix: Remove the silent swap heuristic entirely. The method should trust its callers to pass arguments correctly, and the CLI/service layer should be responsible for correct argument ordering.

Severity

High — this is a data integrity issue. Silent argument swapping can create incorrect validation attachments that are difficult to detect and debug. It also violates the project's explicit fail-fast coding standard.

Subtasks

  • Locate ValidationAttachmentRepository.attach() in src/cleveragents/infrastructure/database/repositories.py (lines 3790–3791)
  • Remove the silent argument-swap heuristic (if "/" in resource_id and "/" not in validation_name: validation_name, resource_id = resource_id, validation_name)
  • Add explicit fail-fast argument validation (e.g., raise ValueError if validation_name or resource_id are empty or clearly malformed)
  • Update or add Behave BDD unit test scenarios covering: correct argument order succeeds, swapped arguments are NOT silently corrected, malformed arguments raise ValueError
  • Verify no callers in the codebase rely on the silent-swap behaviour (grep for attach( calls on ValidationAttachmentRepository)
  • Run nox -e lint, nox -e typecheck, nox -e unit_tests, nox -e coverage_report and confirm all pass
  • Open PR, link to this issue, obtain 2 approving reviews, merge

Definition of Done

  • The silent argument-swap heuristic is removed from ValidationAttachmentRepository.attach()
  • The method raises a clear, descriptive exception (not silently corrects) when called with arguments in the wrong order or with invalid values
  • All existing callers pass arguments in the correct order (verified by code search and test coverage)
  • New Behave BDD scenarios cover the corrected behaviour and the error path
  • All nox stages pass
  • Coverage >= 97%
  • PR is merged and this issue is closed

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

## Metadata - **Branch**: `fix/validation-attachment-repo-silent-arg-swap` - **Commit Message**: `fix(repositories): remove silent argument swap heuristic from ValidationAttachmentRepository.attach()` - **Milestone**: v3.7.0 - **Parent Epic**: #362 ## What Was Tested The `ValidationAttachmentRepository.attach()` method in `src/cleveragents/infrastructure/database/repositories.py` was analyzed against the specification and CONTRIBUTING.md coding standards. ## Expected Behavior (from spec and CONTRIBUTING.md) Per CONTRIBUTING.md: > "Public and protected methods must validate arguments as the first step (fail-fast)." > "Exceptions must be allowed to propagate to the top-level execution. Errors should never be suppressed." When `validation_name` and `resource_id` are passed in the wrong order, the method should raise a clear error, not silently correct the caller's mistake. ## Actual Behavior In `src/cleveragents/infrastructure/database/repositories.py`, `ValidationAttachmentRepository.attach()` (lines 3790–3791): ```python if "/" in resource_id and "/" not in validation_name: validation_name, resource_id = resource_id, validation_name ``` This heuristic silently swaps the arguments when it detects they appear to be in the wrong order (based on whether they contain a "/" character). This: 1. **Violates fail-fast**: Instead of raising a `ValueError` for incorrect argument order, it silently "fixes" the caller's bug. 2. **Hides bugs**: Callers that pass arguments in the wrong order will never know — their code is silently "corrected." 3. **Is fragile**: The heuristic assumes validation names always contain "/" and resource IDs sometimes don't — but both can contain "/" (e.g., resource IDs like "git-checkout/my-repo" and validation names like "local/lint-check" both contain "/"). 4. **Can produce wrong results**: If both `validation_name` and `resource_id` contain "/" (the common case), the swap is never triggered even when arguments are wrong. ## Steps to Reproduce 1. Call `attach(validation_name="git-checkout/my-repo", resource_id="local/lint-check", ...)` (arguments swapped) 2. Observe: The method silently swaps them and creates an attachment with the wrong association 3. No error is raised; the caller has no indication that arguments were wrong ## Code Location - `src/cleveragents/infrastructure/database/repositories.py`, `ValidationAttachmentRepository.attach()`, lines 3790–3791 - Fix: Remove the silent swap heuristic entirely. The method should trust its callers to pass arguments correctly, and the CLI/service layer should be responsible for correct argument ordering. ## Severity High — this is a data integrity issue. Silent argument swapping can create incorrect validation attachments that are difficult to detect and debug. It also violates the project's explicit fail-fast coding standard. ## Subtasks - [ ] Locate `ValidationAttachmentRepository.attach()` in `src/cleveragents/infrastructure/database/repositories.py` (lines 3790–3791) - [ ] Remove the silent argument-swap heuristic (`if "/" in resource_id and "/" not in validation_name: validation_name, resource_id = resource_id, validation_name`) - [ ] Add explicit fail-fast argument validation (e.g., raise `ValueError` if `validation_name` or `resource_id` are empty or clearly malformed) - [ ] Update or add Behave BDD unit test scenarios covering: correct argument order succeeds, swapped arguments are NOT silently corrected, malformed arguments raise `ValueError` - [ ] Verify no callers in the codebase rely on the silent-swap behaviour (grep for `attach(` calls on `ValidationAttachmentRepository`) - [ ] Run `nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e coverage_report` and confirm all pass - [ ] Open PR, link to this issue, obtain 2 approving reviews, merge ## Definition of Done - [ ] The silent argument-swap heuristic is removed from `ValidationAttachmentRepository.attach()` - [ ] The method raises a clear, descriptive exception (not silently corrects) when called with arguments in the wrong order or with invalid values - [ ] All existing callers pass arguments in the correct order (verified by code search and test coverage) - [ ] New Behave BDD scenarios cover the corrected behaviour and the error path - [ ] All nox stages pass - [ ] Coverage >= 97% - [ ] PR is merged and this issue is closed --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.7.0 milestone 2026-04-05 02:59:14 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Confirmed
  • MoSCoW: Should Have — spec compliance issue

Valid UAT finding verified during batch triage.


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

Issue triaged by project owner: - **State**: Verified - **Priority**: Confirmed - **MoSCoW**: Should Have — spec compliance issue Valid UAT finding verified during batch triage. --- **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
#362 Epic: Security & Safety Hardening
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#2970
No description provided.