test(agents): capture file_read raw ValueError crash on NUL-byte path bug (#180) #200

Merged
CoreRasurae merged 1 commit from tdd/m1-file-read-nul-byte-path into develop 2026-12-02 12:22:32 +00:00
Member

Summary

Was meant to add the mandatory TDD issue-capture test for #180 ("file_read tool crashes with a raw ValueError instead of a descriptive ExecutionError when the path contains an embedded NUL byte"), per the companion TDD ticket #182.

Investigation found this bug does not reproduce against current code. Commit fe9ce14 (the fix for sibling issue #175, file_write's path validation) already added a shared _validate_path_characters() helper and explicitly applied it to _file_read_tool too, ahead of every branch that can reach the filesystem (src/cleveractors/agents/tool.py:1016). Its _ILLEGAL_PATH_CHARS set includes every ASCII control character 0x00-0x1F, so a NUL byte is already rejected with a descriptive ExecutionError before os.path.realpath() — the crash site #180 names — is ever reached. Confirmed directly against current code:

await tool_agent.invoke("file_read", {"file": "abc\x00def.txt"})
# raises: ExecutionError: File path contains disallowed characters: '\x00'. ...

Issues #175 and #180 were filed as distinct tickets (per the project's one-concern-per-issue rule) before #175's fix landed with broader scope than its own ticket described — #180 and this PR just weren't cross-referenced against it.

Because there's no live bug to invert, this PR adds a plain regression-guard scenario to features/tool_agent.feature / features/steps/tool_agent_steps.py (extending the existing pair, per the project's step-file rules) tagged only @tdd_issue @tdd_issue_180 — no @tdd_expected_fail, since the assertion already passes outright and the project's TddExpectedFailPolicy fails any @tdd_expected_fail scenario whose assertion is never inverted (a "stale tag" signal). The scenario calls ToolAgent.invoke("file_read", {"file": ...}) directly with a relative NUL-byte path (so it exercises the exact safe_mode/os.path.realpath() branch #180 named, rather than the unrelated absolute-path guard) and asserts an ExecutionError naming "disallowed characters" is raised.

Validity of the test was verified: the _validate_path_characters() call was temporarily removed from _file_read_tool (simulating the pre-fe9ce14 state) and the scenario re-run in isolation — it then fails with Expected ExecutionError, but got <class 'ValueError'>, reproducing issue #180's exact signature. The guard was restored immediately after; src/cleveractors/agents/tool.py carries no diff in this PR.

This PR does not close #180 or #182 — maintainer triage should confirm and close both, referencing fe9ce14, since no separate bugfix PR is needed for #180.

Note: per existing project practice (see PR !192), this repository's PRs target develop, not master as issue #182's Definition of Done states.

Refs #180, Refs #182

Test plan

  • nox -s lint — green
  • nox -s format -- --check — green
  • nox -s typecheck — green (0 errors)
  • nox -s security_scan — green (bandit + semgrep, 0 findings)
  • nox -s dead_code — green (vulture, 0 findings)
  • nox -s unit_tests — green
  • nox -s coverage_report — green (>= 96.5% threshold)
  • Confirmed the scenario's assertion fails (Expected ExecutionError, but got ValueError) when _validate_path_characters() is temporarily removed from _file_read_tool, proving the regression test actually guards the fix

🤖 Generated with Claude Code

## Summary Was meant to add the mandatory TDD issue-capture test for #180 ("`file_read` tool crashes with a raw `ValueError` instead of a descriptive `ExecutionError` when the path contains an embedded NUL byte"), per the companion TDD ticket #182. **Investigation found this bug does not reproduce against current code.** Commit `fe9ce14` (the fix for sibling issue #175, `file_write`'s path validation) already added a shared `_validate_path_characters()` helper and explicitly applied it to `_file_read_tool` too, ahead of every branch that can reach the filesystem (`src/cleveractors/agents/tool.py:1016`). Its `_ILLEGAL_PATH_CHARS` set includes every ASCII control character `0x00`-`0x1F`, so a NUL byte is already rejected with a descriptive `ExecutionError` before `os.path.realpath()` — the crash site #180 names — is ever reached. Confirmed directly against current code: ```python await tool_agent.invoke("file_read", {"file": "abc\x00def.txt"}) # raises: ExecutionError: File path contains disallowed characters: '\x00'. ... ``` Issues #175 and #180 were filed as distinct tickets (per the project's one-concern-per-issue rule) before #175's fix landed with broader scope than its own ticket described — #180 and this PR just weren't cross-referenced against it. Because there's no live bug to invert, this PR adds a **plain regression-guard scenario** to `features/tool_agent.feature` / `features/steps/tool_agent_steps.py` (extending the existing pair, per the project's step-file rules) tagged only `@tdd_issue @tdd_issue_180` — no `@tdd_expected_fail`, since the assertion already passes outright and the project's `TddExpectedFailPolicy` fails any `@tdd_expected_fail` scenario whose assertion is never inverted (a "stale tag" signal). The scenario calls `ToolAgent.invoke("file_read", {"file": ...})` directly with a *relative* NUL-byte path (so it exercises the exact `safe_mode`/`os.path.realpath()` branch #180 named, rather than the unrelated absolute-path guard) and asserts an `ExecutionError` naming "disallowed characters" is raised. **Validity of the test was verified**: the `_validate_path_characters()` call was temporarily removed from `_file_read_tool` (simulating the pre-`fe9ce14` state) and the scenario re-run in isolation — it then fails with `Expected ExecutionError, but got <class 'ValueError'>`, reproducing issue #180's exact signature. The guard was restored immediately after; `src/cleveractors/agents/tool.py` carries no diff in this PR. **This PR does not close #180 or #182** — maintainer triage should confirm and close both, referencing `fe9ce14`, since no separate bugfix PR is needed for #180. **Note:** per existing project practice (see PR !192), this repository's PRs target `develop`, not `master` as issue #182's Definition of Done states. Refs #180, Refs #182 ## Test plan - [x] `nox -s lint` — green - [x] `nox -s format -- --check` — green - [x] `nox -s typecheck` — green (0 errors) - [x] `nox -s security_scan` — green (bandit + semgrep, 0 findings) - [x] `nox -s dead_code` — green (vulture, 0 findings) - [x] `nox -s unit_tests` — green - [x] `nox -s coverage_report` — green (>= 96.5% threshold) - [x] Confirmed the scenario's assertion fails (`Expected ExecutionError, but got ValueError`) when `_validate_path_characters()` is temporarily removed from `_file_read_tool`, proving the regression test actually guards the fix 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test(agents): capture file_read raw ValueError crash on NUL-byte path bug (#180)
Some checks failed
CI / lint (pull_request) Successful in 1m5s
CI / typecheck (pull_request) Successful in 2m7s
CI / quality (pull_request) Successful in 1m58s
CI / build (pull_request) Successful in 1m59s
CI / security (pull_request) Successful in 2m22s
CI / integration_tests (pull_request) Successful in 5m20s
CI / unit_tests (pull_request) Successful in 6m28s
CI / coverage (pull_request) Failing after 13m53s
CI / benchmark (pull_request) Failing after 20m15s
CI / status-check (pull_request) Has been cancelled
96ddb46e03
Adds the regression test for issue #180: ToolAgent._file_read_tool was
reported to let a `file` argument containing an embedded NUL byte
reach the unguarded `os.path.realpath()` call used by its `safe_mode`
symlink-escape check (ADR-2035 D-4), raising a raw ValueError instead
of the tool's own ExecutionError.

Investigation found the bug does not reproduce against current code:
commit fe9ce14 (issue #175's fix for file_write's path validation)
already added a shared `_validate_path_characters()` helper and
explicitly applied it to `_file_read_tool` too, ahead of every branch
that can reach the filesystem. Its `_ILLEGAL_PATH_CHARS` set includes
every ASCII control character 0x00-0x1F, so a NUL byte is rejected
with a descriptive ExecutionError before `os.path.realpath()` is ever
reached -- confirmed directly: `ToolAgent.invoke("file_read", {"file":
"abc\x00def.txt"})` raises `ExecutionError: File path contains
disallowed characters: '\x00'. ...`, not a ValueError. #175 and #180
were filed as distinct issues (per the project's one-concern-per-issue
rule) before #175's fix landed with broader scope than its own ticket
described.

Because there is no live bug to invert, this commit adds a plain
regression-guard scenario to features/tool_agent.feature /
features/steps/tool_agent_steps.py (extending the existing pair, per
the project's step-file rules) tagged only `@tdd_issue` and
`@tdd_issue_180` -- no `@tdd_expected_fail`, since the assertion
already passes outright and TddExpectedFailPolicy fails any
@tdd_expected_fail scenario whose assertion isn't ever inverted (a
"stale tag" signal). The scenario calls `ToolAgent.invoke("file_read",
{"file": ...})` directly with a *relative* NUL-byte path (so it
exercises the exact safe_mode/os.path.realpath() branch #180 named,
rather than the unrelated absolute-path guard) and asserts an
ExecutionError naming "disallowed characters" is raised.

Validity of the test was verified by temporarily removing the
_validate_path_characters() call from _file_read_tool (simulating the
pre-fe9ce14 state) and re-running the scenario in isolation: it then
fails with "Expected ExecutionError, but got <class 'ValueError'>",
reproducing issue #180's exact signature. The guard was restored
immediately after (src/cleveractors/agents/tool.py carries no diff in
this commit); nox -s unit_tests was re-run clean afterward to confirm.

With the regression scenario in place: nox -s lint, nox -s format --
check, nox -s typecheck, nox -s security_scan, nox -s dead_code, nox -s
unit_tests (160 features, 3375 scenarios, 15543 steps), and nox -s
coverage_report (97.3%, >= 96.5% threshold) are all green. No src/,
robot/, or benchmarks/ files changed in this commit, so the
previously-verified nox -s integration_tests (382 Robot tests) and
nox -s benchmark_regression -- --quick (no significant change) results
from the prior commit on this branch remain valid and were not re-run.

No CHANGELOG.md entry: this is a test-only commit with no behavior
change, consistent with project precedent for TDD/regression-only
commits.

This finding (bug #180 already fixed, no separate bugfix PR needed) is
left for maintainer triage on issues #180 and #182 rather than closed
here.

Refs: #180, #182
CoreRasurae force-pushed tdd/m1-file-read-nul-byte-path from 96ddb46e03
Some checks failed
CI / lint (pull_request) Successful in 1m5s
CI / typecheck (pull_request) Successful in 2m7s
CI / quality (pull_request) Successful in 1m58s
CI / build (pull_request) Successful in 1m59s
CI / security (pull_request) Successful in 2m22s
CI / integration_tests (pull_request) Successful in 5m20s
CI / unit_tests (pull_request) Successful in 6m28s
CI / coverage (pull_request) Failing after 13m53s
CI / benchmark (pull_request) Failing after 20m15s
CI / status-check (pull_request) Has been cancelled
to abb0ed0888
Some checks failed
CI / security (pull_request) Successful in 1m6s
CI / lint (pull_request) Successful in 2m31s
CI / typecheck (pull_request) Successful in 2m44s
CI / build (pull_request) Successful in 55s
CI / quality (pull_request) Successful in 1m56s
CI / integration_tests (pull_request) Successful in 2m59s
CI / unit_tests (pull_request) Successful in 5m48s
CI / benchmark (pull_request) Failing after 22m8s
CI / coverage (pull_request) Successful in 7m15s
CI / status-check (pull_request) Successful in 2s
2026-12-01 20:53:41 +00:00
Compare
hurui200320 left a comment

PR Review: !200 (Ticket #180, TDD companion #182)

Verdict: Approve

Test-only PR (+56/-0 across the existing features/tool_agent.feature / features/steps/tool_agent_steps.py pair) adding a regression-guard scenario for the file_read NUL-byte-path bug. The central claim — that the bug no longer reproduces because fe9ce14 (_validate_path_characters, from #175's fix) already guards _file_read_tool — was independently verified against the current code, and the new scenario was mutation-verified to actually guard the fix. All local quality gates that can be affected by this change are green. The one deviation from issue #182's letter (no @tdd_expected_fail tag) is necessary, correct, and well documented: TddExpectedFailPolicy.on_scenario (features/tdd_expected_fail.py:105-117) fails any @tdd_expected_fail scenario whose assertion passes without inversion, so tagging this already-passing scenario would break CI.

Critical Issues

None.

Major Issues

None.

Minor Issues

None.

Nits

  1. features/steps/tool_agent_steps.py, lines 277–289 (step docstring) — The docstring states the scenario "exercises the exact branch issue #180 names as the crash site (os.path.realpath() inside the safe_mode symlink-escape check)" and then, one sentence later, correctly says _validate_path_characters "rejects the NUL byte before any of _file_read_tool's branches touch the filesystem." Strictly speaking, the scenario exercises the validation guard that protects the crash site — the realpath branch itself is unreachable for NUL-byte input (that is the whole point of the guard). The same mild overstatement appears in the scenario's feature-file comment block. Recommendation: reword to "exercises the same entry path that would reach the os.path.realpath() crash site if the validation guard were absent." Non-blocking; behavior and tags are correct.

  2. features/steps/tool_agent_steps.py, line 296 vs line 317 — The two adjacent sibling NUL-byte steps use different (and inert) broad-except disable comments: the new step uses # pylint: disable=broad-except while the #181 sibling uses # pylint: disable=broad-exception-caught. Neither is enforced (the project lints with ruff E/F/W/B/I, which does not flag this), so this is purely cosmetic consistency between the paired steps. Consider aligning the wording in a future touch-up.

Summary

Verification performed (local, authoritative):

  • Read the PR head commit (abb0ed0, based squarely on develop @ 84c7f89, single commit, mergeable) and the full changed codebase context: src/cleveractors/agents/tool.py (_validate_path_characters, _ILLEGAL_PATH_CHARS, _file_read_tool, invoke/_execute_tool error contract), the sibling #181 scenario/steps, features/tdd_expected_fail.py, and the tool docs.
  • Behavior confirmed: with the PR's exact configuration (default safe_mode=true, no _unsafe_mode, relative path), ToolAgent.invoke("file_read", {"file": "abc\x00def.txt"}) raises ExecutionError: File path contains disallowed characters: '\x00'... — matching the scenario's tool execution should fail with message containing "disallowed characters" assertion, which also type-checks the error as ExecutionError (i.e., the required "ExecutionError, not a raw ValueError" assertion from #182's acceptance criteria is satisfied via the shared Then step).
  • Mutation check (guard validity): bypassing _validate_path_characters (simulating the pre-fe9ce14 state) with the same arguments reproduces issue #180's exact signature — ValueError: lstat: embedded null character in path escaping invoke() uncaught. The scenario would therefore catch a regression of the original bug. The PR author's identical verification claim is accurate.
  • nox -s lint ✅, nox -s format -- --check ✅, nox -s typecheck ✅ (0 errors), behave features/tool_agent.feature ✅ (63/63 scenarios, incl. the new one, run in isolation via tag filter as well). Coverage is over src only and no src files changed, so the threshold is unaffected; commit message reports 97.3% vs the 96.5% threshold.
  • Commit quality: first line matches issue #182's Metadata Commit Message exactly; the body is detailed and every factual claim in it checked out (fe9ce14 exists with the quoted message; the _ILLEGAL_PATH_CHARS 0x00–0x1F claim is accurate; the single-commit, no-fix-commit-per-branch rule is honored).

Per reviewer instructions, the following author-decided / red-tape items are excluded from this review (the author explicitly decided or deferred them in the PR description and on #180): not closing #180/#182 from this PR (deferred to maintainer triage), targeting develop instead of the DoD's master (established practice per PR !192), the missing ISSUES CLOSED footer, and label/CHANGELOG housekeeping.

Informational, non-gating: CI run 598 on the PR head shows CI / benchmark failing with the other 9 jobs green. Per review policy CI is not relied on here; noting only that this feature-only change cannot affect ASV benchmark workloads (which exercise src//benchmarks/), so the failure appears unrelated to this diff.

Note: GISM0 unavailable in this session — reviewed without the ticket memory journal, continuing from Gitea sources only.

Nice, disciplined piece of TDD-triage work: the investigation is correct, the guard is real, and the documentation of the deviation is exemplary. Approved — maintainer triage can now close #180/#182 referencing fe9ce14.

## PR Review: !200 (Ticket #180, TDD companion #182) ### Verdict: Approve Test-only PR (+56/-0 across the existing `features/tool_agent.feature` / `features/steps/tool_agent_steps.py` pair) adding a regression-guard scenario for the `file_read` NUL-byte-path bug. The central claim — that the bug no longer reproduces because `fe9ce14` (`_validate_path_characters`, from #175's fix) already guards `_file_read_tool` — was independently verified against the current code, and the new scenario was mutation-verified to actually guard the fix. All local quality gates that can be affected by this change are green. The one deviation from issue #182's letter (no `@tdd_expected_fail` tag) is necessary, correct, and well documented: `TddExpectedFailPolicy.on_scenario` (`features/tdd_expected_fail.py:105-117`) fails any `@tdd_expected_fail` scenario whose assertion passes without inversion, so tagging this already-passing scenario would break CI. ### Critical Issues None. ### Major Issues None. ### Minor Issues None. ### Nits 1. **`features/steps/tool_agent_steps.py`, lines 277–289 (step docstring)** — The docstring states the scenario "exercises the exact branch issue #180 names as the crash site (`os.path.realpath()` inside the `safe_mode` symlink-escape check)" and then, one sentence later, correctly says `_validate_path_characters` "rejects the NUL byte before any of `_file_read_tool`'s branches touch the filesystem." Strictly speaking, the scenario exercises the validation guard that protects the crash site — the `realpath` branch itself is unreachable for NUL-byte input (that is the whole point of the guard). The same mild overstatement appears in the scenario's feature-file comment block. Recommendation: reword to "exercises the same entry path that would reach the `os.path.realpath()` crash site if the validation guard were absent." Non-blocking; behavior and tags are correct. 2. **`features/steps/tool_agent_steps.py`, line 296 vs line 317** — The two adjacent sibling NUL-byte steps use different (and inert) broad-except disable comments: the new step uses `# pylint: disable=broad-except` while the #181 sibling uses `# pylint: disable=broad-exception-caught`. Neither is enforced (the project lints with ruff E/F/W/B/I, which does not flag this), so this is purely cosmetic consistency between the paired steps. Consider aligning the wording in a future touch-up. ### Summary **Verification performed (local, authoritative):** - Read the PR head commit (`abb0ed0`, based squarely on `develop` @ `84c7f89`, single commit, mergeable) and the full changed codebase context: `src/cleveractors/agents/tool.py` (`_validate_path_characters`, `_ILLEGAL_PATH_CHARS`, `_file_read_tool`, `invoke`/`_execute_tool` error contract), the sibling #181 scenario/steps, `features/tdd_expected_fail.py`, and the tool docs. - **Behavior confirmed:** with the PR's exact configuration (default `safe_mode=true`, no `_unsafe_mode`, relative path), `ToolAgent.invoke("file_read", {"file": "abc\x00def.txt"})` raises `ExecutionError: File path contains disallowed characters: '\x00'...` — matching the scenario's `tool execution should fail with message containing "disallowed characters"` assertion, which also type-checks the error as `ExecutionError` (i.e., the required "ExecutionError, not a raw ValueError" assertion from #182's acceptance criteria is satisfied via the shared Then step). - **Mutation check (guard validity):** bypassing `_validate_path_characters` (simulating the pre-`fe9ce14` state) with the same arguments reproduces issue #180's exact signature — `ValueError: lstat: embedded null character in path` escaping `invoke()` uncaught. The scenario would therefore catch a regression of the original bug. The PR author's identical verification claim is accurate. - `nox -s lint` ✅, `nox -s format -- --check` ✅, `nox -s typecheck` ✅ (0 errors), `behave features/tool_agent.feature` ✅ (63/63 scenarios, incl. the new one, run in isolation via tag filter as well). Coverage is over `src` only and no `src` files changed, so the threshold is unaffected; commit message reports 97.3% vs the 96.5% threshold. - Commit quality: first line matches issue #182's Metadata Commit Message exactly; the body is detailed and every factual claim in it checked out (`fe9ce14` exists with the quoted message; the `_ILLEGAL_PATH_CHARS` 0x00–0x1F claim is accurate; the single-commit, no-fix-commit-per-branch rule is honored). **Per reviewer instructions, the following author-decided / red-tape items are excluded from this review** (the author explicitly decided or deferred them in the PR description and on #180): not closing #180/#182 from this PR (deferred to maintainer triage), targeting `develop` instead of the DoD's `master` (established practice per PR !192), the missing `ISSUES CLOSED` footer, and label/CHANGELOG housekeeping. **Informational, non-gating:** CI run 598 on the PR head shows `CI / benchmark` failing with the other 9 jobs green. Per review policy CI is not relied on here; noting only that this feature-only change cannot affect ASV benchmark workloads (which exercise `src/`/`benchmarks/`), so the failure appears unrelated to this diff. **Note:** GISM0 unavailable in this session — reviewed without the ticket memory journal, continuing from Gitea sources only. Nice, disciplined piece of TDD-triage work: the investigation is correct, the guard is real, and the documentation of the deviation is exemplary. Approved — maintainer triage can now close #180/#182 referencing `fe9ce14`.
CoreRasurae force-pushed tdd/m1-file-read-nul-byte-path from abb0ed0888
Some checks failed
CI / security (pull_request) Successful in 1m6s
CI / lint (pull_request) Successful in 2m31s
CI / typecheck (pull_request) Successful in 2m44s
CI / build (pull_request) Successful in 55s
CI / quality (pull_request) Successful in 1m56s
CI / integration_tests (pull_request) Successful in 2m59s
CI / unit_tests (pull_request) Successful in 5m48s
CI / benchmark (pull_request) Failing after 22m8s
CI / coverage (pull_request) Successful in 7m15s
CI / status-check (pull_request) Successful in 2s
to 5e9ca51530
Some checks failed
CI / lint (pull_request) Successful in 1m18s
CI / typecheck (pull_request) Successful in 1m43s
CI / security (pull_request) Successful in 1m4s
CI / quality (pull_request) Successful in 1m43s
CI / build (pull_request) Successful in 1m44s
CI / integration_tests (pull_request) Successful in 3m52s
CI / benchmark (pull_request) Has been cancelled
CI / unit_tests (pull_request) Successful in 6m56s
CI / coverage (pull_request) Successful in 6m39s
CI / status-check (pull_request) Successful in 2s
2026-12-02 11:33:52 +00:00
Compare
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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/cleveractors-core!200
No description provided.