provider: a plugin host ends with the test whose HOME it started in (#6761)

TestRemoveListedAccountLeavesHiddenNamesake failed in full runs (CI Test
at e99307fb8, ubuntu) and passed alone. A bisect over the 1779 tests
that run before it found TestPluginEmptyKeyKeyAsked: its PluginAPIKey
starts a real plugin host (Bun) and leaves it up. plugin.SignOut asks a
running host, and that host's files are the earlier test's HOME, so the
remove landed there and this test's plugin-auth.json kept the account.

claudeHome (which movedPlugin and the culprit both use) now stops a
host that is up before it sets the new HOME, and again in cleanup. That
covers every provider test that sets a HOME through it, not only this
pair.

Run (mote, then mica as mote was over its cores):
- red before: -run '^(TestPluginEmptyKeyKeyAsked|TestRemoveListedAccountLeavesHiddenNamesake)$'
  -> "the account removed is still signed in"; green after.
- go vet ./internal/provider/; go test -count=1 -timeout 45m
  ./internal/provider/ ./internal/plugin/ at this tree: ok 142.9s, ok 171.6s.
Not run: the full suite (test-only change in one package's helper).
This commit is contained in:
yetone
2026-11-15 22:38:32 +08:00
parent 9bcdcfb7d1
commit 248edad80c
+14
View File
@@ -19,6 +19,7 @@ import (
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/codexcat"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/testenv"
)
@@ -325,10 +326,23 @@ func claudeHome(t *testing.T) string {
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
// a plugin host is this test's HOME's: one an earlier test left up
// would answer a sign-out in that test's files, not these (#6761), so
// none is up before, and the one this test starts ends with it
stopPluginHost()
t.Cleanup(stopPluginHost)
forgetClaudeCredential()
return home
}
// stopPluginHost stops a plugin host that is up, so the next call starts
// one under the HOME it is made in.
func stopPluginHost() {
if plugin.Running() {
plugin.Restart()
}
}
func TestClaudeAccountIsProvider(t *testing.T) {
home := claudeHome(t)
creds := claudeSignIn(t, home, time.Now().Add(time.Hour))