Windows: Hermes profile tests share testenv's LOCALAPPDATA, so they read each other's profiles (5 red in a full internal/agent run)
What fails
On Windows, internal/agent's Hermes profile tests pass when run alone but fail when run together. Order decides which ones fail. In a full go test ./internal/agent -count=1 -timeout 45m at ea9f2639b (Windows 11, go1.26.8), five are red:
- TestHermesProfilesAreNotListedAsAgents (not filed before)
- TestHermesProfilesFollowMagpieModel (listed in #6068)
- TestHermesProfileModels (listed in #6068)
- TestHermesProfileRowsReadAsNames
- TestHermesProfilesAreAgents
--- FAIL: TestHermesProfileRowsReadAsNames
got map[hermes#chat:Hermes · chat hermes#default:Hermes · default hermes#empty:Hermes · empty hermes#excel--u64cd-u4f5c-u5458:… hermes#later:Hermes · later … hermes#writer:Hermes · writer]
want map[hermes#excel--u64cd-u4f5c-u5458:… (only its own 8)]
--- FAIL: TestHermesProfilesAreNotListedAsAgents (0.04s)
hermes_test.go:1135: the profile is no agent for the Library: <nil>
chat, default, empty, later and writer are other tests' profiles.
Small reproduction, no full run needed:
go test ./internal/agent -count=1 -run '^(TestHermesProfiles.*|TestHermesProfileRows.*|TestHermesProfileModels)$'
That gives 4 red: FollowMagpieModel, ProfileModels, ProfilesAreAgents and ProfileRowsReadAsNames. Each passes alone.
Cause
On Windows, Hermes's default home is %LOCALAPPDATA%\hermes (appdir.hermesDefault), not ~/.hermes. These tests sandbox HOME, USERPROFILE and HERMES_HOME="", but not LOCALAPPDATA. So appdir.HermesHomeIn(home) lands in testenv's package-wide sandbox, which every test shares, and each test reads the profiles the earlier ones wrote there. Logged from inside such a test:
home=C:\Users\…\Temp\TestZZWhereHermes3905026684\001
LOCALAPPDATA=C:\Users\…\Temp\magpie-test-home-1054898609\AppData\Local
HermesHomeIn=C:\Users\…\Temp\magpie-test-home-1054898609\AppData\Local\hermes
On macOS and Linux, Hermes's home is under HOME, so each test has its own folder and CI never shows this. Windows CI only compiles these tests.
Likely fix
Each Hermes test that sets its own HOME also sets LOCALAPPDATA (and APPDATA) under that home. A small helper shared by hermes_test.go would do it, as testenv does for the package. A guard could also check that HermesHomeIn(home) is under home. Not tried yet.
Found while running the full package for #6084. The run is unchanged by that branch: the same 40 reds at clean ea9f2639b.
A correction to the report above, after checking what it claimed but hadn't run. Windows 11, go1.26.8, at ea9f2639b.
Wrong: "each passes alone"
TestHermesProfilesAreAgents is red on this machine even alone, with -count=1:
hermes_test.go:1046: with Hermes gone: [hermes hermes#coder]
It has a second cause, separate from LOCALAPPDATA: the test reads the machine's real Hermes. This machine has Hermes installed, with %LOCALAPPDATA%\hermes\bin on PATH. After the test deletes its own hermes-agent folder, Hermes is still found installed through that, so the profile stays an agent. With the hermes entry taken off PATH, the test passes alone. The other four pass alone, once each.
(With -count=3 alone, TestHermesProfileModels is red too. That is the same shared folder: each run reads the profiles the previous run left there.)
Now tried: the LOCALAPPDATA cause
I tried the fix locally, uncommitted and then reverted: each Hermes test that sets USERPROFILE also sets t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local")), 15 lines in hermes_test.go.
| Run, with that change | Real hermes on PATH | Result |
|---|---|---|
-run '^(TestHermesProfiles.*|TestHermesProfileRows.*|TestHermesProfileModels)$' |
no | ok (4 red without the change) |
-run '^TestHermes' |
no | ok |
-run '^TestHermes' |
yes | TestHermesProfilesAreAgents red, the rest ok |
So LOCALAPPDATA isolation fixes the cross-test reds. TestHermesProfilesAreAgents also needs its install check kept off the real machine (PATH, or however Hermes is found), so a dev box with Hermes installed doesn't turn it red.
Not tried: a full internal/agent run with the change.