feat(core): keep a host native binary's state in the user data directory (#5769)

The bundled persistent path is ./data, relative to the working directory.
That suits the image (which sets /app/data) and a run from the checkout, but
a native binary on the PATH would write its state, and its TLS material,
into whatever directory it was started from.

A native run outside a container now defaults to the platform's per-user data
directory: $XDG_DATA_HOME/floci-aws (or ~/.local/share/floci-aws) on Linux,
~/Library/Application Support/floci-aws on macOS, %LOCALAPPDATA%\floci-aws on
Windows. HostDefaultsConfigSource sits at ordinal 260, between the bundled
application.yml (255) and config/application.yml (265), so any path the
user configures still wins. The JVM, dev mode and the image keep ./data.

Refs #5767

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-16 00:01:06 -04:00
1 parent 6e01216f88
commit 0a5809a559
6 files changed
+207 -1

No files matched your search

@@ -0,0 +1,44 @@
package io.github.hectorvent.floci.config;
import org.junit.jupiter.api.Test;
import java.nio.file.Path;
import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
class HostDataDirTest {
@Test
void linuxUsesXdgDataHomeWhenSet() {
assertThat(HostDataDir.forPlatform("Linux", Map.of("XDG_DATA_HOME", "/srv/xdg"), "/home/u"),
equalTo(Path.of("/srv/xdg", "floci-aws")));
}
@Test
void linuxFallsBackToLocalShare() {
assertThat(HostDataDir.forPlatform("Linux", Map.of("XDG_DATA_HOME", " "), "/home/u"),
equalTo(Path.of("/home/u", ".local", "share", "floci-aws")));
}
@Test
void macUsesApplicationSupport() {
assertThat(HostDataDir.forPlatform("Mac OS X", Map.of(), "/Users/u"),
equalTo(Path.of("/Users/u", "Library", "Application Support", "floci-aws")));
}
@Test
void windowsUsesLocalAppData() {
assertThat(HostDataDir.forPlatform("Windows 11", Map.of("LOCALAPPDATA", "C:/Users/u/AppData/Local"), "C:/Users/u"),
equalTo(Path.of("C:/Users/u/AppData/Local", "floci-aws")));
assertThat(HostDataDir.forPlatform("Windows 11", Map.of(), "C:/Users/u"),
equalTo(Path.of("C:/Users/u", "AppData", "Local", "floci-aws")));
}
@Test
void jvmRunsKeepTheBundledDefault() {
// The test JVM is not a native image, so nothing moves.
assertThat(HostDataDir.persistentPathDefault(), equalTo("./data"));
}
}
@@ -0,0 +1,39 @@
package io.github.hectorvent.floci.config;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.aMapWithSize;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.nullValue;
class HostDefaultsConfigSourceTest {
@Test
void emptyOutsideANativeHostRun() {
HostDefaultsConfigSource source = new HostDefaultsConfigSource(false);
assertThat(source.getProperties(), aMapWithSize(0));
assertThat(source.getValue(HostDefaultsConfigSource.PERSISTENT_PATH), nullValue());
}
@Test
void jvmConstructorIsEmpty() {
assertThat(new HostDefaultsConfigSource().getProperties(), aMapWithSize(0));
}
@Test
void nativeHostRunSetsBothPathsToTheSameDirectory() {
HostDefaultsConfigSource source = new HostDefaultsConfigSource(true);
String dir = source.getValue(HostDefaultsConfigSource.PERSISTENT_PATH);
assertThat(source.getValue(HostDefaultsConfigSource.HOST_PERSISTENT_PATH), equalTo(dir));
}
@Test
void ordinalOverridesOnlyTheBundledYaml() {
// classpath application.yml is 255, config/application.yml in the working directory 265.
assertThat(new HostDefaultsConfigSource(false).getOrdinal(), allOf(greaterThan(255), lessThan(265)));
}
}