Skip to content

fix(cli): reject unsupported agentmain arguments - #742

Open
imMamdouhaboammar wants to merge 1 commit into
lsdefine:mainfrom
imMamdouhaboammar:fix/agentmain-reject-unknown-cli-upstream
Open

fix(cli): reject unsupported agentmain arguments#742
imMamdouhaboammar wants to merge 1 commit into
lsdefine:mainfrom
imMamdouhaboammar:fix/agentmain-reject-unknown-cli-upstream

Conversation

@imMamdouhaboammar

Copy link
Copy Markdown

Summary

Fixes the fail-silent CLI behavior described in upstream issue #566.

agentmain.py uses parse_known_args() because reflect scripts accept extra --key value pairs. Before this patch, unknown arguments could be converted into reflect arguments even when --reflect was not active, allowing unsupported commands such as --goal to fall through into normal interactive startup instead of failing at the CLI boundary.

Changes

  • Reject unknown arguments when --reflect was not supplied
  • Reject an explicitly empty reflect script path with a clear argparse error
  • Keep valid reflect-specific --key value extras supported
  • Require reflect keys to begin with exactly two leading dashes and contain a name
  • Reject option-shaped values such as --name --other
  • Strip exactly two key dashes with k[2:] instead of normalizing malformed keys via lstrip('-')
  • Leave supported top-level flags and runtime modes unchanged

Regression coverage

  • --goal dummy-goal.json without --reflect exits through argparse with code 2 and an unrecognized arguments diagnostic
  • incomplete --reflect script.py --name is rejected
  • option-shaped missing value --name --other is rejected
  • malformed triple-dash key ---name hive-master is rejected
  • --reflect '' is rejected explicitly as an empty script path
  • valid --reflect script.py --name hive-master remains supported and the reflect script receives name=hive-master

The subprocess harness is isolated from the developer checkout: it runs from a temporary working directory with an empty mykey.py, no-op plugin hooks, PYTHONNOUSERSITE=1, and only the temporary state plus repository on PYTHONPATH.

Verification

  • Initial RED on current main: unsupported --goal entered runtime instead of failing at argparse; incomplete reflect extras were silently accepted
  • GitHub Actions run 31162976599 passed after isolating the subprocess environment
  • Review feedback identified two additional parser edge cases. Regression-only run 31163651223 failed exactly on ---name hive-master and the explicit empty reflect path, while existing valid reflect behavior passed
  • Minimal parser fix passed GitHub Actions run 31163720543: py_compile, all four regression methods and subcases, and git diff --check
  • Final branch is rebuilt directly from current main as one commit changing only agentmain.py and the focused regression test

No dependency or configuration change is added.

The connected GitHub integration can write to this fork but direct creation of the upstream PR returned 403 Resource not accessible by integration, so this fork PR is the clean contribution branch for lsdefine/GenericAgent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant