Refine macOS/LogAlias platform tuning, fix a real WithRoot bug found on Windows

Platform tuning:
- macOS Desktop's RuntimeDir() now prefers $TMPDIR (the OS-managed,
  per-user ephemeral directory NSTemporaryDirectory() returns) over
  the previous ~/Library/Application Support/<App>/Runtime placeholder.
- Resolver.EnsureLogAlias() creates the optional LogAliasDir() symlink
  to LogDir(), idempotently, leaving any pre-existing entry alone.

Verified the SHGetKnownFolderPath fallback (knownfolders_windows.go)
on a real Windows host for the first time: with APPDATA/LOCALAPPDATA/
PROGRAMDATA all unset, it correctly resolves the real known folders.
go vet's one unsafeptr finding there is a documented, permanent,
unavoidable characteristic of this raw-syscall pattern, not a bug.

That same real-Windows run surfaced a genuine, previously-invisible
bug: WithRoot assumed root's own address family always matched the
*simulated* platform's, which silently broke (mixed separators, or an
outright invalid mid-path drive letter) whenever the real host's
native family differed from what WithPlatform was simulating -- e.g.
WithPlatform("linux") with WithRoot(t.TempDir()) on a real Windows
host. This was invisible on macOS/Linux, where t.TempDir() happens to
already share the simulated Unix family.

Fixed applyRoot (now applyRootRebase) to decompose the resolved path
into segments and re-join them onto root using root's own family,
inferred from its content like JoinDirFile already does, not from the
simulated platform. Two call sites chaining onto an already-rooted
value (logDirUnix, darwin.go's State/Runtime fallback) switched from a
hardcoded unixJoin to JoinDirFile for the same reason. core/config's
working-directory layer had the identical bug one level up; fixed via
a new paths.JoinDirFileFamily.

TODO.md/ARCHITECTURE.md/README.md updated accordingly; core/TODO.md's
remaining items are now all explicitly out-of-scope or deliberately
deprioritized, not open work.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
terminarandClaude Sonnet 5 committed 2026-09-20 16:37:30 +02:00
1 parent e6b5324ad3
commit da2ec85381
13 files changed
+515 -70

No files matched your search

+23
View File
@@ -164,12 +164,35 @@ func TestWindowsDesktopSimplerLayering(t *testing.T) {
}
func TestWindowsMissingHomeIsCleanError(t *testing.T) {
// windowsBase's native SHGetKnownFolderPath fallback (see
// knownfolders_windows.go) is only consulted when actually running
// on a real Windows host (runtime.GOOS == "windows"), regardless of
// WithPlatform -- deliberately, so it reflects genuine behavior
// there instead of firing under simulation. That means this specific
// scenario (empty environment, no override) resolves a *real*
// known-folder path on an actual Windows host instead of erroring,
// which is correct, intended behavior, not a bug -- but it makes
// this test non-deterministic across hosts. Disable the native
// fallback here so the "no override, no env, no fallback available"
// path is exercised deterministically on every host, including real
// Windows (see the Windows-verification note in TODO.md).
withoutNativeKnownFolder(t)
r := mustResolver(t, yetApp(), WithPlatform("windows"), WithEnvironment(map[string]string{}))
if _, err := r.ConfigDir(); err != ErrNoHomeDirectory {
t.Fatalf("ConfigDir() error = %v, want ErrNoHomeDirectory", err)
}
}
// withoutNativeKnownFolder disables nativeKnownFolder for the duration
// of t, restoring its previous value afterwards.
func withoutNativeKnownFolder(t *testing.T) {
t.Helper()
prev := nativeKnownFolder
nativeKnownFolder = nil
t.Cleanup(func() { nativeKnownFolder = prev })
}
func TestWindowsAPIOverride(t *testing.T) {
r := mustResolver(t, yetApp(), WithPlatform("windows"), WithEnvironment(windowsEnv()), WithConfigDir(`D:\portable\yet-config`))
got, err := r.ConfigDir()