mirror of
https://github.com/block/buzz.git
synced 2026-11-01 23:11:58 +00:00
## Summary
`nest_dir()` fell back to `~/.buzz` whenever `init_nest_dir` had not
run. That is always true in unit tests, so a test that reached nest code
read the real nest and could rewrite `~/.buzz/AGENTS.md`.
- Under `cfg(test)` that fallback now panics. The message says how to
pin the nest: `pin_temp_nest_dir_for_thread()` for work on the test
thread, or `pin_nest_dir_for_test` in a child-process test for work on
other threads. The new thread pin returns a guard that owns a `TempDir`.
Dropping it unpins the thread and deletes the dir. A process-wide pin
does not fit in-process tests, because `cargo test` runs them all in one
process and the `OnceLock` can be set only once.
- Seven tests reached the fallback, all through
`default_agent_workdir()`:
`auth_command_uses_augmented_path_for_node_adapter`,
`test_prepared_install_command_uses_default_workdir` and five
`provider_deploy_*` tests. They now pin a temp nest. Under `cfg!(test)`,
`default_agent_workdir()` resolves on every call instead of caching for
the process, because a cached per-test nest would be deleted before the
next test used it.
- `nest_dir_is_under_home` and `init_nest_dir_prod_sets_buzz` could only
pass by reaching the fallback. A `should_panic` test of the guard
replaces them, plus a test that the thread pin and its dir go away on
drop.
- `init_nest_dir()` still resolved the real `~/.buzz{,-dev}` under
`cfg(test)`. An in-process test that reached `run_boot_migrations` would
have set the process-wide nest to the real one for every later test.
Now, under `cfg(test)`, it panics unless the nest is already pinned with
`pin_nest_dir_for_test`, and is a no-op when it is, as a second call is
in production. A thread pin does not count, because `init_nest_dir` sets
the nest for the whole process. No test reaches this today.
- Both panic messages point at `commands/agents_tests.rs`, which calls
`pin_nest_dir_for_test`, as the example to copy.
Production behaviour is unchanged.
### Related issue
None found. This continues the test-cleanup work in #8727.
### Testing
- `cargo test --workspace` in `desktop/src-tauri` passes: 3430 lib
tests, including both child-process pin tests.
- The new `init_nest_dir()` test runs in a child process, so a missing
guard cannot leak the real path to other tests. With the guard disabled,
it fails at "unpinned init_nest_dir() must panic".
- The `managed_agents::nest` tests pass with the final panic message.
- `just desktop-tauri-clippy` passes on the default and mesh-llm graphs,
re-run after cherry-picking onto current main.
🤖 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>