新v学员 runs magpie on native Windows. Library -> RTK -> Hermes Agent
failed with "rtk's installer didn't add its hook to Hermes Agent:
Config: C:\Users\admin\AppData\Local\hermes\config.yaml ...". magpie
hard-coded ~/.hermes. Hermes' own default
(hermes_constants._get_platform_default_hermes_home) is
$LOCALAPPDATA\hermes on win32 (~/AppData/Local/hermes when LOCALAPPDATA
is empty) and ~/.hermes elsewhere, with $HERMES_HOME overriding it.
rtk 0.51's resolve_hermes_home knows only $HERMES_HOME and ~/.hermes,
on every OS.
What changed:
- appdir.HermesHome / HermesHomeIn / HermesDefaultIn: $HERMES_HOME,
else Hermes' per-OS default. This is the one place that resolves it.
- agent: hermesIn (Agents-page model wiring) and hermesProfiles use it
through place.hermesHome / hermesDefault. A WSL distro keeps
~/.hermes (Linux paths, Windows env not read). The Agents-page wiring
was wrong on native Windows too: without HERMES_HOME it wrote
%USERPROFILE%\.hermes\config.yaml, which Hermes never reads.
- sessions.HermesDir uses it, so Windows sessions are found.
- library/rtk: the hermes spec reads and writes the agent's own folder
(a.Dir), and rtkSpec.env passes HERMES_HOME=<that folder> to
`rtk init -g --agent hermes --auto-patch`.
- Tests resolve the folder through appdir instead of home/.hermes. New
TestHermesDefault/TestHermesHome (appdir), TestHermesFolder (agent:
Windows default, profiles under it, WSL unchanged), and
TestRTKHermesHome (library, a fake rtk that behaves like 0.51).
- docs/reference.md and docs/subsystems/library.md describe the
Windows folder and the env.
Run:
- gofmt -l clean. go vet ./... on darwin, GOOS=linux -tags nogui and
GOOS=windows.
- darwin: go test ./internal/appdir ./internal/library
./internal/sessions ./internal/agent ./internal/tui.
- TestRTKHermesHome against the old rtk.go fails with the reporter's
exact message ("didn't add its hook ... AppData/Local/hermes/
config.yaml"), and its default subtest fails with HERMES_HOME="".
- Windows box (cross-compiled test binaries, testenv sandbox
USERPROFILE/LOCALAPPDATA): appdir Hermes tests, agent
Hermes|Reseat|Effort (incl. TestHermesFolder) and library Hermes|RTK
pass. TestRTKHermesHome skips there (shell fake). The sessions binary
failed only TestHermesMessageVisibility, because its testdata wasn't
copied to the box.
- Real rtk.exe 0.51.0 on the Windows box: with
HERMES_HOME=<sandbox>\AppData\Local\hermes it wrote the plugin there
and patched that config.yaml. Without HERMES_HOME it wrote
C:\Users\<user>\.hermes, ignoring a sandbox USERPROFILE (rtk asks
Windows for the home folder). That confirms the cause and the fix.
The stray folder it made on the test box was removed.
Not run: real Hermes on Windows (no install, and running hermes under
a temp HERMES_HOME rewrites the live launcher); the GUI suite; the full
go test ./... ; the reporter's own machine.
62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package appdir
|
|
|
|
import (
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
// TestHermesDefault: Hermes's default home is %LOCALAPPDATA%\hermes on
|
|
// Windows, AppData\Local\hermes under the home folder without LOCALAPPDATA,
|
|
// and ~/.hermes everywhere else (hermes_constants.
|
|
// _get_platform_default_hermes_home). magpie looked in ~/.hermes on Windows
|
|
// too, where Hermes and rtk's hook weren't (新v学员 on Discord).
|
|
func TestHermesDefault(t *testing.T) {
|
|
home := filepath.Join("C:", "Users", "admin")
|
|
local := filepath.Join(home, "AppData", "Local")
|
|
for _, c := range []struct{ goos, local, want string }{
|
|
{"windows", local, filepath.Join(local, "hermes")},
|
|
{"windows", "", filepath.Join(home, "AppData", "Local", "hermes")},
|
|
{"windows", filepath.Join("D:", "Local"), filepath.Join("D:", "Local", "hermes")},
|
|
{"darwin", local, filepath.Join(home, ".hermes")},
|
|
{"linux", "", filepath.Join(home, ".hermes")},
|
|
} {
|
|
if got := hermesDefault(c.goos, home, c.local); got != c.want {
|
|
t.Errorf("%s, LOCALAPPDATA=%q: %q, want %q", c.goos, c.local, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestHermesHome: HERMES_HOME comes first; without it, the platform's
|
|
// default, LOCALAPPDATA read as this machine has it.
|
|
func TestHermesHome(t *testing.T) {
|
|
home := t.TempDir()
|
|
local := filepath.Join(home, "AppData", "Local")
|
|
t.Setenv("LOCALAPPDATA", local)
|
|
t.Setenv("HERMES_HOME", "")
|
|
want := filepath.Join(home, ".hermes")
|
|
if runtime.GOOS == "windows" {
|
|
want = filepath.Join(local, "hermes")
|
|
}
|
|
if got := HermesHomeIn(home); got != want {
|
|
t.Errorf("HermesHomeIn = %q, want %q", got, want)
|
|
}
|
|
if got := HermesDefaultIn(home); got != want {
|
|
t.Errorf("HermesDefaultIn = %q, want %q", got, want)
|
|
}
|
|
custom := filepath.Join(home, "elsewhere")
|
|
t.Setenv("HERMES_HOME", custom)
|
|
if got := HermesHomeIn(home); got != custom {
|
|
t.Errorf("HermesHomeIn with HERMES_HOME = %q, want %q", got, custom)
|
|
}
|
|
if got := HermesDefaultIn(home); got != want {
|
|
t.Errorf("HermesDefaultIn with HERMES_HOME = %q, want %q", got, want)
|
|
}
|
|
// a relative one, which Hermes would take from its working folder,
|
|
// reads as unset
|
|
t.Setenv("HERMES_HOME", "rel")
|
|
if got := HermesHomeIn(home); got != want {
|
|
t.Errorf("HermesHomeIn with a relative HERMES_HOME = %q, want %q", got, want)
|
|
}
|
|
}
|