From 798b01c3a67fe5d07c3fce3edc4d7db178024a29 Mon Sep 17 00:00:00 2001 From: Sam Freund Date: Sun, 1 Feb 2026 21:30:37 -0600 Subject: [PATCH] Copy old configs before testing (#2348) ## Description Presently, any tests using our old configs happen in place. This is problematic, as it changes the files themselves. This means that anyone running the tests will cause unintentional modifications, which stand a chance of being committed and merged into main. We want these old database files to remain untouched, thus we copy them to a temp directory prior to running our tests. ## Meta Merge checklist: - [x] Pull Request title is [short, imperative summary](https://cbea.ms/git-commit/) of proposed changes - [x] The description documents the _what_ and _why_, including events that led to this PR - [ ] If this PR changes behavior or adds a feature, user documentation is updated - [ ] If this PR touches photon-serde, all messages have been regenerated and hashes have not changed unexpectedly - [ ] If this PR touches configuration, this is backwards compatible with all settings going back to the previous seasons's last release (seasons end after champs ends) - [ ] If this PR touches pipeline settings or anything related to data exchange, the frontend typing is updated - [ ] If this PR addresses a bug, a regression test for it is added --- .../common/configuration/SQLConfigTest.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java b/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java index 0d1a8061d..4bc11bbf7 100644 --- a/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java +++ b/photon-core/src/test/java/org/photonvision/common/configuration/SQLConfigTest.java @@ -22,9 +22,11 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import com.fasterxml.jackson.core.JsonProcessingException; import edu.wpi.first.cscore.UsbCameraInfo; +import java.io.IOException; import java.nio.file.Path; import java.util.Collection; import java.util.List; +import org.apache.commons.io.FileUtils; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -43,7 +45,7 @@ import org.photonvision.vision.pipeline.PipelineType; import org.photonvision.vision.pipeline.ReflectivePipelineSettings; public class SQLConfigTest { - @TempDir private static Path tmpDir; + @TempDir private Path tmpDir; @BeforeAll public static void init() { @@ -91,11 +93,15 @@ public class SQLConfigTest { } @Test - public void testLoad2024_3_1() { - var cfgLoader = - new SqlConfigProvider( - TestUtils.getConfigDirectoriesPath(false) - .resolve("photonvision_config_from_v2024.3.1")); + public void testLoad2024_3_1() throws IOException { + // Copy the 2024.3.1 config to a temp dir + FileUtils.copyDirectory( + TestUtils.getConfigDirectoriesPath(false) + .resolve("photonvision_config_from_v2024.3.1") + .toFile(), + tmpDir.resolve("photonvision_config_from_v2024.3.1").toFile()); + + var cfgLoader = new SqlConfigProvider(tmpDir.resolve("photonvision_config_from_v2024.3.1")); assertDoesNotThrow(cfgLoader::load); @@ -128,8 +134,12 @@ public class SQLConfigTest { } @Test - public void testLoadNewNNMM() throws JsonProcessingException { - var folder = TestUtils.getConfigDirectoriesPath(false).resolve("2025.3.1-old-nnmm"); + public void testLoadNewNNMM() throws JsonProcessingException, IOException { + var folder = tmpDir.resolve("2025.3.1-old-nnmm"); + FileUtils.copyDirectory( + TestUtils.getConfigDirectoriesPath(false).resolve("2025.3.1-old-nnmm").toFile(), + folder.toFile()); + var cfgManager = new ConfigManager(folder, new SqlConfigProvider(folder)); // Replace global configmanager @@ -161,8 +171,12 @@ public class SQLConfigTest { } @Test - public void testMaxDetectionsMigration() { - var folder = TestUtils.getConfigDirectoriesPath(false).resolve("2025.3.1-old-nnmm"); + public void testMaxDetectionsMigration() throws IOException { + var folder = tmpDir.resolve("2025.3.1-old-nnmm"); + FileUtils.copyDirectory( + TestUtils.getConfigDirectoriesPath(false).resolve("2025.3.1-old-nnmm").toFile(), + folder.toFile()); + var cfgManager = new ConfigManager(folder, new SqlConfigProvider(folder)); // Replace global configmanager