TDD: file_write tool accepts a path containing embedded markup/control characters and fails late with a raw OS error instead of rejecting it up front #176

Closed
opened 2026-11-19 16:17:22 +00:00 by CoreRasurae · 0 comments
Member

Metadata

Commit Message: test(agents): capture file_write accepting a malformed path bug (#175)
Branch: tdd/m1-file-write-path-validation

Background and context

Companion TDD issue for bug #175 (_file_write_tool/_validate_file_path_safety accepts a file argument containing embedded markup/control characters and only fails late, with a raw OS error, inside FileAccessCore.write()). 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.

Current behavior

No automated test exists that proves ToolAgent._file_write_tool / _validate_file_path_safety lets a file argument containing illegal/markup characters (e.g. file\" <span class=\"editor-tab\" data-tab=\"file\">some/path.v) through validation unrejected, and that the failure only surfaces later as a raw OSError/[Errno 2] from the underlying filesystem call rather than a clear, early ExecutionError. See #175 for full root-cause analysis and captured evidence.

Expected behavior

A Behave scenario demonstrates the bug: calling the file_write tool (in unsafe mode, so validation reaches the path-safety check rather than stopping earlier) with a file argument containing an embedded markup fragment results in the call proceeding to the underlying OS write attempt and failing with a raw OSError-derived message, instead of being rejected up front by _validate_file_path_safety with a descriptive ExecutionError. Do not restrict yourself to embedded markup, also consider other invalid formatted paths, i.e. paths that cannot be handled in any meaningful way based on current code logic. 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 (#175) lands.

Acceptance criteria

  • A Behave scenario tagged @tdd_issue @tdd_issue_175 @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) and asserts that _file_write_tool rejects the malformed path with a descriptive ExecutionError before any filesystem call occurs (i.e. no attempt is made to open/write the real OS path).
  • Running the scenario against the current (unfixed) code fails the underlying assertion (bug reproduced -- the call proceeds to the OS and fails late), 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/; no real network/LLM calls -- the tool call args are constructed directly in the test.

Supporting information

  • See bug issue #175 for the full root-cause analysis and the captured log evidence.

Subtasks

  • Add a Behave scenario reproducing the malformed-path-accepted behavior, tagged @tdd_issue @tdd_issue_175 @tdd_expected_fail.
  • Implement the step(s) needed to invoke _file_write_tool/_validate_file_path_safety directly (or via the ToolAgent tool-dispatch surface) with a path containing embedded markup, in an isolated temp directory so no real production files are touched. Do not restrict yourself to embedded markup, also consider other invalid formatted paths, i.e. paths that cannot be handled in any meaningful way based on current code logic.
  • Assert no filesystem write/open is attempted for the malformed path (e.g. by pointing file at a path whose parent directory does not exist, so an unvalidated attempt would raise [Errno 2], and asserting the raised error is the validation error rather than the raw OSError). Do not restrict yourself to embedded markup, also consider other invalid formatted paths, i.e. paths that cannot be handled in any meaningful way based on current code logic. You should validate that the path is sound with respect to the code logic accepted formats.
  • 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 #175 has a Forgejo dependency on this TDD issue (i.e. #175 depends on this issue; this issue blocks #175).
## Metadata Commit Message: `test(agents): capture file_write accepting a malformed path bug (#175)` Branch: tdd/m1-file-write-path-validation ## Background and context Companion TDD issue for bug #175 (`_file_write_tool`/`_validate_file_path_safety` accepts a `file` argument containing embedded markup/control characters and only fails late, with a raw OS error, inside `FileAccessCore.write()`). 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. ## Current behavior No automated test exists that proves `ToolAgent._file_write_tool` / `_validate_file_path_safety` lets a `file` argument containing illegal/markup characters (e.g. `file\" <span class=\"editor-tab\" data-tab=\"file\">some/path.v`) through validation unrejected, and that the failure only surfaces later as a raw `OSError`/`[Errno 2]` from the underlying filesystem call rather than a clear, early `ExecutionError`. See #175 for full root-cause analysis and captured evidence. ## Expected behavior A Behave scenario demonstrates the bug: calling the `file_write` tool (in `unsafe` mode, so validation reaches the path-safety check rather than stopping earlier) with a `file` argument containing an embedded markup fragment results in the call proceeding to the underlying OS write attempt and failing with a raw `OSError`-derived message, instead of being rejected up front by `_validate_file_path_safety` with a descriptive `ExecutionError`. Do not restrict yourself to embedded markup, also consider other invalid formatted paths, i.e. paths that cannot be handled in any meaningful way based on current code logic. 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 (#175) lands. ## Acceptance criteria - A Behave scenario tagged `@tdd_issue @tdd_issue_175 @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) and asserts that `_file_write_tool` rejects the malformed path with a descriptive `ExecutionError` *before* any filesystem call occurs (i.e. no attempt is made to open/write the real OS path). - Running the scenario against the current (unfixed) code fails the underlying assertion (bug reproduced -- the call proceeds to the OS and fails late), 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/`; no real network/LLM calls -- the tool call args are constructed directly in the test. ## Supporting information - See bug issue #175 for the full root-cause analysis and the captured log evidence. ## Subtasks - [ ] Add a Behave scenario reproducing the malformed-path-accepted behavior, tagged `@tdd_issue @tdd_issue_175 @tdd_expected_fail`. - [ ] Implement the step(s) needed to invoke `_file_write_tool`/`_validate_file_path_safety` directly (or via the `ToolAgent` tool-dispatch surface) with a path containing embedded markup, in an isolated temp directory so no real production files are touched. Do not restrict yourself to embedded markup, also consider other invalid formatted paths, i.e. paths that cannot be handled in any meaningful way based on current code logic. - [ ] Assert no filesystem write/open is attempted for the malformed path (e.g. by pointing `file` at a path whose parent directory does not exist, so an unvalidated attempt would raise `[Errno 2]`, and asserting the raised error is the *validation* error rather than the raw `OSError`). Do not restrict yourself to embedded markup, also consider other invalid formatted paths, i.e. paths that cannot be handled in any meaningful way based on current code logic. You should validate that the path is sound with respect to the code logic accepted formats. - [ ] 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 #175 has a Forgejo dependency on this TDD issue (i.e. #175 depends on this issue; this issue blocks #175).
CoreRasurae added this to the v2.1.0 milestone 2026-11-19 21:53:28 +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.

Reference
cleveragents/cleveractors-core#176
No description provided.