// SPDX-License-Identifier: MPL-2.0 #include "sequa/platform/process.hpp" #include "sequa/studio/host/paths.hpp" #include "sequa/studio/host/shadow.hpp" #include "temp_dir.hpp" #include #include using namespace sequa::studio::host; namespace { // Enfant de test de platform/process : écrit, attend, sort avec un code donné. const std::filesystem::path child = SEQUA_TEST_CHILD; } // namespace TEST_CASE("Copie fantome : nom, nettoyage, copie en cours d'execution conservee") { testing::TempDir dir; const auto bin = bin_dir(dir.path()); const auto first = make_shadow_copy(child, bin); const auto second = make_shadow_copy(child, bin); // même seconde : suffixe -1 REQUIRE(first.has_value()); REQUIRE(second.has_value()); CHECK(*first != *second); CHECK(is_shadow_copy_name(first->filename().string())); CHECK(is_shadow_copy_name(second->filename().string())); CHECK_FALSE(make_shadow_copy(dir.path() / "absent.exe", bin).has_value()); // Un fichier étranger dans bin/ n'est jamais touché. const auto foreign = bin / "autre-outil.exe"; std::filesystem::copy_file(child, foreign); auto running = sequa::platform::ChildProcess::launch(*first, {"--sleep", "3000"}); REQUIRE(running.has_value()); const std::size_t removed = cleanup_shadow_copies(bin); #if defined(_WIN32) CHECK(removed == 1); // la copie en cours d'exécution est verrouillée CHECK(std::filesystem::exists(*first)); #else CHECK(removed == 2); #endif CHECK_FALSE(std::filesystem::exists(*second)); CHECK(std::filesystem::exists(foreign)); running->terminate(); CHECK(cleanup_shadow_copies(bin) <= 1); } TEST_CASE("Copie fantome : reconnaissance du motif") { CHECK(is_shadow_copy_name("sequa-core-20261106T210000Z-1234.exe")); CHECK(is_shadow_copy_name("sequa-core-20261106T210000Z-1234-2")); CHECK_FALSE(is_shadow_copy_name("sequa-core.exe")); CHECK_FALSE(is_shadow_copy_name("sequa-core-20261106T210000Z.exe")); CHECK_FALSE(is_shadow_copy_name("sequa-core-2026110XT210000Z-1.exe")); CHECK_FALSE(is_shadow_copy_name("sequa-core-20261106T210000Z-12a.exe")); CHECK_FALSE(is_shadow_copy_name("autre-20261106T210000Z-1.exe")); }