mirror of
https://github.com/block/buzz.git
synced 2026-11-28 12:12:04 +00:00
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>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { test } from "node:test";
|
||||
import { after, test } from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { spawn } from "node:child_process";
|
||||
|
||||
@@ -12,7 +12,11 @@ const desktopRoot = path.resolve(
|
||||
);
|
||||
const configDir = path.join(desktopRoot, "src-tauri");
|
||||
const wrapper = path.join(desktopRoot, "scripts/tauri-command.mjs");
|
||||
const fakeCli = path.join(tmpdir(), `buzz-fake-tauri-${process.pid}.mjs`);
|
||||
// Everything these tests write lives under one private root, removed once the
|
||||
// file's tests finish.
|
||||
const tempRoot = mkdtempSync(path.join(tmpdir(), "buzz-tauri-command-test-"));
|
||||
after(() => rmSync(tempRoot, { recursive: true, force: true }));
|
||||
const fakeCli = path.join(tempRoot, "fake-tauri.mjs");
|
||||
|
||||
writeFileSync(
|
||||
fakeCli,
|
||||
@@ -65,10 +69,8 @@ function packageVariant(variant, result, runnerArguments = []) {
|
||||
}
|
||||
|
||||
test("opposite Tauri package variants own private frontend artifacts", async () => {
|
||||
const resultRoot = path.join(tmpdir(), `buzz-tauri-results-${process.pid}`);
|
||||
mkdirSync(resultRoot, { recursive: true });
|
||||
const ossResult = path.join(resultRoot, "oss.json");
|
||||
const internalResult = path.join(resultRoot, "internal.json");
|
||||
const ossResult = path.join(tempRoot, "oss.json");
|
||||
const internalResult = path.join(tempRoot, "internal.json");
|
||||
|
||||
await Promise.all([
|
||||
packageVariant("0", ossResult),
|
||||
@@ -83,10 +85,7 @@ test("opposite Tauri package variants own private frontend artifacts", async ()
|
||||
});
|
||||
|
||||
test("private config precedes Cargo runner arguments", async () => {
|
||||
const result = path.join(
|
||||
tmpdir(),
|
||||
`buzz-tauri-runner-arguments-${process.pid}.json`,
|
||||
);
|
||||
const result = path.join(tempRoot, "runner-arguments.json");
|
||||
await packageVariant("0", result, [
|
||||
"--config",
|
||||
'{"bundle":{"active":false}}',
|
||||
@@ -106,10 +105,7 @@ test("private config precedes Cargo runner arguments", async () => {
|
||||
});
|
||||
|
||||
test("private frontendDist is never mistaken for a URL", async () => {
|
||||
const result = path.join(
|
||||
tmpdir(),
|
||||
`buzz-tauri-frontend-dist-${process.pid}.json`,
|
||||
);
|
||||
const result = path.join(tempRoot, "frontend-dist.json");
|
||||
await packageVariant("0", result);
|
||||
const invocation = JSON.parse(readFileSync(result, "utf8"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user