返回 DeepSeek-Reasonix
single_instance_test.go
根目录 / desktop / single_instance_test.go
1 package main
2
3 import (
4 "os"
5 "path/filepath"
6 "testing"
7 )
8
9 func TestSingleInstanceIDScopesToReasonixHome(t *testing.T) {
10 first := filepath.Join(t.TempDir(), "first")
11 second := filepath.Join(t.TempDir(), "second")
12 t.Setenv("REASONIX_HOME", first)
13 firstID := singleInstanceID()
14 t.Setenv("REASONIX_HOME", filepath.Join(first, "."))
15 if got := singleInstanceID(); got != firstID {
16 t.Fatalf("same data home produced different ids: %q != %q", got, firstID)
17 }
18 t.Setenv("REASONIX_HOME", second)
19 if got := singleInstanceID(); got == firstID {
20 t.Fatalf("different data homes produced the same id %q", got)
21 }
22 }
23
24 func TestSingleInstanceIDDoesNotSplitReleaseChannels(t *testing.T) {
25 t.Setenv("REASONIX_HOME", t.TempDir())
26 oldChannel := channel
27 t.Cleanup(func() { channel = oldChannel })
28 channel = "stable"
29 stableID := singleInstanceID()
30 channel = "canary"
31 if got := singleInstanceID(); got != stableID {
32 t.Fatalf("same data home split by channel: stable=%q canary=%q", stableID, got)
33 }
34 }
35
36 func TestSingleInstanceIDResolvesMissingHomeThroughSymlink(t *testing.T) {
37 root := t.TempDir()
38 realParent := filepath.Join(root, "real")
39 if err := os.MkdirAll(realParent, 0o755); err != nil {
40 t.Fatal(err)
41 }
42 aliasParent := filepath.Join(root, "alias")
43 if err := os.Symlink(realParent, aliasParent); err != nil {
44 t.Skipf("symlink unavailable: %v", err)
45 }
46 t.Setenv("REASONIX_HOME", filepath.Join(realParent, "not-created", "home"))
47 realID := singleInstanceID()
48 t.Setenv("REASONIX_HOME", filepath.Join(aliasParent, "not-created", "home"))
49 if got := singleInstanceID(); got != realID {
50 t.Fatalf("aliased missing data home produced different ids: %q != %q", got, realID)
51 }
52 }
53
53 lines GO