Keep tests out of the user profile; small socket fixes (#127)

* Keep tests out of the user profile

The no-argument ChatPreferences constructor seeds preferences.xml in
~/.praktiKST when it is missing, so 21 older test files could create a
profile file for whoever ran the build. They now use ChatPreferences(Path)
with a @TempDir. None of them reads the file: their assertions are on the
field initialisers, which both constructors share, so no assertion changes
meaning. ChatPreferencesStationMapVisibilityTest passes its file to the
constructor instead of redirecting it with the setter afterwards.

The two opt-in ON4KST practice tests keep the no-argument constructor: they
deliberately read the operator's real profile for live credentials.

As a net, the test tasks run with user.home pointed at build/test-user-home,
emptied before each run, and fail if a preferences.xml appears there. This
also keeps the sound files, the map tile cache and the Skiko native library
that tests unpacked into the real home directory out of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Make DXClusterThreadPooledServer.serverSocket volatile

run() assigns the server socket on the server thread, and stop() closes it
from another thread. closeServerSocket() is synchronized, but the write in
run() is not, so nothing guaranteed that stop() saw the socket run() had
opened; it could find null and leave the socket listening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Drop the ineffective SO_REUSEADDR from the Win-Test sked socket

WinTestSkedSender.sendUdp() set reuse address on a socket the constructor
had already bound, where it has no effect, so it was never in effect in any
shipped version. The socket binds an ephemeral port and only sends, which
gains nothing from it, and enabling it for real would change UDP multi-bind
semantics on Windows. Removing the call keeps the behaviour exactly as
shipped and stops the code from claiming an option it does not have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Check the test user.home in a finalizer task

The stray-preferences check ran as a doLast of the test task, which Gradle
skips once a test fails, so a failing run could hide the file. It is now a
separate task, checkTestUserHome, that every test task is finalized by;
finalizers run when the test task fails too. It captures only a File, so it
stays configuration-cache safe.

Each test task now gets its own scratch home, build/test-user-home/<task
name>, so a second test task cannot wipe another's. Emptying it checks the
result of deleteRecursively(), which reports failure instead of throwing,
and stops the task, so a leftover file is never blamed on the current run.

The check stays limited to preferences.xml. Other files land in the scratch
.praktiKST by design, such as the sound files PlayAudioUtils seeds from the
bundled resources; absorbing those is the redirection's job, and a wider
check would need an exclusion list that grows with every seeded file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Keep generateStrings configuration-cache safe

The argument provider of generateStrings referenced the script-level
generatedI18nDirectory, which captures the build script object, so storing
the configuration cache failed for every build that included app-desktop.
The task now works on a local copy of the provider.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Declare the test user.home as a test task output

Test tasks are cacheable, and a cache hit skips doFirst, so the scratch home
was neither emptied nor rewritten and checkTestUserHome judged whatever an
earlier run had left there: a false alarm after a violating run, or a hidden
violation when a passing result for violating inputs came from the cache.
The scratch home is now a declared output, restored and replaced together
with the cached result, so the check always sees the files belonging to the
inputs. The doFirst wipe stays for real executions.

Skiko unpacked its native library, about 30 MB, into the scratch home, which
would now land in every app-desktop cache entry. skiko.data.path points it
at build/skiko-data instead, outside the output and kept between runs.

user.home and skiko.data.path are passed through an argument provider: as
system properties they would be task inputs, and their absolute paths would
make the cache key differ between checkouts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Rsclub2_2andClaude Opus 5.5 authored and GitHub committed 2026-10-16 10:48:33 +02:00
1 parent 2898c530d9
commit 81b16ad4c5
25 files changed
+214 -84

No files matched your search

@@ -40,7 +40,8 @@ public class DXClusterThreadPooledServer implements Runnable {
Executors.newSingleThreadScheduledExecutor();
private volatile boolean stopped;
private ServerSocket serverSocket;
/** Assigned by run() on the server thread and closed by stop() from another one. */
private volatile ServerSocket serverSocket;
public DXClusterThreadPooledServer(
int port,
@@ -178,7 +178,6 @@ public class WinTestSkedSender {
private void sendUdp(WinTestMessage msg) throws Exception {
try (DatagramSocket socket = new DatagramSocket()) {
socket.setBroadcast(true);
socket.setReuseAddress(true);
byte[] bytes = msg.toBytes();
DatagramPacket packet = new DatagramPacket(bytes, bytes.length, broadcastAddress, port);
@@ -22,15 +22,20 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.Timeout;
import kst4contest.model.ChatCategory;
import kst4contest.model.ChatMessage;
import kst4contest.model.ChatPreferences;
import kst4contest.testing.ManualScheduler;
import java.nio.file.Path;
class On4KstConnectionProbeTest {
@TempDir
Path tempDir;
@Test
void separatesClientProbeServerProbeAndInternalResponses() {
assertEquals("CK|", On4KstProtocol.clientLivenessProbe());
@@ -357,7 +362,7 @@ class On4KstConnectionProbeTest {
}
private ChatPreferences localPreferences() {
ChatPreferences preferences = new ChatPreferences();
ChatPreferences preferences = new ChatPreferences(tempDir.resolve("preferences.xml"));
preferences.setStn_on4kstServersDns("127.0.0.1");
preferences.setStn_loginCallSign("DL1ABC");
preferences.setStn_loginPassword("test-password");
@@ -5,13 +5,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import kst4contest.model.ChatPreferences;
import java.nio.file.Path;
class On4KstProtocolTest {
@TempDir
Path tempDir;
@Test
void buildsLoginWithReplayOverlap() {
assertEquals(
@@ -72,7 +78,7 @@ class On4KstProtocolTest {
@Test
void resolvesBeaconVariablesBeforeApplyingProtocolValidation() {
ChatPreferences preferences = new ChatPreferences();
ChatPreferences preferences = new ChatPreferences(tempDir.resolve("preferences.xml"));
preferences.setMYQRGFirstCat("144.300");
ChatController controller = new ChatController();
@@ -92,7 +98,7 @@ class On4KstProtocolTest {
@Test
void acceptsTemporarilyUnresolvedVariableOnlyBeaconTemplate() {
ChatPreferences preferences = new ChatPreferences();
ChatPreferences preferences = new ChatPreferences(tempDir.resolve("preferences.xml"));
preferences.setMYQRGFirstCat("");
ChatController controller = new ChatController();
@@ -110,7 +116,7 @@ class On4KstProtocolTest {
@Test
void rejectsEmptyOverlongAndProtocolBreakingBeaconText() {
ChatPreferences preferences = new ChatPreferences();
ChatPreferences preferences = new ChatPreferences(tempDir.resolve("preferences.xml"));
ChatController controller = new ChatController();
controller.setChatPreferences(preferences);
@@ -1,21 +1,26 @@
package kst4contest.model;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.file.Path;
/** The interface language is stored per profile, like every other GUI preference. */
class ChatPreferencesLanguageTest {
@TempDir
Path tempDir;
@Test
void theDefaultIsTheSystemLanguage() {
// Empty means "follow the system", which is what the spec asks for on a first start.
assertEquals("", new ChatPreferences().getGuiOptions_language());
assertEquals("", new ChatPreferences(tempDir.resolve("preferences.xml")).getGuiOptions_language());
}
@Test
void aChosenLanguageIsKept() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
prefs.setGuiOptions_language("de");
@@ -24,7 +29,7 @@ class ChatPreferencesLanguageTest {
@Test
void aNullSetterValueBecomesEmpty() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
prefs.setGuiOptions_language(null);
@@ -1,6 +1,7 @@
package kst4contest.model;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
@@ -10,6 +11,7 @@ import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Path;
/**
* No default that goes to another radio amateur changes with the interface language.
@@ -22,11 +24,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
class ChatPreferencesLocaleTest {
@TempDir
Path tempDir;
private Map<String, String> stringFieldsUnder(final Locale locale) throws Exception {
Locale previous = Locale.getDefault();
try {
Locale.setDefault(locale);
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
Map<String, String> values = new LinkedHashMap<>();
for (Field field : ChatPreferences.class.getDeclaredFields()) {
@@ -1,16 +1,21 @@
package kst4contest.model;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.Path;
class ChatPreferencesObservableTest {
@TempDir
Path tempDir;
@Test
void theDefaultsMatchTheFormerJavaFxProperties() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
assertEquals(360.0, prefs.getActualQTF().get(), 0.0001,
"actualQTF defaulted to 360 as a SimpleDoubleProperty");
@@ -20,7 +25,7 @@ class ChatPreferencesObservableTest {
@Test
void theQrgValuesStartUnavailable() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
assertNull(prefs.getMYQRGFirstCat().get(),
"an unset own QRG must stay unavailable rather than becoming a fixed band");
@@ -29,7 +34,7 @@ class ChatPreferencesObservableTest {
@Test
void theListSettingsStartEmpty() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
assertTrue(prefs.getLstNotify_QSOSniffer_sniffedCallSignList().snapshot().isEmpty());
assertTrue(prefs.getLstNotify_QSOSniffer_sniffedPrefixLocList().snapshot().isEmpty());
@@ -1,8 +1,10 @@
package kst4contest.model;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.nio.file.Path;
/**
* The two designs' colour overrides are stored independently.
@@ -13,9 +15,12 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/
class ChatPreferencesPaletteTest {
@TempDir
Path tempDir;
@Test
void theTwoDesignsAreStoredIndependently() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
prefs.setGuiOptions_paletteOverridesDay("surface=#FFFFFF");
prefs.setGuiOptions_paletteOverridesEvening("surface=#000000");
@@ -27,7 +32,7 @@ class ChatPreferencesPaletteTest {
@Test
void anUnsetOverrideReadsAsEmptyAndNotAsNull() {
// A preferences file from an older release has no such element at all.
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
assertEquals("", prefs.getGuiOptions_paletteOverridesDay());
assertEquals("", prefs.getGuiOptions_paletteOverridesEvening());
@@ -35,7 +40,7 @@ class ChatPreferencesPaletteTest {
@Test
void aNullSetterValueBecomesEmpty() {
ChatPreferences prefs = new ChatPreferences();
ChatPreferences prefs = new ChatPreferences(tempDir.resolve("preferences.xml"));
prefs.setGuiOptions_paletteOverridesDay(null);
prefs.setGuiOptions_paletteOverridesEvening(null);
@@ -18,7 +18,8 @@ class ChatPreferencesStationMapVisibilityTest {
@Test
void pathAnalysisIsVisibleByDefault() {
ChatPreferences preferences = new ChatPreferences();
ChatPreferences preferences = new ChatPreferences(
temporaryDirectory.resolve("preferences.xml"));
assertTrue(preferences.isGUIstationMapPathAnalysisVisible());
}
@@ -27,9 +28,7 @@ class ChatPreferencesStationMapVisibilityTest {
void hiddenPathAnalysisStateSurvivesXmlRoundTrip() throws IOException {
Path preferencesFile = temporaryDirectory.resolve("preferences.xml");
ChatPreferences writtenPreferences = new ChatPreferences();
writtenPreferences.setStoreAndRestorePreferencesFileName(
preferencesFile.toString());
ChatPreferences writtenPreferences = new ChatPreferences(preferencesFile);
writtenPreferences.setGUIstationMapPathAnalysisVisible(false);
writtenPreferences.writePreferencesToXmlFile();
@@ -38,9 +37,7 @@ class ChatPreferencesStationMapVisibilityTest {
"<GUIstationMapPathAnalysisVisible>false"
+ "</GUIstationMapPathAnalysisVisible>"));
ChatPreferences restoredPreferences = new ChatPreferences();
restoredPreferences.setStoreAndRestorePreferencesFileName(
preferencesFile.toString());
ChatPreferences restoredPreferences = new ChatPreferences(preferencesFile);
restoredPreferences.readPreferencesFromXmlFile();
assertFalse(restoredPreferences.isGUIstationMapPathAnalysisVisible());
@@ -63,9 +60,8 @@ class ChatPreferencesStationMapVisibilityTest {
</praktiKST>
""");
ChatPreferences restoredPreferences = new ChatPreferences();
restoredPreferences.setStoreAndRestorePreferencesFileName(
legacyPreferencesFile.toString());
ChatPreferences restoredPreferences =
new ChatPreferences(legacyPreferencesFile);
restoredPreferences.readPreferencesFromXmlFile();
assertTrue(restoredPreferences.isGUIstationMapPathAnalysisVisible());