From c06a550b73680289d5a94de7a412356d4040297d Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 7 Oct 2026 02:21:39 +0800 Subject: [PATCH] provider tests: the hold tests pass on any -count, each starting from a config folder of its own instead of the files the last round left TestHoldReadsSettingsOnce and TestHoldReadsMigrationsOnce failed on every -count>=2, without any load ("a visibility before any was set", "moved before any move"): they wrote settings.json and migrations.json into the package's one test HOME, so the second round found held-agent's visibility and held-sub's move already there. The leftover was only those files, not a package global production relies on: Hold's cache is dropped at the last release, and filememo re-reads a file that changed. Each of the four hold tests that writes a magpie file now sets XDG_CONFIG_HOME to a TempDir, as the rest of the package's tests do. Before: go test -run TestHoldReads -count=2 fails both. After: -run TestHold -count=20 -race -shuffle=on passes. --- internal/provider/hold_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/provider/hold_test.go b/internal/provider/hold_test.go index f9a0586d..111f8535 100644 --- a/internal/provider/hold_test.go +++ b/internal/provider/hold_test.go @@ -46,6 +46,7 @@ func TestHoldBuildsOnce(t *testing.T) { // the agents read settings.json for every model of every agent), and a // setting saved meanwhile is seen at once. func TestHoldReadsSettingsOnce(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // a run starts from no files, not the last run's defer Hold()() if _, ok := VisibleTo("held-agent"); ok { t.Fatal("a visibility before any was set") @@ -69,6 +70,7 @@ func TestHoldReadsSettingsOnce(t *testing.T) { // A provider saved while a request holds the catalog is in it at once. func TestHoldSeesWrites(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // a run starts from no files, not the last run's if err := Save(Provider{ID: "held", Name: "Held", Chat: "https://held.example/v1", Key: "k", Models: []string{"a"}}); err != nil { t.Fatal(err) } @@ -100,6 +102,7 @@ func TestHoldSeesWrites(t *testing.T) { // account written meanwhile has them built again, and a caller changing // its list changes no one else's. func TestHoldBuildsProvidersOnce(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // a run starts from no files, not the last run's if err := Save(Provider{ID: "once", Name: "Once", Chat: "https://once.example/v1", Key: "k", Models: []string{"a"}}); err != nil { t.Fatal(err) } @@ -178,6 +181,7 @@ func TestCursorKeychainReadOnce(t *testing.T) { // and a move written meanwhile, even one read from the file as it was // before, is seen at once. func TestHoldReadsMigrationsOnce(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) // a run starts from no files, not the last run's defer Hold()() if Moved("held-sub") { t.Fatal("moved before any move")