UAT: ActionArgument.validate_name rejects hyphenated argument names — spec has no identifier restriction on argument names #4677

Open
opened 2026-04-08 17:59:58 +00:00 by HAL9000 · 0 comments
Owner

Bug Report

Feature Area

ActionArgument domain model — argument name validation

What Was Tested

Code-level analysis of src/cleveragents/domain/models/core/action.py ActionArgument.validate_name.

Expected Behavior (from spec)

The spec (docs/specification.md, Action Configuration Files JSON Schema, $defs/argument) defines argument names as:

"name": {
  "type": "string",
  "description": "Argument name. Used as the key in --arg name=value."
}

No pattern restriction is specified. The spec does not require argument names to be Python identifiers. The spec examples show names like target_coverage_percent, test_framework — but the schema itself imposes no restriction beyond being a non-empty string.

Actual Behavior (from code)

The ActionArgument.validate_name validator uses Python's .isidentifier() which:

  1. Rejects hyphens (e.g., target-coverage would fail)
  2. Rejects names starting with digits (e.g., 2fa-token would fail)
# src/cleveragents/domain/models/core/action.py
@field_validator("name")
@classmethod
def validate_name(cls: type[ActionArgument], v: str) -> str:
    """Validate argument name is a valid Python identifier."""
    if not v.isidentifier():
        raise ValueError(
            "Argument name must be a valid Python identifier "
            "(alphanumeric and underscores, not starting with a digit)"
        )
    return v

However, ActionConfigSchema.ActionArgumentSchema.validate_name uses a different (more permissive) check:

# src/cleveragents/action/schema.py
@field_validator("name")
@classmethod
def validate_name(cls, v: str) -> str:
    """Ensure argument name is a valid identifier."""
    if not v.replace("-", "_").isidentifier():
        raise ValueError(...)
    return v

The schema layer allows hyphens (by replacing them with underscores before checking), but the domain model layer rejects them. This creates an inconsistency: a YAML file with name: target-coverage would pass ActionConfigSchema validation but fail when the ActionArgument domain model is constructed.

Steps to Reproduce

from cleveragents.domain.models.core.action import ActionArgument

# This should be valid per spec but raises ValueError:
arg = ActionArgument(
    name="target-coverage",  # hyphen in name
    arg_type="integer",
    requirement="required",
)
# Raises: ValueError: Argument name must be a valid Python identifier

Code Location

src/cleveragents/domain/models/core/action.py:

  • ActionArgument.validate_name (line ~150)

src/cleveragents/action/schema.py:

  • ActionArgumentSchema.validate_name (line ~100) — more permissive, allows hyphens

Fix Required

The domain model validator should be consistent with the schema layer and the spec. Since the spec imposes no pattern restriction, the domain model should at minimum allow hyphens:

@field_validator("name")
@classmethod
def validate_name(cls: type[ActionArgument], v: str) -> str:
    """Validate argument name."""
    if not v.replace("-", "_").isidentifier():
        raise ValueError(
            "Argument name must be alphanumeric with hyphens or underscores"
        )
    return v

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

## Bug Report ### Feature Area `ActionArgument` domain model — argument name validation ### What Was Tested Code-level analysis of `src/cleveragents/domain/models/core/action.py` `ActionArgument.validate_name`. ### Expected Behavior (from spec) The spec (docs/specification.md, Action Configuration Files JSON Schema, `$defs/argument`) defines argument names as: ```json "name": { "type": "string", "description": "Argument name. Used as the key in --arg name=value." } ``` **No pattern restriction is specified.** The spec does not require argument names to be Python identifiers. The spec examples show names like `target_coverage_percent`, `test_framework` — but the schema itself imposes no restriction beyond being a non-empty string. ### Actual Behavior (from code) The `ActionArgument.validate_name` validator uses Python's `.isidentifier()` which: 1. Rejects hyphens (e.g., `target-coverage` would fail) 2. Rejects names starting with digits (e.g., `2fa-token` would fail) ```python # src/cleveragents/domain/models/core/action.py @field_validator("name") @classmethod def validate_name(cls: type[ActionArgument], v: str) -> str: """Validate argument name is a valid Python identifier.""" if not v.isidentifier(): raise ValueError( "Argument name must be a valid Python identifier " "(alphanumeric and underscores, not starting with a digit)" ) return v ``` However, `ActionConfigSchema.ActionArgumentSchema.validate_name` uses a different (more permissive) check: ```python # src/cleveragents/action/schema.py @field_validator("name") @classmethod def validate_name(cls, v: str) -> str: """Ensure argument name is a valid identifier.""" if not v.replace("-", "_").isidentifier(): raise ValueError(...) return v ``` The schema layer allows hyphens (by replacing them with underscores before checking), but the domain model layer rejects them. This creates an inconsistency: a YAML file with `name: target-coverage` would pass `ActionConfigSchema` validation but fail when the `ActionArgument` domain model is constructed. ### Steps to Reproduce ```python from cleveragents.domain.models.core.action import ActionArgument # This should be valid per spec but raises ValueError: arg = ActionArgument( name="target-coverage", # hyphen in name arg_type="integer", requirement="required", ) # Raises: ValueError: Argument name must be a valid Python identifier ``` ### Code Location `src/cleveragents/domain/models/core/action.py`: - `ActionArgument.validate_name` (line ~150) `src/cleveragents/action/schema.py`: - `ActionArgumentSchema.validate_name` (line ~100) — more permissive, allows hyphens ### Fix Required The domain model validator should be consistent with the schema layer and the spec. Since the spec imposes no pattern restriction, the domain model should at minimum allow hyphens: ```python @field_validator("name") @classmethod def validate_name(cls: type[ActionArgument], v: str) -> str: """Validate argument name.""" if not v.replace("-", "_").isidentifier(): raise ValueError( "Argument name must be alphanumeric with hyphens or underscores" ) return v ``` --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: uat-tester
HAL9000 added this to the v3.5.0 milestone 2026-04-08 18:05:39 +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.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#4677
No description provided.