TDD: shell tool crashes with a raw ValueError instead of a descriptive ExecutionError when the command contains an embedded NUL byte #183

Closed
opened 2026-11-20 09:47:43 +00:00 by CoreRasurae · 0 comments
Member

Metadata

Commit Message: test(agents): capture shell tool raw ValueError crash on NUL-byte command bug (#181)
Branch: tdd/m1-shell-nul-byte-command

Background and context

Companion TDD issue for bug #181 (ToolAgent._execute_shell_command lets a command string containing an embedded NUL byte reach the unguarded asyncio.create_subprocess_shell() call, which raises a raw ValueError instead of the tool's own ExecutionError). Per the project's mandatory Bug Fix TDD Workflow, a failing test proving the bug exists must be written and merged to master BEFORE the fix is implemented. See #181 for the full root-cause analysis and the directly-confirmed reproduction.

Current behavior

No automated test exists that proves ToolAgent._execute_shell_command / _shell_tool lets a command argument containing an embedded NUL byte (\x00) through unrejected, and that it then crashes with a raw ValueError ("embedded null byte") that escapes ToolAgent.invoke(), instead of a clear, early ExecutionError raised before any subprocess is spawned.

Expected behavior

A Behave scenario demonstrates the bug: calling the shell tool (on an agent configured with allow_shell: true) with a command argument containing an embedded NUL byte, via ToolAgent.invoke(), results in an uncaught ValueError propagating out of the call instead of the tool raising a descriptive ExecutionError before asyncio.create_subprocess_shell is reached. The assertion fails while the bug is present, and the scenario is tagged @tdd_expected_fail so it passes CI via inversion until the real fix (#181) lands.

Acceptance criteria

  • A Behave scenario tagged @tdd_issue @tdd_issue_181 @tdd_expected_fail exists in features/ (new or extended step file).
  • The scenario's assertion step uses assert / raise AssertionError only (per project TDD rules) — it must catch whatever ToolAgent.invoke() actually raises for the NUL-byte command argument and assert that it is an ExecutionError (the fixed behavior), not a raw ValueError; while the bug is present, that assertion fails, which @tdd_expected_fail inverts into a CI pass.
  • Running the scenario against the current (unfixed) code fails the underlying assertion (bug reproduced — invoke() raises a bare ValueError, not ExecutionError), which the suite reports as passing only because of the @tdd_expected_fail inversion.
  • nox -s unit_tests is green; coverage unaffected or improved.
  • No mocks/fakes are added outside features/mocks/; the shell call uses a real ToolAgent instance with allow_shell: true — no real network/LLM calls, and no reliance on the NUL byte actually reaching a real shell process (it must never get that far).

Supporting information

  • See bug issue #181 for the full root-cause analysis and the directly-confirmed reproduction (ValueError: embedded null byte).

Subtasks

  • Add a Behave scenario reproducing the shell NUL-byte-command crash, tagged @tdd_issue @tdd_issue_181 @tdd_expected_fail.
  • Implement the step(s) needed to invoke ToolAgent.invoke("shell", {"command": ...}) directly with a command value containing an embedded NUL byte, on an agent with allow_shell: true and safe_mode at its default.
  • Assert that the raised exception is an ExecutionError rather than a ValueError (i.e. that validation — not the OS-level subprocess call — is what rejects the input); this assertion fails on unfixed code because today's exception is a bare ValueError.
  • Verify the scenario fails on unfixed code (bug reproduced) and passes CI only via the @tdd_expected_fail inversion.
  • Run nox -s unit_tests, nox -s lint, and nox -s typecheck on the new files, 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 matches the Commit Message in Metadata exactly.
  • The commit is pushed to the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a PR to master, reviewed, and merged.
  • Bug issue #181 has a Forgejo dependency on this TDD issue (i.e. #181 depends on this issue; this issue blocks #181).
## Metadata Commit Message: `test(agents): capture shell tool raw ValueError crash on NUL-byte command bug (#181)` Branch: tdd/m1-shell-nul-byte-command ## Background and context Companion TDD issue for bug #181 (`ToolAgent._execute_shell_command` lets a `command` string containing an embedded NUL byte reach the unguarded `asyncio.create_subprocess_shell()` call, which raises a raw `ValueError` instead of the tool's own `ExecutionError`). Per the project's mandatory Bug Fix TDD Workflow, a failing test proving the bug exists must be written and merged to master BEFORE the fix is implemented. See #181 for the full root-cause analysis and the directly-confirmed reproduction. ## Current behavior No automated test exists that proves `ToolAgent._execute_shell_command` / `_shell_tool` lets a `command` argument containing an embedded NUL byte (`\x00`) through unrejected, and that it then crashes with a raw `ValueError` ("embedded null byte") that escapes `ToolAgent.invoke()`, instead of a clear, early `ExecutionError` raised before any subprocess is spawned. ## Expected behavior A Behave scenario demonstrates the bug: calling the `shell` tool (on an agent configured with `allow_shell: true`) with a `command` argument containing an embedded NUL byte, via `ToolAgent.invoke()`, results in an uncaught `ValueError` propagating out of the call instead of the tool raising a descriptive `ExecutionError` before `asyncio.create_subprocess_shell` is reached. The assertion fails while the bug is present, and the scenario is tagged `@tdd_expected_fail` so it passes CI via inversion until the real fix (#181) lands. ## Acceptance criteria - A Behave scenario tagged `@tdd_issue @tdd_issue_181 @tdd_expected_fail` exists in `features/` (new or extended step file). - The scenario's assertion step uses `assert` / `raise AssertionError` only (per project TDD rules) — it must catch whatever `ToolAgent.invoke()` actually raises for the NUL-byte `command` argument and assert that it is an `ExecutionError` (the fixed behavior), not a raw `ValueError`; while the bug is present, that assertion fails, which `@tdd_expected_fail` inverts into a CI pass. - Running the scenario against the current (unfixed) code fails the underlying assertion (bug reproduced — `invoke()` raises a bare `ValueError`, not `ExecutionError`), which the suite reports as passing only because of the `@tdd_expected_fail` inversion. - `nox -s unit_tests` is green; coverage unaffected or improved. - No mocks/fakes are added outside `features/mocks/`; the `shell` call uses a real `ToolAgent` instance with `allow_shell: true` — no real network/LLM calls, and no reliance on the NUL byte actually reaching a real shell process (it must never get that far). ## Supporting information - See bug issue #181 for the full root-cause analysis and the directly-confirmed reproduction (`ValueError: embedded null byte`). ## Subtasks - [ ] Add a Behave scenario reproducing the shell NUL-byte-command crash, tagged `@tdd_issue @tdd_issue_181 @tdd_expected_fail`. - [ ] Implement the step(s) needed to invoke `ToolAgent.invoke("shell", {"command": ...})` directly with a `command` value containing an embedded NUL byte, on an agent with `allow_shell: true` and `safe_mode` at its default. - [ ] Assert that the raised exception is an `ExecutionError` rather than a `ValueError` (i.e. that validation — not the OS-level subprocess call — is what rejects the input); this assertion fails on unfixed code because today's exception is a bare `ValueError`. - [ ] Verify the scenario fails on unfixed code (bug reproduced) and passes CI only via the `@tdd_expected_fail` inversion. - [ ] Run `nox -s unit_tests`, `nox -s lint`, and `nox -s typecheck` on the new files, 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 matches the Commit Message in Metadata exactly. - The commit is pushed to the branch matching the Branch in Metadata exactly. - The commit is submitted as a PR to master, reviewed, and merged. - Bug issue #181 has a Forgejo dependency on this TDD issue (i.e. #181 depends on this issue; this issue blocks #181).
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/cleveractors-core#183
No description provided.