@@ -47,12 +47,23 @@ func requireNPM(t *testing.T) {
4747 }
4848}
4949
50- func TestUpdateNPMLocalInstall (t * testing.T ) {
50+ func TestUpdateNPMInstall (t * testing.T ) {
5151 requireNPM (t )
5252
53+ // Skip if lstk already exists at npm's global bin path (e.g., installed
54+ // via Homebrew into the same prefix). npm install -g would fail with
55+ // EEXIST when it tries to create a symlink over the existing binary.
56+ npmBinOut , err := exec .Command ("npm" , "bin" , "-g" ).Output ()
57+ if err == nil {
58+ globalBin := filepath .Join (strings .TrimSpace (string (npmBinOut )), "lstk" )
59+ if _ , err := os .Stat (globalBin ); err == nil {
60+ t .Skipf ("lstk already exists at npm global bin path %s, would conflict with npm install -g" , globalBin )
61+ }
62+ }
63+
5364 ctx := testContext (t )
5465
55- // Set up a fake local npm project.
66+ // Set up a fake local npm project so we get a binary inside node_modules .
5667 // On Windows, t.TempDir() may return a short 8.3 path (e.g. RUNNER~1)
5768 // while the program resolves the long path. EvalSymlinks normalizes both.
5869 projectDir , err := filepath .EvalSymlinks (t .TempDir ())
@@ -93,16 +104,16 @@ func TestUpdateNPMLocalInstall(t *testing.T) {
93104 out , err = buildCmd .CombinedOutput ()
94105 require .NoError (t , err , "go build failed: %s" , string (out ))
95106
96- // Run the binary directly (not through npx) so os.Executable() resolves to the node_modules path
107+ // Run the binary directly (not through npx) so os.Executable() resolves to the node_modules path.
108+ // The update should always use `npm install -g` regardless of local/global context.
97109 cmd := exec .CommandContext (ctx , nmBinaryPath , "update" , "--non-interactive" )
98110 cmd .Dir = projectDir
99111 stdout , err := cmd .CombinedOutput ()
100112 stdoutStr := string (stdout )
101113
102114 require .NoError (t , err , "lstk update failed: %s" , stdoutStr )
103115 requireExitCode (t , 0 , err )
104- assert .Contains (t , stdoutStr , "npm (local)" , "should detect local npm install" )
105- assert .Contains (t , stdoutStr , projectDir , "should show the project directory" )
116+ assert .Contains (t , stdoutStr , "npm install -g" , "should always use global install" )
106117 assert .Contains (t , stdoutStr , "Updated to" , "should complete the update" )
107118}
108119
0 commit comments