UAT: agents invariant add silently defaults to global scope when no scope flag is given — spec requires exactly one scope flag #6331

Open
opened 2026-04-09 20:11:03 +00:00 by HAL9000 · 0 comments
Owner

Summary

agents invariant add silently defaults to GLOBAL scope when the user provides no scope flag. The specification explicitly requires exactly one scope flag (--global, --project, --plan, or --action) and must error if none is given.

Spec Reference

  • docs/specification.md line 17873: "Exactly ==one scope flag== is required for add and list."
  • docs/specification.md line 17900: "At least one scope flag (--global, --project, --plan, or --action) must be provided."

Code Location

File: src/cleveragents/cli/commands/invariant.py

_resolve_scope() function (lines 70–97):

def _resolve_scope(
    is_global: bool,
    project: str | None,
    plan: str | None,
    action: str | None,
) -> tuple[InvariantScope, str]:
    flags_set = sum(
        [is_global, project is not None, plan is not None, action is not None]
    )
    if flags_set > 1:
        raise typer.BadParameter(...)

    if project is not None:
        return InvariantScope.PROJECT, project
    if plan is not None:
        return InvariantScope.PLAN, plan
    if action is not None:
        return InvariantScope.ACTION, action

    # Default to global   <-- BUG: should raise error when flags_set == 0
    return InvariantScope.GLOBAL, "system"

The function checks for flags_set > 1 (conflict) but silently falls through to a global default when flags_set == 0. This violates the spec contract.

Steps to Reproduce

agents invariant add "Never delete production data"
# No error; invariant is silently created at GLOBAL scope with source_name "system"

Expected Behavior (per spec)

Error: At least one scope flag is required.
Usage: agents invariant add [--global] [--project PROJECT] [--plan PLAN_ID] [--action ACTION] <TEXT>

Actual Behavior

The invariant is silently created at GLOBAL scope with source_name="system", no error or warning is emitted.

Impact

  • Users unintentionally create global invariants when they meant to scope to a project or plan.
  • Automated tooling relying on the spec contract will not get the expected error response when no scope flag is given.
  • Breaks the invariant CLI contract documented in the specification.

Fix

In _resolve_scope(), add a check when flags_set == 0:

if flags_set == 0:
    raise typer.BadParameter(
        "Exactly one scope flag is required: --global, --project, --plan, or --action"
    )

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

## Summary `agents invariant add` silently defaults to `GLOBAL` scope when the user provides no scope flag. The specification explicitly requires exactly one scope flag (`--global`, `--project`, `--plan`, or `--action`) and must error if none is given. ## Spec Reference - `docs/specification.md` line 17873: "Exactly ==one scope flag== is required for `add` and `list`." - `docs/specification.md` line 17900: "At least one scope flag (`--global`, `--project`, `--plan`, or `--action`) must be provided." ## Code Location **File**: `src/cleveragents/cli/commands/invariant.py` **`_resolve_scope()` function (lines 70–97)**: ```python def _resolve_scope( is_global: bool, project: str | None, plan: str | None, action: str | None, ) -> tuple[InvariantScope, str]: flags_set = sum( [is_global, project is not None, plan is not None, action is not None] ) if flags_set > 1: raise typer.BadParameter(...) if project is not None: return InvariantScope.PROJECT, project if plan is not None: return InvariantScope.PLAN, plan if action is not None: return InvariantScope.ACTION, action # Default to global <-- BUG: should raise error when flags_set == 0 return InvariantScope.GLOBAL, "system" ``` The function checks for `flags_set > 1` (conflict) but silently falls through to a global default when `flags_set == 0`. This violates the spec contract. ## Steps to Reproduce ```bash agents invariant add "Never delete production data" # No error; invariant is silently created at GLOBAL scope with source_name "system" ``` ## Expected Behavior (per spec) ``` Error: At least one scope flag is required. Usage: agents invariant add [--global] [--project PROJECT] [--plan PLAN_ID] [--action ACTION] <TEXT> ``` ## Actual Behavior The invariant is silently created at `GLOBAL` scope with `source_name="system"`, no error or warning is emitted. ## Impact - Users unintentionally create global invariants when they meant to scope to a project or plan. - Automated tooling relying on the spec contract will not get the expected error response when no scope flag is given. - Breaks the invariant CLI contract documented in the specification. ## Fix In `_resolve_scope()`, add a check when `flags_set == 0`: ```python if flags_set == 0: raise typer.BadParameter( "Exactly one scope flag is required: --global, --project, --plan, or --action" ) ``` --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.2.0 milestone 2026-04-16 22:15:54 +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.

Depends on
Reference
cleveragents/cleveragents-core#6331
No description provided.