spec/mspec/lib/mspec/helpers/tmp.rb also tries to remove SPEC_TEMP_DIR
at exit, before this `END`. At that time, the "tmp" marker directory
causes an ENOTEMPTY.
The sandbox marker created at the temp root is ours, so the END block
must remove it before Dir.rmdir(tmpdir); otherwise that call always
fails with ENOTEMPTY and a clean run looks like it left files behind.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bundler's spec helpers walk up from the working directory looking for a
`.bundle` directory, stopping at the first ancestor that contains a `tmp`
directory (Bundler::SharedHelpers#search_up). On Windows the test temp dir
lives under the user home (%LOCALAPPDATA%\Temp), so the search escaped the
sandbox and picked up the real ~/.bundle, breaking config, cache and other
specs. Create a `tmp` marker at the temp root so the search stops there.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
On Windows, when a test process is killed after a timeout, the OS may
not release file/directory handles immediately. The Dir.rmdir in the
diagnostic tree-walk raises Errno::EACCES, which was unhandled, causing
the entire cleanup to abort before FileUtils.rm_rf could run.
Rescue EACCES in the best-effort tree cleanup so it falls through to
FileUtils.rm_rf which handles this more robustly.