返回 DeepSeek-Reasonix
workspace_repo_test.go
根目录 / internal / boot / workspace_repo_test.go
1 package boot
2
3 import (
4 "context"
5 "os/exec"
6 "path/filepath"
7 "testing"
8
9 "reasonix/internal/gitcmd"
10 )
11
12 // A session resolves its workspace's repository when it opens; a rebuild of
13 // the same workspace keeps that identity, and another workspace resolves its own.
14 func TestWorkspaceRepoResolvedAtOpenAndCarriedAcrossRebuilds(t *testing.T) {
15 if _, err := exec.LookPath("git"); err != nil {
16 t.Skip("git not installed")
17 }
18 root := t.TempDir()
19 if out, err := exec.Command("git", "-C", root, "init", "-q").CombinedOutput(); err != nil {
20 t.Fatalf("git init: %v: %s", err, out)
21 }
22 ctx := context.Background()
23 repo := workspaceRepo(ctx, gitcmd.Repo{}, root)
24 if !repo.Valid() {
25 t.Fatalf("workspaceRepo(%s) = %+v, want a resolved repository", root, repo)
26 }
27 carried := gitcmd.Repo{Dir: repo.Dir, GitDir: "/pinned", CommonDir: "/pinned", WorkTree: "/pinned"}
28 if got := workspaceRepo(ctx, carried, root); got != carried {
29 t.Fatalf("rebuild of the same workspace = %+v, want the identity it opened with", got)
30 }
31 other := t.TempDir()
32 if got := workspaceRepo(ctx, carried, other); got.Valid() || got.Dir != filepath.Clean(other) {
33 t.Fatalf("another workspace = %+v, want it resolved on its own (no repository)", got)
34 }
35 }
36
36 lines GO