UAT: agents invariant add silently defaults to --global scope when no scope flag is provided — spec requires an error #3984

Open
opened 2026-04-06 08:16:54 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/backlog-invariant-add-scope-flag-required
  • Commit Message: fix(invariant): require explicit scope flag in invariant add command
  • Milestone: None (Backlog)
  • Parent Epic: #3370

Summary

The agents invariant add CLI command silently defaults to --global scope when no scope flag is provided. The specification (line 17808) explicitly states: "At least one scope flag (--global, --project, --plan, or --action) must be provided." The implementation should raise an error when no scope flag is given, but instead silently creates a global invariant.

Backlog note: This issue was discovered during autonomous UAT 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.

Current Behavior

Running agents invariant add "Never delete production data" (with no scope flag) silently creates a global invariant with source_name="system" instead of raising an error.

The _resolve_scope() function in src/cleveragents/cli/commands/invariant.py (lines 73-88) has this comment:

# Default to global
return InvariantScope.GLOBAL, "system"

The module docstring also says "If no scope flag is given, --global is assumed." — contradicting the specification.

Expected Behavior

Per spec (line 17808): "At least one scope flag (--global, --project, --plan, or --action) must be provided."

Running agents invariant add "Never delete production data" with no scope flag should raise a typer.BadParameter error with a message like: "At least one scope flag must be provided: --global, --project, --plan, or --action"

Steps to Reproduce

  1. Run: agents invariant add "Never delete production data" (no scope flag)
  2. Observe: Command succeeds and creates a global invariant
  3. Expected: Command fails with an error requiring a scope flag

Code Location

  • File: src/cleveragents/cli/commands/invariant.py
  • Function: _resolve_scope() (lines 73-88)
  • Fix: Remove the default-to-global fallback and raise typer.BadParameter when flags_set == 0

Subtasks

  • Update _resolve_scope() to raise typer.BadParameter when no scope flag is provided
  • Update module docstring to remove "If no scope flag is given, --global is assumed."
  • Add Behave BDD test: agents invariant add with no scope flag raises error
  • Verify existing tests still pass
  • Run nox (all default sessions), fix any errors
  • Verify coverage >= 97% via nox -s coverage_report

Definition of Done

  • agents invariant add "text" (no scope flag) raises a clear error message
  • agents invariant add --global "text" still works correctly
  • Unit tests cover the no-scope-flag error case
  • Code passes nox -e typecheck and nox -e unit_tests
  • All nox stages pass
  • Coverage >= 97%

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

## Metadata - **Branch**: `fix/backlog-invariant-add-scope-flag-required` - **Commit Message**: `fix(invariant): require explicit scope flag in invariant add command` - **Milestone**: None (Backlog) - **Parent Epic**: #3370 ## Summary The `agents invariant add` CLI command silently defaults to `--global` scope when no scope flag is provided. The specification (line 17808) explicitly states: "At least one scope flag (`--global`, `--project`, `--plan`, or `--action`) must be provided." The implementation should raise an error when no scope flag is given, but instead silently creates a global invariant. > **Backlog note:** This issue was discovered during autonomous UAT 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. ## Current Behavior Running `agents invariant add "Never delete production data"` (with no scope flag) silently creates a global invariant with `source_name="system"` instead of raising an error. The `_resolve_scope()` function in `src/cleveragents/cli/commands/invariant.py` (lines 73-88) has this comment: ```python # Default to global return InvariantScope.GLOBAL, "system" ``` The module docstring also says "If no scope flag is given, `--global` is assumed." — contradicting the specification. ## Expected Behavior Per spec (line 17808): "At least one scope flag (`--global`, `--project`, `--plan`, or `--action`) must be provided." Running `agents invariant add "Never delete production data"` with no scope flag should raise a `typer.BadParameter` error with a message like: "At least one scope flag must be provided: --global, --project, --plan, or --action" ## Steps to Reproduce 1. Run: `agents invariant add "Never delete production data"` (no scope flag) 2. Observe: Command succeeds and creates a global invariant 3. Expected: Command fails with an error requiring a scope flag ## Code Location - **File**: `src/cleveragents/cli/commands/invariant.py` - **Function**: `_resolve_scope()` (lines 73-88) - **Fix**: Remove the default-to-global fallback and raise `typer.BadParameter` when `flags_set == 0` ## Subtasks - [ ] Update `_resolve_scope()` to raise `typer.BadParameter` when no scope flag is provided - [ ] Update module docstring to remove "If no scope flag is given, `--global` is assumed." - [ ] Add Behave BDD test: `agents invariant add` with no scope flag raises error - [ ] Verify existing tests still pass - [ ] Run `nox` (all default sessions), fix any errors - [ ] Verify coverage >= 97% via `nox -s coverage_report` ## Definition of Done - [ ] `agents invariant add "text"` (no scope flag) raises a clear error message - [ ] `agents invariant add --global "text"` still works correctly - [ ] Unit tests cover the no-scope-flag error case - [ ] Code passes `nox -e typecheck` and `nox -e unit_tests` - All nox stages pass - Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:12:16 +00:00
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#3984
No description provided.