@@ -431,27 +431,26 @@ TEST(midi_learn_cancel) {
431431// ===========================================================================
432432
433433/* *
434- * @brief RAII Cleanup Guard structure ensuring strict test isolation by backing up
435- * and recovering local disk configuration payloads automatically .
434+ * @brief RAII Cleanup Guard ensuring strict test isolation by forcing file operations
435+ * into a unique temporary workspace directory across all development platforms .
436436 */
437437struct config_backup_guard {
438+ std::filesystem::path original_cwd;
439+ std::filesystem::path temp_dir;
438440 std::string config_file = " midi_config.json" ;
439- std::string backup_file = " midi_config.json.bak" ;
440- bool backed_up = false ;
441441
442442 config_backup_guard () {
443- if (fs::exists (config_file)) {
444- fs::rename (config_file, backup_file);
445- backed_up = true ;
446- }
443+ original_cwd = std::filesystem::current_path ();
444+ // Generate a unique directory name using random tokens
445+ temp_dir = std::filesystem::temp_directory_path () / std::filesystem::path (" midi_test_" + std::to_string (std::rand ()));
446+ std::filesystem::create_directories (temp_dir);
447+ std::filesystem::current_path (temp_dir);
447448 }
448449
449450 ~config_backup_guard () {
450- if (fs::exists (config_file)) {
451- fs::remove (config_file);
452- }
453- if (backed_up && fs::exists (backup_file)) {
454- fs::rename (backup_file, config_file);
451+ std::filesystem::current_path (original_cwd);
452+ if (!temp_dir.empty () && std::filesystem::exists (temp_dir)) {
453+ std::filesystem::remove_all (temp_dir);
455454 }
456455 }
457456};
0 commit comments