返回 DeepSeek-Reasonix
workspace_git_cache_test.go
根目录 / desktop / workspace_git_cache_test.go
1 package main
2
3 import (
4 "path/filepath"
5 "testing"
6 )
7
8 func TestWorkspaceGitCheckoutInvalidatesInFlightBranchProbe(t *testing.T) {
9 base := gitScopeRepo(t)
10 key := filepath.Clean(base)
11 request := new(int)
12 workspaceGitBranchCache.Lock()
13 workspaceGitBranchCache.entries[key] = workspaceGitBranchCacheEntry{refreshing: true, request: request}
14 workspaceGitBranchCache.Unlock()
15 started, release, done := make(chan struct{}), make(chan struct{}), make(chan struct{})
16 original := workspaceGitBranchForMetaProbe
17 workspaceGitBranchForMetaProbe = func(string) string { close(started); <-release; return "main" }
18 defer func() { workspaceGitBranchForMetaProbe = original }()
19 go func() { refreshWorkspaceGitBranchForMeta(key, base, request); close(done) }()
20 <-started
21 err := workspaceCheckoutBranch(base, "shared", false)
22 close(release)
23 <-done
24 if err != nil {
25 t.Fatal(err)
26 }
27 workspaceGitBranchCache.Lock()
28 cached, exists := workspaceGitBranchCache.entries[key]
29 workspaceGitBranchCache.Unlock()
30 if !exists || cached.branch != "shared" {
31 t.Fatal("late pre-checkout probe replaced refreshed branch metadata")
32 }
33 }
34
34 lines GO