返回 DeepSeek-Reasonix
delivery_paths_test.go
根目录 / internal / config / delivery_paths_test.go
1 package config
2
3 import (
4 "path/filepath"
5 "testing"
6 )
7
8 func TestDeliveryWorktreeDirUsesLocalAppDataOnWindows(t *testing.T) {
9 setRuntimeGOOS(t, "windows")
10 t.Setenv("REASONIX_STATE_HOME", "")
11 t.Setenv("REASONIX_HOME", "")
12
13 localAppData := filepath.Join(t.TempDir(), "AppData", "Local")
14 oldCacheDir := osUserCacheDir
15 osUserCacheDir = func() string { return localAppData }
16 t.Cleanup(func() { osUserCacheDir = oldCacheDir })
17
18 want := filepath.Join(localAppData, "reasonix", "worktrees")
19 if got := DeliveryWorktreeDir(); got != want {
20 t.Fatalf("DeliveryWorktreeDir() = %q, want local durable storage %q", got, want)
21 }
22 }
23
24 func TestDeliveryWorktreeDirFallsBackToLocalAppDataUnderUserProfile(t *testing.T) {
25 setRuntimeGOOS(t, "windows")
26 t.Setenv("REASONIX_STATE_HOME", "")
27 t.Setenv("REASONIX_HOME", "")
28
29 home := t.TempDir()
30 oldCacheDir := osUserCacheDir
31 oldHomeDir := osUserHomeDir
32 osUserCacheDir = func() string { return "" }
33 osUserHomeDir = func() (string, error) { return home, nil }
34 t.Cleanup(func() {
35 osUserCacheDir = oldCacheDir
36 osUserHomeDir = oldHomeDir
37 })
38
39 want := filepath.Join(home, "AppData", "Local", "reasonix", "worktrees")
40 if got := DeliveryWorktreeDir(); got != want {
41 t.Fatalf("DeliveryWorktreeDir() = %q, want fallback %q", got, want)
42 }
43 }
44
45 func TestDeliveryWorktreeDirHonorsExplicitStateHomeOnWindows(t *testing.T) {
46 setRuntimeGOOS(t, "windows")
47 stateHome := filepath.Join(t.TempDir(), "state")
48 t.Setenv("REASONIX_STATE_HOME", stateHome)
49 t.Setenv("REASONIX_HOME", filepath.Join(t.TempDir(), "reasonix-home"))
50
51 want := filepath.Join(stateHome, "worktrees")
52 if got := DeliveryWorktreeDir(); got != want {
53 t.Fatalf("DeliveryWorktreeDir() = %q, want explicit state home %q", got, want)
54 }
55 }
56
56 lines GO