返回 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 "reasonix/internal/gitcmd"
8 )
9
10 func TestWorkspaceGitCheckoutInvalidatesInFlightBranchProbe(t *testing.T) {
11 base := gitScopeRepo(t)
12 key := filepath.Clean(base)
13 request := new(int)
14 workspaceGitBranchCache.Lock()
15 workspaceGitBranchCache.entries[key] = workspaceGitBranchCacheEntry{refreshing: true, request: request}
16 workspaceGitBranchCache.Unlock()
17 started, release, done := make(chan struct{}), make(chan struct{}), make(chan struct{})
18 original := workspaceGitBranchForMetaProbe
19 workspaceGitBranchForMetaProbe = func(gitcmd.Repo) string { close(started); <-release; return "main" }
20 defer func() { workspaceGitBranchForMetaProbe = original }()
21 repo := openWorkspaceRepo(base)
22 go func() { refreshWorkspaceGitBranchForMeta(key, base, repo, request); close(done) }()
23 <-started
24 err := workspaceCheckoutBranch(repo, "shared", false)
25 close(release)
26 <-done
27 if err != nil {
28 t.Fatal(err)
29 }
30 workspaceGitBranchCache.Lock()
31 cached, exists := workspaceGitBranchCache.entries[key]
32 workspaceGitBranchCache.Unlock()
33 if !exists || cached.branch != "shared" {
34 t.Fatal("late pre-checkout probe replaced refreshed branch metadata")
35 }
36 }
37
37 lines GO