TDD: file_read tool crashes with a raw ValueError instead of a descriptive ExecutionError when the path contains an embedded NUL byte #182

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

Metadata

Commit Message: test(agents): capture file_read raw ValueError crash on NUL-byte path bug (#180)
Branch: tdd/m1-file-read-nul-byte-path

Background and context

Companion TDD issue for bug #180 (ToolAgent._file_read_tool lets a file argument containing an embedded NUL byte reach the unguarded os.path.realpath() call used by its safe_mode symlink-escape check, 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 #180 for the full root-cause analysis and the directly-confirmed reproduction.

Current behavior

No automated test exists that proves ToolAgent._file_read_tool lets a file argument containing an embedded NUL byte (\x00) through its validation unrejected, and that it then crashes with a raw ValueError ("embedded null character in path") that escapes both ToolAgent.invoke() and (unwrapped in message quality, if not in type) ToolAgent.process_message(), instead of a clear, early ExecutionError.

Expected behavior

A Behave scenario demonstrates the bug: calling the file_read tool with a file 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 any filesystem call occurs. 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 (#180) lands.

Acceptance criteria

  • A Behave scenario tagged @tdd_issue @tdd_issue_180 @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 file 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 file_read call uses a real ToolAgent instance and a real (but isolated, temp-directory-rooted) filesystem — no real network/LLM calls.

Supporting information

  • See bug issue #180 for the full root-cause analysis and the directly-confirmed reproduction (ValueError: lstat: embedded null character in path).

Subtasks

  • Add a Behave scenario reproducing the file_read NUL-byte-path crash, tagged @tdd_issue @tdd_issue_180 @tdd_expected_fail.
  • Implement the step(s) needed to invoke ToolAgent.invoke("file_read", {"file": ...}) directly with a file value containing an embedded NUL byte, in an isolated temp directory so no real production files are touched.
  • Assert that the raised exception is an ExecutionError rather than a ValueError (i.e. that validation — not the raw OS/stdlib 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 #180 has a Forgejo dependency on this TDD issue (i.e. #180 depends on this issue; this issue blocks #180).
## Metadata Commit Message: `test(agents): capture file_read raw ValueError crash on NUL-byte path bug (#180)` Branch: tdd/m1-file-read-nul-byte-path ## Background and context Companion TDD issue for bug #180 (`ToolAgent._file_read_tool` lets a `file` argument containing an embedded NUL byte reach the unguarded `os.path.realpath()` call used by its `safe_mode` symlink-escape check, 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 #180 for the full root-cause analysis and the directly-confirmed reproduction. ## Current behavior No automated test exists that proves `ToolAgent._file_read_tool` lets a `file` argument containing an embedded NUL byte (`\x00`) through its validation unrejected, and that it then crashes with a raw `ValueError` ("embedded null character in path") that escapes both `ToolAgent.invoke()` and (unwrapped in message quality, if not in type) `ToolAgent.process_message()`, instead of a clear, early `ExecutionError`. ## Expected behavior A Behave scenario demonstrates the bug: calling the `file_read` tool with a `file` 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 any filesystem call occurs. 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 (#180) lands. ## Acceptance criteria - A Behave scenario tagged `@tdd_issue @tdd_issue_180 @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 `file` 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 `file_read` call uses a real `ToolAgent` instance and a real (but isolated, temp-directory-rooted) filesystem — no real network/LLM calls. ## Supporting information - See bug issue #180 for the full root-cause analysis and the directly-confirmed reproduction (`ValueError: lstat: embedded null character in path`). ## Subtasks - [ ] Add a Behave scenario reproducing the file_read NUL-byte-path crash, tagged `@tdd_issue @tdd_issue_180 @tdd_expected_fail`. - [ ] Implement the step(s) needed to invoke `ToolAgent.invoke("file_read", {"file": ...})` directly with a `file` value containing an embedded NUL byte, in an isolated temp directory so no real production files are touched. - [ ] Assert that the raised exception is an `ExecutionError` rather than a `ValueError` (i.e. that validation — not the raw OS/stdlib 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 #180 has a Forgejo dependency on this TDD issue (i.e. #180 depends on this issue; this issue blocks #180).
Author
Member

The commit was merged but the commits message got overwritten due to wrong Forgejo merge option click

The commit was merged but the commits message got overwritten due to wrong Forgejo merge option click
Author
Member

It was PR #200

It was PR #200
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#182
No description provided.