zeroclaw/src/tools
Alex Gorevski 45cdd25b3d fix(tests): harden brittle tests for cross-platform stability and refactoring resilience
## Problem

The test suite contained several categories of latent brittleness
identified in docs/testing-brittle-tests.md that would surface during
refactoring or cross-platform (Windows) CI execution:

1. Hardcoded Unix paths: \Path::new("/tmp")\ and \PathBuf::from("/tmp")\
   used as workspace directories in agent tests, which fail on Windows
   where /tmp does not exist.

2. Exact string match assertions: ~20 \ssert_eq!(response, "exact text")\
   assertions in agent unit and e2e tests that break on any mock wording
   change, even when the underlying orchestration behavior is correct.

3. Fragile error message string matching: \.contains("specific message")\
   assertions coupled to internal error wording rather than testing the
   error category or behavioral outcome.

## What Changed

### Hardcoded paths → platform-agnostic temp dirs (4 files, 7 locations)
- \src/agent/tests.rs\: Replaced all 4 instances of \Path::new("/tmp")\
  and \PathBuf::from("/tmp")\ with \std::env::temp_dir()\ in
  \make_memory()\, \uild_agent_with()\, \uild_agent_with_memory()\,
  and \uild_agent_with_config()\ helpers.
- \	ests/agent_e2e.rs\: Replaced all 3 instances in \make_memory()\,
  \uild_agent()\, and \uild_agent_xml()\ helpers.

### Exact string assertions → behavioral checks (2 files, ~20 locations)
- \src/agent/tests.rs\: Converted 10 \ssert_eq!(response, "...")\ to
  \ssert!(!response.is_empty(), "descriptive message")\ across tests for
  text pass-through, tool execution, tool failure recovery, XML dispatch,
  mixed text+tool responses, multi-tool batch, and run_single delegation.
- \	ests/agent_e2e.rs\: Converted 9 exact-match assertions to behavioral
  checks. Multi-turn test now uses \ssert_ne!(r1, r2)\ to verify
  sequential responses are distinct without coupling to exact wording.
- Provider error propagation test simplified to \ssert!(result.is_err())\
  without asserting on the error message string.

### Fragile error message assertions → structural checks (2 files)
- \src/tools/git_operations.rs\: Replaced fragile OR-branch string match
  (\contains("git repository") || contains("Git command failed")\) with
  structural assertions: checks \!result.success\, error is non-empty,
  and error does NOT mention autonomy/read-only (verifying the failure
  is git-related, not permission-related).
- \src/cron/scheduler.rs\: Replaced \contains("agent job failed:")\ with
  \!success\ and \!output.is_empty()\ checks that verify failure behavior
  without coupling to exact log format.

## What Was NOT Changed (and why)
- \src/agent/loop_.rs\ parser tests: Exact string assertions are the
  contract for XML tool call parsing — the exact output IS the spec.
- \src/providers/reliable.rs\: Error message assertions test the error
  format contract (provider/model attribution in failure messages).
- \src/service/mod.rs\: Already platform-gated with \#[cfg]\; XML escape
  test is a formatting contract where exact match is appropriate.
- \src/config/schema.rs\: TOML test strings use /tmp as data values for
  deserialization tests, not filesystem access; HOME tests already use
  \std::env::temp_dir()\.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:17:58 +08:00
..
browser_open.rs refactor: simplify CLI commands and update architecture docs 2026-02-14 05:17:16 -05:00
browser.rs fix(browser): preserve backend-specific unsupported-action errors 2026-02-17 18:12:27 +08:00
composio.rs fix(policy): standardize side-effect tool autonomy gates 2026-02-18 12:42:56 +08:00
cron_add.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
cron_list.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
cron_remove.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
cron_run.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
cron_runs.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
cron_update.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
delegate.rs fix(policy): standardize side-effect tool autonomy gates 2026-02-18 12:42:56 +08:00
file_read.rs fix(security): move record_action before canonicalize in file_read 2026-02-16 17:21:52 +01:00
file_write.rs fix(security): enforce action guards in file_write and scheduler (#269) 2026-02-16 01:57:58 -05:00
git_operations.rs fix(tests): harden brittle tests for cross-platform stability and refactoring resilience 2026-02-18 14:17:58 +08:00
hardware_board_info.rs fix: resolve all clippy warnings, formatting, and Mistral endpoint 2026-02-17 20:00:08 +08:00
hardware_memory_map.rs fix: resolve all clippy warnings, formatting, and Mistral endpoint 2026-02-17 20:00:08 +08:00
hardware_memory_read.rs fix(security): resolve rebase conflicts and provider regressions 2026-02-17 19:19:06 +08:00
http_request.rs fix(security): disable automatic redirects in http_request tool (#624) 2026-02-17 15:15:48 -05:00
image_info.rs fix(memory): prevent autosave key collisions across runtime flows 2026-02-15 22:55:52 -05:00
memory_forget.rs fix(policy): standardize side-effect tool autonomy gates 2026-02-18 12:42:56 +08:00
memory_recall.rs feat(memory): add session_id isolation to Memory trait (#530) 2026-02-17 07:44:05 -05:00
memory_store.rs fix(policy): standardize side-effect tool autonomy gates 2026-02-18 12:42:56 +08:00
mod.rs fix(policy): standardize side-effect tool autonomy gates 2026-02-18 12:42:56 +08:00
pushover.rs fix(tools): harden pushover security and validation 2026-02-17 19:10:09 +08:00
schedule.rs Implement cron job management tools and types 2026-02-17 17:06:28 +08:00
schema.rs fix(build): complete strict lint and test cleanup (replacement for #476) 2026-02-18 00:18:54 +08:00
screenshot.rs fix(ci): unblock dependabot dependency PR checks (#658) 2026-02-17 15:51:07 -05:00
shell.rs feat(config): make config writes atomic with rollback-safe replacement (#190) 2026-02-15 12:18:45 -05:00
traits.rs test: deepen and complete project-wide test coverage (#297) 2026-02-16 05:58:24 -05:00