UAT: agents invariant add silently defaults to --global scope when no scope flag is given, but spec requires at least one scope flag #2825

Open
opened 2026-04-04 20:42:16 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/invariant-add-require-explicit-scope-flag
  • Commit Message: fix(invariant): raise error when no scope flag is provided to agents invariant add
  • Milestone: v3.3.0
  • Parent Epic: #394

Bug Report

What Was Tested

Code analysis of src/cleveragents/cli/commands/invariant.py — the _resolve_scope() helper function (lines 95–97).

Expected Behavior (from spec)

Per docs/specification.md line 17808:

"At least one scope flag (--global, --project, --plan, or --action) must be provided."

Running agents invariant add "Some invariant text" with no scope flag should produce an error:

Error: At least one scope flag (--global, --project, --plan, or --action) must be provided.

Actual Behavior

In src/cleveragents/cli/commands/invariant.py lines 95–97, the _resolve_scope() function silently defaults to global scope when no scope flag is provided:

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

The module docstring at line 23 even documents this incorrect behavior:

If no scope flag is given, ``--global`` is assumed.

This means agents invariant add "Some text" silently creates a global invariant, which is unexpected and violates the spec's requirement for explicit scope specification.

Steps to Reproduce

  1. Run agents invariant add "Some invariant text" (no scope flag)
  2. Observe: Invariant is silently created with global scope
  3. Expected: Error message requiring at least one scope flag

Code Location

  • src/cleveragents/cli/commands/invariant.py, _resolve_scope() function, lines 95–97
  • src/cleveragents/cli/commands/invariant.py, module docstring, line 23

Subtasks

  • Write a failing BDD scenario in features/ demonstrating that agents invariant add "text" (no scope flag) raises a BadParameter error with the correct message
  • Write a failing BDD scenario confirming that providing at least one scope flag (e.g. --global) succeeds as before
  • In _resolve_scope(), replace the silent default-to-global fallback with raise typer.BadParameter("At least one scope flag (--global, --project, --plan, or --action) must be provided.")
  • Update the module docstring at line 23 to remove the incorrect "If no scope flag is given, --global is assumed" statement and replace it with the correct spec-aligned description
  • Ensure all nox quality gates pass (nox -e lint, nox -e typecheck, nox -e unit_tests, nox -e coverage_report)
  • Open a PR, obtain two approving reviews, and merge

Definition of Done

  • agents invariant add "text" (no scope flag) exits with a clear error: "At least one scope flag (--global, --project, --plan, or --action) must be provided."
  • agents invariant add --global "text" continues to work correctly
  • agents invariant add --project myproject "text" continues to work correctly
  • BDD scenarios cover the no-scope-flag error case and at least one valid-scope-flag success case
  • Module docstring no longer documents the incorrect silent-default behaviour
  • All type annotations are explicit and pass nox -e typecheck (Pyright) with no suppressions
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-uat-tester

## Metadata - **Branch**: `fix/invariant-add-require-explicit-scope-flag` - **Commit Message**: `fix(invariant): raise error when no scope flag is provided to agents invariant add` - **Milestone**: v3.3.0 - **Parent Epic**: #394 ## Bug Report ### What Was Tested Code analysis of `src/cleveragents/cli/commands/invariant.py` — the `_resolve_scope()` helper function (lines 95–97). ### Expected Behavior (from spec) Per `docs/specification.md` line 17808: > "At least one scope flag (`--global`, `--project`, `--plan`, or `--action`) must be provided." Running `agents invariant add "Some invariant text"` with no scope flag should produce an error: ``` Error: At least one scope flag (--global, --project, --plan, or --action) must be provided. ``` ### Actual Behavior In `src/cleveragents/cli/commands/invariant.py` lines 95–97, the `_resolve_scope()` function silently defaults to global scope when no scope flag is provided: ```python # Default to global return InvariantScope.GLOBAL, "system" ``` The module docstring at line 23 even documents this incorrect behavior: ``` If no scope flag is given, ``--global`` is assumed. ``` This means `agents invariant add "Some text"` silently creates a global invariant, which is unexpected and violates the spec's requirement for explicit scope specification. ### Steps to Reproduce 1. Run `agents invariant add "Some invariant text"` (no scope flag) 2. Observe: Invariant is silently created with global scope 3. Expected: Error message requiring at least one scope flag ### Code Location - `src/cleveragents/cli/commands/invariant.py`, `_resolve_scope()` function, lines 95–97 - `src/cleveragents/cli/commands/invariant.py`, module docstring, line 23 ## Subtasks - [ ] Write a failing BDD scenario in `features/` demonstrating that `agents invariant add "text"` (no scope flag) raises a `BadParameter` error with the correct message - [ ] Write a failing BDD scenario confirming that providing at least one scope flag (e.g. `--global`) succeeds as before - [ ] In `_resolve_scope()`, replace the silent default-to-global fallback with `raise typer.BadParameter("At least one scope flag (--global, --project, --plan, or --action) must be provided.")` - [ ] Update the module docstring at line 23 to remove the incorrect "If no scope flag is given, `--global` is assumed" statement and replace it with the correct spec-aligned description - [ ] Ensure all nox quality gates pass (`nox -e lint`, `nox -e typecheck`, `nox -e unit_tests`, `nox -e coverage_report`) - [ ] Open a PR, obtain two approving reviews, and merge ## Definition of Done - [ ] `agents invariant add "text"` (no scope flag) exits with a clear error: `"At least one scope flag (--global, --project, --plan, or --action) must be provided."` - [ ] `agents invariant add --global "text"` continues to work correctly - [ ] `agents invariant add --project myproject "text"` continues to work correctly - [ ] BDD scenarios cover the no-scope-flag error case and at least one valid-scope-flag success case - [ ] Module docstring no longer documents the incorrect silent-default behaviour - [ ] All type annotations are explicit and pass `nox -e typecheck` (Pyright) with no suppressions - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-uat-tester
freemo added this to the v3.3.0 milestone 2026-04-04 20:42:22 +00:00
freemo removed this from the v3.3.0 milestone 2026-04-06 20:53:05 +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.

Blocks
#394 Epic: Decision Framework
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#2825
No description provided.