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:
1 parent
e6b5324ad3
commit
da2ec85381
13 files changed
+515
-70
No files matched your search
+53
-12
@@ -58,24 +58,46 @@ func TestSplitWindowsRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyRootUnix(t *testing.T) {
|
||||
if got, want := applyRootUnix("", "/etc/yet"), "/etc/yet"; got != want {
|
||||
t.Errorf("applyRootUnix(\"\", ...) = %q, want %q", got, want)
|
||||
func TestApplyRootRebaseUnix(t *testing.T) {
|
||||
if got, want := applyRootRebase("", "/etc/yet", false), "/etc/yet"; got != want {
|
||||
t.Errorf("applyRootRebase(\"\", ...) = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := applyRootUnix("/tmp/root", "/etc/yet"), "/tmp/root/etc/yet"; got != want {
|
||||
t.Errorf("applyRootUnix = %q, want %q", got, want)
|
||||
if got, want := applyRootRebase("/tmp/root", "/etc/yet", false), "/tmp/root/etc/yet"; got != want {
|
||||
t.Errorf("applyRootRebase = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyRootWindows(t *testing.T) {
|
||||
if got, want := applyRootWindows("", `C:\ProgramData\yet`), `C:\ProgramData\yet`; got != want {
|
||||
t.Errorf("applyRootWindows(\"\", ...) = %q, want %q", got, want)
|
||||
func TestApplyRootRebaseWindows(t *testing.T) {
|
||||
if got, want := applyRootRebase("", `C:\ProgramData\yet`, true), `C:\ProgramData\yet`; got != want {
|
||||
t.Errorf("applyRootRebase(\"\", ...) = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := applyRootWindows(`C:\sandbox`, `C:\ProgramData\yet`), `C:\sandbox\ProgramData\yet`; got != want {
|
||||
t.Errorf("applyRootWindows = %q, want %q", got, want)
|
||||
if got, want := applyRootRebase(`C:\sandbox`, `C:\ProgramData\yet`, true), `C:\sandbox\ProgramData\yet`; got != want {
|
||||
t.Errorf("applyRootRebase = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := applyRootWindows(`C:\sandbox`, `\\server\share\yet`), `C:\sandbox\yet`; got != want {
|
||||
t.Errorf("applyRootWindows(UNC) = %q, want %q", got, want)
|
||||
if got, want := applyRootRebase(`C:\sandbox`, `\\server\share\yet`, true), `C:\sandbox\yet`; got != want {
|
||||
t.Errorf("applyRootRebase(UNC) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// TestApplyRootRebaseMismatchedFamily covers the scenario that motivated
|
||||
// applyRootRebase's design: root in the REAL host's native family (e.g.
|
||||
// t.TempDir()'s result on a real Windows host) combined with p in a
|
||||
// *different*, simulated platform's family (see README's "Testing on
|
||||
// any host"). Before this was fixed, mismatched families produced a
|
||||
// mixed-separator (Unix root, Windows-native root) or doubly-drive-
|
||||
// lettered (Windows root, Unix p incorrectly windows-joined) result.
|
||||
func TestApplyRootRebaseMismatchedFamily(t *testing.T) {
|
||||
// Windows-native root (as a real t.TempDir() would return), Unix p
|
||||
// (a Linux-simulated resolver's unrooted result).
|
||||
if got, want := applyRootRebase(`C:\Users\test\AppData\Local\Temp\001`, "/home/test/.config/yet", false),
|
||||
`C:\Users\test\AppData\Local\Temp\001\home\test\.config\yet`; got != want {
|
||||
t.Errorf("applyRootRebase(windows root, unix p) = %q, want %q", got, want)
|
||||
}
|
||||
// Unix-native root, Windows p (a Windows-simulated resolver's
|
||||
// unrooted result) -- the mirror image, for symmetry.
|
||||
if got, want := applyRootRebase("/tmp/sandbox", `C:\Users\test\AppData\Roaming\yet`, true),
|
||||
"/tmp/sandbox/Users/test/AppData/Roaming/yet"; got != want {
|
||||
t.Errorf("applyRootRebase(unix root, windows p) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,3 +109,22 @@ func TestJoinDirFile(t *testing.T) {
|
||||
t.Errorf("JoinDirFile(windows) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJoinDirFileFamily(t *testing.T) {
|
||||
// dir carries its own family: content wins regardless of platform.
|
||||
if got, want := JoinDirFileFamily("windows", "/etc/yet", "yet.yaml"), "/etc/yet/yet.yaml"; got != want {
|
||||
t.Errorf("JoinDirFileFamily(unix dir, windows platform) = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := JoinDirFileFamily("linux", `C:\Users\test\workdir`, "yet.yaml"),
|
||||
`C:\Users\test\workdir\yet.yaml`; got != want {
|
||||
t.Errorf("JoinDirFileFamily(windows dir, linux platform) = %q, want %q", got, want)
|
||||
}
|
||||
// dir is ambiguous (no separator of its own, e.g. the default "."):
|
||||
// platform decides, same as JoinFamily.
|
||||
if got, want := JoinDirFileFamily("windows", ".", "yet.yaml"), `.\yet.yaml`; got != want {
|
||||
t.Errorf("JoinDirFileFamily(ambiguous, windows) = %q, want %q", got, want)
|
||||
}
|
||||
if got, want := JoinDirFileFamily("linux", ".", "yet.yaml"), "./yet.yaml"; got != want {
|
||||
t.Errorf("JoinDirFileFamily(ambiguous, linux) = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user