55 "os"
66 "os/exec"
77 "path/filepath"
8+ "runtime"
89 "strings"
910 "testing"
1011 "time"
@@ -20,7 +21,11 @@ func TestMain(m *testing.M) {
2021 panic ("create temp dir: " + err .Error ())
2122 }
2223
23- binPath := filepath .Join (tmpDir , "codebase-memory-mcp" )
24+ binName := "codebase-memory-mcp"
25+ if runtime .GOOS == "windows" {
26+ binName += ".exe"
27+ }
28+ binPath := filepath .Join (tmpDir , binName )
2429 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Minute )
2530 cmd := exec .CommandContext (ctx , "go" , "build" , "-o" , binPath , "./" )
2631 cmd .Dir = "."
@@ -45,6 +50,15 @@ func testCmd(t *testing.T, args ...string) *exec.Cmd {
4550 return exec .CommandContext (ctx , testBinPath , args ... )
4651}
4752
53+ // testEnvWithHome returns env vars with HOME (and USERPROFILE on Windows) set.
54+ func testEnvWithHome (home string , extra ... string ) []string {
55+ env := append (os .Environ (), "HOME=" + home )
56+ if runtime .GOOS == "windows" {
57+ env = append (env , "USERPROFILE=" + home )
58+ }
59+ return append (env , extra ... )
60+ }
61+
4862func TestCLI_Version (t * testing.T ) {
4963 out , err := testCmd (t , "--version" ).CombinedOutput ()
5064 if err != nil {
@@ -59,7 +73,7 @@ func TestCLI_Version(t *testing.T) {
5973func TestCLI_InstallDryRun (t * testing.T ) {
6074 home := t .TempDir ()
6175 cmd := testCmd (t , "install" , "--dry-run" )
62- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + t .TempDir ())
76+ cmd .Env = testEnvWithHome ( home , "PATH=" + t .TempDir ())
6377 out , err := cmd .CombinedOutput ()
6478 if err != nil {
6579 t .Fatalf ("install --dry-run failed: %v\n %s" , err , out )
@@ -78,7 +92,7 @@ func TestCLI_InstallDryRun(t *testing.T) {
7892func TestCLI_UninstallDryRun (t * testing.T ) {
7993 home := t .TempDir ()
8094 cmd := testCmd (t , "uninstall" , "--dry-run" )
81- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + t .TempDir ())
95+ cmd .Env = testEnvWithHome ( home , "PATH=" + t .TempDir ())
8296 out , err := cmd .CombinedOutput ()
8397 if err != nil {
8498 t .Fatalf ("uninstall --dry-run failed: %v\n %s" , err , out )
@@ -116,7 +130,7 @@ func TestCLI_InstallAndUninstall(t *testing.T) {
116130
117131 // Install
118132 cmd := testCmd (t , "install" )
119- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
133+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
120134 out , err := cmd .CombinedOutput ()
121135 if err != nil {
122136 t .Fatalf ("install failed: %v\n %s" , err , out )
@@ -138,7 +152,7 @@ func TestCLI_InstallAndUninstall(t *testing.T) {
138152
139153 // Uninstall
140154 cmd = testCmd (t , "uninstall" )
141- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath )
155+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath )
142156 out , err = cmd .CombinedOutput ()
143157 if err != nil {
144158 t .Fatalf ("uninstall failed: %v\n %s" , err , out )
@@ -166,7 +180,7 @@ func TestCLI_InstallRemovesOldSkill(t *testing.T) {
166180 }
167181
168182 cmd := testCmd (t , "install" )
169- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
183+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
170184 out , err := cmd .CombinedOutput ()
171185 if err != nil {
172186 t .Fatalf ("install failed: %v\n %s" , err , out )
@@ -186,7 +200,7 @@ func TestCLI_InstallIdempotent(t *testing.T) {
186200
187201 for i := 0 ; i < 2 ; i ++ {
188202 cmd := testCmd (t , "install" )
189- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
203+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
190204 out , err := cmd .CombinedOutput ()
191205 if err != nil {
192206 t .Fatalf ("install round %d failed: %v\n %s" , i , err , out )
@@ -204,7 +218,7 @@ func TestCLI_InstallForceOverwrites(t *testing.T) {
204218 emptyPath := t .TempDir ()
205219
206220 cmd := testCmd (t , "install" )
207- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
221+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
208222 if out , err := cmd .CombinedOutput (); err != nil {
209223 t .Fatalf ("first install failed: %v\n %s" , err , out )
210224 }
@@ -215,7 +229,7 @@ func TestCLI_InstallForceOverwrites(t *testing.T) {
215229 }
216230
217231 cmd = testCmd (t , "install" )
218- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
232+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
219233 out , err := cmd .CombinedOutput ()
220234 if err != nil {
221235 t .Fatalf ("second install failed: %v\n %s" , err , out )
@@ -226,7 +240,7 @@ func TestCLI_InstallForceOverwrites(t *testing.T) {
226240 }
227241
228242 cmd = testCmd (t , "install" , "--force" )
229- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
243+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
230244 out , err = cmd .CombinedOutput ()
231245 if err != nil {
232246 t .Fatalf ("force install failed: %v\n %s" , err , out )
@@ -238,12 +252,15 @@ func TestCLI_InstallForceOverwrites(t *testing.T) {
238252}
239253
240254func TestCLI_InstallPATHAppend (t * testing.T ) {
255+ if runtime .GOOS == "windows" {
256+ t .Skip ("shell RC PATH append is Unix-specific" )
257+ }
258+
241259 home := t .TempDir ()
242- t .Setenv ("SHELL" , "/bin/zsh" )
243260 emptyPath := t .TempDir ()
244261
245262 cmd := testCmd (t , "install" )
246- cmd .Env = append ( os . Environ (), "HOME=" + home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
263+ cmd .Env = testEnvWithHome ( home , "PATH=" + emptyPath , "SHELL=/bin/zsh" )
247264 out , err := cmd .CombinedOutput ()
248265 if err != nil {
249266 t .Fatalf ("install failed: %v\n %s" , err , out )
0 commit comments