Files
buzz/crates/buzz-agent/tests
Matt Toohey d14e95f90e test: stop desktop, buzz-agent and mobile tests leaking temp files (#8748)
## Summary

Six test files wrote into the shared temp dir on every normal run and
never removed what they wrote.

**Desktop and buzz-agent (first commit)**

- `desktop/src/protectedFeatures/tauriCommand.test.mjs` wrote its fake
Tauri CLI and three result files straight into `/tmp` under pid-suffixed
names. They now live under one `mkdtempSync` root that an `after()` hook
removes.
- `crates/buzz-agent/tests/permission_boundary.rs` wrote a
`buzz_perm_calllog_*` file for every test whose tool call reached
`fake_mcp`, five per run. `call_log_path` now returns a `TempDir` guard
with the log path inside it, so the log is deleted when the test ends,
including when an assertion panics.
- `cancel_kills_inflight_tool_via_mcp_notification` in
`crates/buzz-agent/tests/regressions.rs` spawns `buzz-dev-mcp`, which
the agent stops with SIGKILL, so the server's `buzz-dev-mcp-*` and
`buzz-dev-mcp-session-*` TempDirs were never deleted. The test now
passes the server a `TMPDIR` it owns and removes.

**Mobile (second commit)**

The three mobile test files left 12 `buzz-video-*` files and 4
`transcode_*` dirs per run.

- `video_viewer_test.dart` and `video_controls_test.dart` pointed their
fake `path_provider` at `Directory.systemTemp`. The viewer downloads
each video there as `buzz-video-*`, and its async delete on close never
completes under FakeAsync. Each test now gets its own temp dir for the
fake, and an `addTearDown` removes it with `deleteSync`. In
`video_controls_test.dart` that teardown is registered first, so it runs
after the viewer is disposed.
- Four `media_upload_test.dart` tests faked `transcodeVideoToMp4` by
writing `out.mp4` into a new `systemTemp` `transcode_*` dir. The upload
service deletes `out.mp4` but not its dir. The fakes now create that dir
under the test's own temp root, which the test already deletes in
`finally`.

Production code is unchanged. **`buzz-dev-mcp`'s SIGKILL shutdown is
left for a follow-up:** the agent still stops the server with SIGKILL,
so outside tests the server's temp dirs are still left behind. Sending
SIGTERM first is the real fix.

### Related issue

None found. This continues the test-cleanup work in #8727.

### Testing

Each run below was bracketed by listings of `/tmp` and the per-user temp
dir (`/var/folders/.../T`), so new leftovers would show up.

- `tauriCommand.test.mjs`: 3/3 pass, with no new `buzz-tauri-*` or
`buzz-fake-tauri-*` entries.
- `cargo test -p buzz-agent --test permission_boundary`: 9/9 pass, with
no new `buzz_perm_calllog_*` files. The tests still check that the call
log is written, so the log really is going into the guarded dir.
- `cancel_kills_inflight_tool_via_mcp_notification` passes with
`buzz-dev-mcp` built, so it ran rather than skipped, and left no new
`buzz-dev-mcp-*` dirs.
- Mobile: `video_viewer_test` (7 tests), `video_controls_test` (20) and
`media_upload_test` (38) pass, each run on its own. With `TMPDIR`
pointed at a scratch dir, the old versions left 12 `buzz-video-*` files
and 4 `transcode_*` dirs, and the new versions left it empty.
- After cherry-picking onto current main, these pass:
  - `cargo clippy -p buzz-agent --all-targets -- -D warnings`
  - biome and `node --check` on `tauriCommand.test.mjs`
  - `dart format` and `flutter analyze` on the three mobile files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 10:35:26 +11:00
..