UAT: agents invariant add silently defaults to --global when no scope flag is provided — spec requires at least one scope flag #2094

Closed
opened 2026-04-03 04:01:53 +00:00 by freemo · 2 comments
Owner

Metadata

  • Branch: fix/invariant-add-require-scope-flag
  • Commit Message: fix(cli): require at least one scope flag for invariant add command
  • Milestone: v3.7.0
  • Parent Epic: #936

Description

The specification (docs/specification.md line 17808) states: "At least one scope flag (--global, --project, --plan, or --action) must be provided."

However, the current implementation in src/cleveragents/cli/commands/invariant.py silently defaults to global scope when no scope flag is given. The _resolve_scope() helper (lines 70–97) returns (InvariantScope.GLOBAL, "system") when all flags are False/None, instead of raising an error.

Current Behavior:

  • agents invariant add "Some constraint" (no scope flag) → exit code 0, invariant added as global
  • No error or warning is shown to the user

Expected Behavior (per spec):

  • agents invariant add "Some constraint" (no scope flag) → exit code non-zero, error: "At least one scope flag (--global, --project, --plan, or --action) must be provided"

Code Location: src/cleveragents/cli/commands/invariant.py, _resolve_scope() function (lines 70–97). When flags_set == 0, the function falls through to return InvariantScope.GLOBAL, "system" instead of raising typer.BadParameter.

Steps to Reproduce:

  1. Run: agents invariant add "Never delete production data" (no scope flag)
  2. Observe: command succeeds with exit code 0, invariant is silently added as global scope

Spec References:

  • docs/specification.md line 17808: "At least one scope flag (--global, --project, --plan, or --action) must be provided. --plan and --action can be repeated to attach the same invariant to multiple plans or actions."
  • docs/specification.md lines 17780–17790: Warning box — "Exactly one scope flag is required for add and list."

Subtasks

  • In _resolve_scope() (lines 70–97 of src/cleveragents/cli/commands/invariant.py), replace the silent fallback to InvariantScope.GLOBAL with a typer.BadParameter raise when flags_set == 0
  • Ensure the error message matches the spec: "At least one scope flag (--global, --project, --plan, or --action) must be provided"
  • Verify exit code is non-zero on missing scope flag
  • Tests (Behave): Add scenario for agents invariant add with no scope flag → expect non-zero exit and correct error message
  • Tests (Behave): Confirm existing scenarios with valid scope flags still pass
  • Tests (Robot): Add integration test asserting the error path for missing scope flag
  • 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 fix(cli): require at least one scope flag for invariant add command exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on branch fix/invariant-add-require-scope-flag exactly.
  • 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: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/invariant-add-require-scope-flag` - **Commit Message**: `fix(cli): require at least one scope flag for invariant add command` - **Milestone**: v3.7.0 - **Parent Epic**: #936 ## Description The specification (`docs/specification.md` line 17808) states: "At least one scope flag (`--global`, `--project`, `--plan`, or `--action`) must be provided." However, the current implementation in `src/cleveragents/cli/commands/invariant.py` silently defaults to global scope when no scope flag is given. The `_resolve_scope()` helper (lines 70–97) returns `(InvariantScope.GLOBAL, "system")` when all flags are `False`/`None`, instead of raising an error. **Current Behavior:** - `agents invariant add "Some constraint"` (no scope flag) → exit code 0, invariant added as global - No error or warning is shown to the user **Expected Behavior (per spec):** - `agents invariant add "Some constraint"` (no scope flag) → exit code non-zero, error: `"At least one scope flag (--global, --project, --plan, or --action) must be provided"` **Code Location:** `src/cleveragents/cli/commands/invariant.py`, `_resolve_scope()` function (lines 70–97). When `flags_set == 0`, the function falls through to `return InvariantScope.GLOBAL, "system"` instead of raising `typer.BadParameter`. **Steps to Reproduce:** 1. Run: `agents invariant add "Never delete production data"` (no scope flag) 2. Observe: command succeeds with exit code 0, invariant is silently added as global scope **Spec References:** - `docs/specification.md` line 17808: "At least one scope flag (`--global`, `--project`, `--plan`, or `--action`) must be provided. `--plan` and `--action` can be repeated to attach the same invariant to multiple plans or actions." - `docs/specification.md` lines 17780–17790: Warning box — "Exactly one scope flag is required for `add` and `list`." ## Subtasks - [ ] In `_resolve_scope()` (lines 70–97 of `src/cleveragents/cli/commands/invariant.py`), replace the silent fallback to `InvariantScope.GLOBAL` with a `typer.BadParameter` raise when `flags_set == 0` - [ ] Ensure the error message matches the spec: `"At least one scope flag (--global, --project, --plan, or --action) must be provided"` - [ ] Verify exit code is non-zero on missing scope flag - [ ] Tests (Behave): Add scenario for `agents invariant add` with no scope flag → expect non-zero exit and correct error message - [ ] Tests (Behave): Confirm existing scenarios with valid scope flags still pass - [ ] Tests (Robot): Add integration test asserting the error path for missing scope flag - [ ] 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 `fix(cli): require at least one scope flag for invariant add command` exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on branch `fix/invariant-add-require-scope-flag` exactly. - 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: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.7.0 milestone 2026-04-03 04:01:58 +00:00
freemo self-assigned this 2026-04-03 16:58:08 +00:00
Author
Owner

MoSCoW classification: Should Have

Rationale: This issue addresses a spec requirement or important quality improvement. It should be included in the milestone if possible.


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

MoSCoW classification: **Should Have** Rationale: This issue addresses a spec requirement or important quality improvement. It should be included in the milestone if possible. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Author
Owner

Closing as duplicate of #3535.

Both issues describe the same bug: agents invariant add silently defaults to --global when no scope flag is provided, but the spec requires at least one scope flag. Issue #3535 is the established tracking issue (v3.3.0 milestone, State/Verified). Please track this work in #3535.


Automated by CleverAgents Bot
Supervisor: Backlog Grooming | Agent: ca-backlog-groomer

Closing as duplicate of #3535. Both issues describe the same bug: `agents invariant add` silently defaults to `--global` when no scope flag is provided, but the spec requires at least one scope flag. Issue #3535 is the established tracking issue (v3.3.0 milestone, `State/Verified`). Please track this work in #3535. --- **Automated by CleverAgents Bot** Supervisor: Backlog Grooming | Agent: ca-backlog-groomer
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#2094
No description provided.