From f1d6d81c091f81e9bc9f3169f0f10c5d52a3ac08 Mon Sep 17 00:00:00 2001 From: mdrakos Date: Tue, 9 Jan 2024 15:44:17 -0800 Subject: [PATCH 1/6] Revert "Merge pull request #3005 from ActiveState/DX-2442" This reverts commit 4c8e6b37f6538164adb5f1b0a40c953fb794015d, reversing changes made to eb39e1ae68320b877c05c44ddd8e3bc7c403efac. --- internal/constants/constants.go | 6 ++ internal/osutils/exeutils.go | 4 +- internal/osutils/osutils_windows.go | 2 +- internal/testhelpers/e2e/dirs.go | 4 + internal/testhelpers/e2e/env.go | 97 ++++++++++++++++++++ internal/testhelpers/e2e/env_unix.go | 17 ++++ internal/testhelpers/e2e/env_windows.go | 46 ++++++++++ internal/testhelpers/e2e/session.go | 65 +------------ pkg/project/events.go | 11 +++ test/integration/activate_int_test.go | 6 +- test/integration/install_scripts_int_test.go | 23 ++--- test/integration/run_int_test.go | 8 +- test/integration/shell_int_test.go | 6 +- test/integration/shells_int_test.go | 7 ++ test/integration/uninstall_int_test.go | 4 +- 15 files changed, 213 insertions(+), 93 deletions(-) create mode 100644 internal/testhelpers/e2e/env.go create mode 100644 internal/testhelpers/e2e/env_unix.go create mode 100644 internal/testhelpers/e2e/env_windows.go diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 3703e14648..f998408f72 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -192,6 +192,9 @@ const SvcAuthPollingRateEnvVarName = "ACTIVESTATE_SVC_AUTH_POLLING_RATE" // log rotation timer interval (1 minute). const SvcLogRotateIntervalEnvVarName = "ACTIVESTATE_CLI_LOG_ROTATE_INTERVAL_MS" +// DisableActivateEventsEnvVarName is the environment variable used to disable events when activating or checking out a project +const DisableActivateEventsEnvVarName = "ACTIVESTATE_CLI_DISABLE_ACTIVATE_EVENTS" + // APIUpdateInfoURL is the URL for our update info server const APIUpdateInfoURL = "https://platform.activestate.com/sv/state-update/api/v1" @@ -528,3 +531,6 @@ const PlatformApiPrintRequestsEnvVarName = "ACTIVESTATE_CLI_PLATFORM_API_PRINT_R // ActiveStateCIEnvVarName is the environment variable set when running in an ActiveState CI environment. const ActiveStateCIEnvVarName = "ACTIVESTATE_CI" + +// OverrideSandbox is the environment variable to set when overriding the sandbox for integration tests. +const OverrideSandbox = "ACTIVESTATE_TEST_OVERRIDE_SANDBOX" diff --git a/internal/osutils/exeutils.go b/internal/osutils/exeutils.go index 8a334adb68..aa184fa016 100644 --- a/internal/osutils/exeutils.go +++ b/internal/osutils/exeutils.go @@ -118,10 +118,8 @@ func ExecSimpleFromDir(dir, bin string, args []string, env []string) (string, st // Execute will run the given command and with optional settings for the exec.Cmd struct func Execute(command string, arg []string, optSetter func(cmd *exec.Cmd) error) (int, *exec.Cmd, error) { - logging.Debug("Executing command: %s, %v", command, arg) - cmd := exec.Command(command, arg...) - + logging.Debug("Executing command: %s, with args: %s", cmd, arg) if optSetter != nil { if err := optSetter(cmd); err != nil { return -1, nil, err diff --git a/internal/osutils/osutils_windows.go b/internal/osutils/osutils_windows.go index 9a20be13dd..c9720bd800 100644 --- a/internal/osutils/osutils_windows.go +++ b/internal/osutils/osutils_windows.go @@ -38,7 +38,7 @@ func BashifyPathEnv(pathList string) (string, error) { cmd.Env = []string{"PATH=" + pathList} bashified, err := cmd.Output() if err != nil { - return "", errs.Wrap(err, "Unable to bashify PATH: %s", pathList) + return "", errs.Wrap(err, "Unable to bashify PATH: %s, output: %s", pathList, string(bashified)) } return string(bashified), nil } diff --git a/internal/testhelpers/e2e/dirs.go b/internal/testhelpers/e2e/dirs.go index 39961262d3..22af224c5c 100644 --- a/internal/testhelpers/e2e/dirs.go +++ b/internal/testhelpers/e2e/dirs.go @@ -23,6 +23,8 @@ type Dirs struct { SockRoot string // HomeDir is used as the test user's home directory HomeDir string + // TempDir is the directory where temporary files are stored + TempDir string } // NewDirs creates all temporary directories @@ -42,6 +44,7 @@ func NewDirs(base string) (*Dirs, error) { defaultBin := filepath.Join(base, "cache", "bin") sockRoot := filepath.Join(base, "sock") homeDir := filepath.Join(base, "home") + tempDir := filepath.Join(base, "temp") subdirs := []string{config, cache, bin, work, defaultBin} for _, subdir := range subdirs { @@ -59,6 +62,7 @@ func NewDirs(base string) (*Dirs, error) { DefaultBin: defaultBin, SockRoot: sockRoot, HomeDir: homeDir, + TempDir: tempDir, } return &dirs, nil diff --git a/internal/testhelpers/e2e/env.go b/internal/testhelpers/e2e/env.go new file mode 100644 index 0000000000..6ffc43060b --- /dev/null +++ b/internal/testhelpers/e2e/env.go @@ -0,0 +1,97 @@ +package e2e + +import ( + "fmt" + "os" + "path/filepath" + "runtime" + "testing" + + "github.com/ActiveState/cli/internal/constants" + "github.com/ActiveState/cli/internal/errs" + "github.com/ActiveState/cli/internal/fileutils" + "github.com/stretchr/testify/require" +) + +func sandboxedTestEnvironment(t *testing.T, dirs *Dirs, updatePath bool, extraEnv ...string) []string { + var env []string + basePath := platformPath() + if os.Getenv(constants.OverrideSandbox) != "" { + basePath = os.Getenv("PATH") + env = append(env, os.Environ()...) + } + if value := os.Getenv(constants.ActiveStateCIEnvVarName); value != "" { + env = append(env, fmt.Sprintf("%s=%s", constants.ActiveStateCIEnvVarName, value)) + } + + env = append(env, []string{ + constants.ConfigEnvVarName + "=" + dirs.Config, + constants.CacheEnvVarName + "=" + dirs.Cache, + constants.DisableRuntime + "=true", + constants.ProjectEnvVarName + "=", + constants.E2ETestEnvVarName + "=true", + constants.DisableUpdates + "=true", + constants.DisableProjectMigrationPrompt + "=true", + constants.OptinUnstableEnvVarName + "=true", + constants.ServiceSockDir + "=" + dirs.SockRoot, + constants.HomeEnvVarName + "=" + dirs.HomeDir, + systemHomeEnvVarName + "=" + dirs.HomeDir, + constants.DisableActivateEventsEnvVarName + "=true", + "NO_COLOR=true", + "CI=true", + }...) + + if updatePath { + // add bin path + oldPath := basePath + newPath := fmt.Sprintf( + "PATH=%s%s%s", + dirs.Bin, string(os.PathListSeparator), oldPath, + ) + env = append(env, newPath) + } else { + env = append(env, "PATH="+basePath) + } + + // append platform specific environment variables + env = append(env, platformSpecificEnv(dirs)...) + + // Prepare sandboxed home directory + err := prepareHomeDir(dirs.HomeDir) + require.NoError(t, err) + + // add session environment variables + env = append(env, extraEnv...) + + return env +} + +func prepareHomeDir(dir string) error { + if runtime.GOOS == "windows" { + return nil + } + + if !fileutils.DirExists(dir) { + err := fileutils.Mkdir(dir) + if err != nil { + return errs.Wrap(err, "Could not create home dir") + } + } + + var filename string + switch runtime.GOOS { + case "linux": + filename = ".bashrc" + case "darwin": + filename = ".zshrc" + } + + rcFile := filepath.Join(dir, filename) + err := fileutils.Touch(rcFile) + if err != nil { + return errs.Wrap(err, "Could not create rc file") + } + + return nil + +} diff --git a/internal/testhelpers/e2e/env_unix.go b/internal/testhelpers/e2e/env_unix.go new file mode 100644 index 0000000000..e92aaf2653 --- /dev/null +++ b/internal/testhelpers/e2e/env_unix.go @@ -0,0 +1,17 @@ +//go:build !windows +// +build !windows + +package e2e + +const ( + basePath = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local:/usr/local/sbin:/usr/local/opt" + systemHomeEnvVarName = "HOME" +) + +func platformSpecificEnv(dirs *Dirs) []string { + return nil +} + +func platformPath() string { + return basePath +} diff --git a/internal/testhelpers/e2e/env_windows.go b/internal/testhelpers/e2e/env_windows.go new file mode 100644 index 0000000000..b16f5b3b50 --- /dev/null +++ b/internal/testhelpers/e2e/env_windows.go @@ -0,0 +1,46 @@ +//go:build windows +// +build windows + +package e2e + +import ( + "fmt" + "os" + + "github.com/ActiveState/cli/internal/condition" +) + +const ( + basePath = `C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\PowerShell\7\;` + systemHomeEnvVarName = "USERPROFILE" +) + +func platformSpecificEnv(dirs *Dirs) []string { + return []string{ + "SystemDrive=C:", + "SystemRoot=C:\\Windows", + "PROGRAMFILES=C:\\Program Files", + "ProgramFiles(x86)=C:\\Program Files (x86)", + "PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC", + "HOMEDRIVE=C:", + "ALLUSERSPROFILE=C:\\ProgramData", + "ProgramData=C:\\ProgramData", + "COMSPEC=C:\\Windows\\System32\\cmd.exe", + "PROGRAMFILES=C:\\Program Files", + "CommonProgramW6432=C:\\Program Files\\Common Files", + "WINDIR=C:\\Windows", + "PUBLIC=C:\\Users\\Public", + "PSModuleAnalysisCachePath=C:\\PSModuleAnalysisCachePath\\ModuleAnalysisCache", + fmt.Sprintf("HOMEPATH=%s", dirs.HomeDir), + // Other environment variables are commonly set by CI systems, but this one is not. + // This is requried for some tests in order to get the correct powershell output. + fmt.Sprintf("PSModulePath=%s", os.Getenv("PSModulePath")), + } +} + +func platformPath() string { + if condition.OnCI() { + return `C:\msys64\usr\bin` + string(os.PathListSeparator) + basePath + } + return basePath +} diff --git a/internal/testhelpers/e2e/session.go b/internal/testhelpers/e2e/session.go index 7745419de1..70fa40ecc0 100644 --- a/internal/testhelpers/e2e/session.go +++ b/internal/testhelpers/e2e/session.go @@ -172,57 +172,7 @@ func New(t *testing.T, retainDirs bool, extraEnv ...string) *Session { func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session { dirs, err := NewDirs("") require.NoError(t, err) - var env []string - env = append(env, os.Environ()...) - env = append(env, []string{ - constants.ConfigEnvVarName + "=" + dirs.Config, - constants.CacheEnvVarName + "=" + dirs.Cache, - constants.DisableRuntime + "=true", - constants.ProjectEnvVarName + "=", - constants.E2ETestEnvVarName + "=true", - constants.DisableUpdates + "=true", - constants.DisableProjectMigrationPrompt + "=true", - constants.OptinUnstableEnvVarName + "=true", - constants.ServiceSockDir + "=" + dirs.SockRoot, - constants.HomeEnvVarName + "=" + dirs.HomeDir, - "NO_COLOR=true", - }...) - - if updatePath { - // add bin path - // Remove release state tool installation from PATH in tests - // This is a workaround as our test sessions are not compeltely - // sandboxed. This should be addressed in: https://activestatef.atlassian.net/browse/DX-2285 - oldPath, _ := os.LookupEnv("PATH") - installPath, err := installation.InstallPathForChannel("release") - require.NoError(t, err) - - binPath := filepath.Join(installPath, "bin") - oldPath = strings.Replace(oldPath, binPath+string(os.PathListSeparator), "", -1) - newPath := fmt.Sprintf( - "PATH=%s%s%s", - dirs.Bin, string(os.PathListSeparator), oldPath, - ) - env = append(env, newPath) - t.Setenv("PATH", newPath) - - cfg, err := config.New() - require.NoError(t, err) - - // In order to ensure that the release state tool does not appear on the PATH - // when a new subshell is started we remove the installation entries from the - // rc file. This is added back later in the session's Close method. - // Again, this is a workaround to be addressed in: https://activestatef.atlassian.net/browse/DX-2285 - if runtime.GOOS != "windows" { - s := bash.SubShell{} - err = s.CleanUserEnv(cfg, sscommon.InstallID, false) - require.NoError(t, err) - } - t.Setenv(constants.HomeEnvVarName, dirs.HomeDir) - } - - // add session environment variables - env = append(env, extraEnv...) + env := sandboxedTestEnvironment(t, dirs, updatePath, extraEnv...) session := &Session{Dirs: dirs, Env: env, retainDirs: retainDirs, T: t} @@ -232,14 +182,6 @@ func new(t *testing.T, retainDirs, updatePath bool, extraEnv ...string) *Session session.SvcExe = session.copyExeToBinDir(svcExe) session.ExecutorExe = session.copyExeToBinDir(execExe) - // Set up environment for test runs. This is separate - // from the environment for the session itself. - // Setting environment variables here allows helper - // functions access to them. - // This is a workaround as our test sessions are not compeltely - // sandboxed. This should be addressed in: https://activestatef.atlassian.net/browse/DX-2285 - t.Setenv(constants.HomeEnvVarName, dirs.HomeDir) - err = fileutils.Touch(filepath.Join(dirs.Base, installation.InstallDirMarker)) require.NoError(session.T, err) @@ -353,7 +295,6 @@ func (s *Session) SpawnCmdWithOpts(exe string, optSetters ...SpawnOptSetter) *Sp cmd := exec.Command(shell, args...) cmd.Env = spawnOpts.Env - if spawnOpts.Dir != "" { cmd.Dir = spawnOpts.Dir } @@ -771,6 +712,8 @@ func (s *Session) SetupRCFile() { if runtime.GOOS == "windows" { return } + s.T.Setenv("HOME", s.Dirs.HomeDir) + defer s.T.Setenv("HOME", os.Getenv("HOME")) cfg, err := config.New() require.NoError(s.T, err) @@ -789,7 +732,7 @@ func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) { if fileutils.TargetExists(filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile))) { err = fileutils.CopyFile(rcFile, filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile))) } else { - err = fileutils.Touch(rcFile) + err = fileutils.Touch(filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile))) } require.NoError(s.T, err) } diff --git a/pkg/project/events.go b/pkg/project/events.go index dfd7cab21b..8957fdaceb 100644 --- a/pkg/project/events.go +++ b/pkg/project/events.go @@ -1,5 +1,12 @@ package project +import ( + "os" + "strings" + + "github.com/ActiveState/cli/internal/constants" +) + type EventType string const ( @@ -14,6 +21,10 @@ func (e EventType) String() string { } func ActivateEvents() []EventType { + if strings.EqualFold(os.Getenv(constants.DisableActivateEventsEnvVarName), "true") { + return []EventType{} + } + return []EventType{ Activate, FirstActivate, diff --git a/test/integration/activate_int_test.go b/test/integration/activate_int_test.go index 1f46f67624..1ad1ba898c 100644 --- a/test/integration/activate_int_test.go +++ b/test/integration/activate_int_test.go @@ -134,10 +134,10 @@ func (suite *ActivateIntegrationTestSuite) TestActivateUsingCommitID() { cp := ts.SpawnWithOpts( e2e.OptArgs("activate", "ActiveState-CLI/Python3#6d9280e7-75eb-401a-9e71-0d99759fbad3", "--path", ts.Dirs.Work), + e2e.OptAppendEnv(constants.DisableRuntime+"=false"), ) - cp.Expect("Skipping runtime setup") - cp.Expect("Activated") - cp.ExpectInput(termtest.OptExpectTimeout(10 * time.Second)) + cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt) + cp.ExpectInput() cp.SendLine("exit") cp.ExpectExitCode(0) diff --git a/test/integration/install_scripts_int_test.go b/test/integration/install_scripts_int_test.go index 323542d565..4f5eb95b95 100644 --- a/test/integration/install_scripts_int_test.go +++ b/test/integration/install_scripts_int_test.go @@ -66,7 +66,9 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() { suite.Require().NoError(fileutils.WriteFile(script, b)) // Construct installer command to execute. + installDir := filepath.Join(ts.Dirs.Work, "install") argsPlain := []string{script} + argsPlain = append(argsPlain, "-t", installDir) if tt.Channel != "" { argsPlain = append(argsPlain, "-b", tt.Channel) } @@ -97,6 +99,7 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() { e2e.OptAppendEnv(constants.DisableRuntime + "=false"), e2e.OptAppendEnv(fmt.Sprintf("%s=%s", constants.AppInstallDirOverrideEnvVarName, appInstallDir)), e2e.OptAppendEnv(fmt.Sprintf("%s=FOO", constants.OverrideSessionTokenEnvVarName)), + e2e.OptAppendEnv(fmt.Sprintf("%s=false", constants.DisableActivateEventsEnvVarName)), } if runtime.GOOS == "windows" { cmd = "powershell.exe" @@ -116,20 +119,6 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() { cp.Expect("ActiveState") } - // We get the default install path and use that to directly invoke - // the state tool. This is to avoid inadvertently using the state - // tool that is already on the PATH. - installPath, err := installation.InstallPathForChannel(constants.ChannelName) - suite.NoError(err) - - binPath := filepath.Join(installPath, "bin") - - if runtime.GOOS != "windows" { - cp.SendLine("echo $PATH") - } else { - cp.SendLine("echo %PATH%") - } - cp.Expect(installPath) cp.SendLine("state --version") cp.Expect("Version " + constants.Version) cp.Expect("Channel " + constants.ChannelName) @@ -138,12 +127,12 @@ func (suite *InstallScriptsIntegrationTestSuite) TestInstall() { cp.ExpectExitCode(0) - stateExec, err := installation.StateExecFromDir(ts.Dirs.HomeDir) + stateExec, err := installation.StateExecFromDir(installDir) suite.NoError(err) suite.FileExists(stateExec) - suite.assertBinDirContents(binPath) - suite.assertCorrectVersion(ts, binPath, tt.Version, tt.Channel) + suite.assertBinDirContents(filepath.Join(installDir, "bin")) + suite.assertCorrectVersion(ts, installDir, tt.Version, tt.Channel) suite.assertAnalytics(ts) suite.DirExists(ts.Dirs.Config) diff --git a/test/integration/run_int_test.go b/test/integration/run_int_test.go index 1f14495762..5e36823660 100644 --- a/test/integration/run_int_test.go +++ b/test/integration/run_int_test.go @@ -232,9 +232,11 @@ func (suite *RunIntegrationTestSuite) TestRun_Unauthenticated() { suite.createProjectFile(ts, 2) - cp := ts.SpawnWithOpts(e2e.OptArgs("activate")) - cp.Expect("Skipping runtime setup") - cp.Expect("Activated") + cp := ts.SpawnWithOpts( + e2e.OptArgs("activate"), + e2e.OptAppendEnv(constants.DisableRuntime+"=false"), + ) + cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt) cp.ExpectInput(termtest.OptExpectTimeout(10 * time.Second)) cp.SendLine(fmt.Sprintf("%s run testMultipleLanguages", cp.Executable())) diff --git a/test/integration/shell_int_test.go b/test/integration/shell_int_test.go index 27fd736263..6db8ebcb92 100644 --- a/test/integration/shell_int_test.go +++ b/test/integration/shell_int_test.go @@ -32,16 +32,18 @@ func (suite *ShellIntegrationTestSuite) TestShell() { cp := ts.SpawnWithOpts( e2e.OptArgs("checkout", "ActiveState-CLI/small-python"), + e2e.OptAppendEnv(constants.DisableRuntime+"=false"), ) - cp.Expect("Checked out project") + cp.Expect("Checked out project", e2e.RuntimeSourcingTimeoutOpt) cp.ExpectExitCode(0) args := []string{"small-python", "ActiveState-CLI/small-python"} for _, arg := range args { cp := ts.SpawnWithOpts( e2e.OptArgs("shell", arg), + e2e.OptAppendEnv(constants.DisableRuntime+"=false"), ) - cp.Expect("Activated") + cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt) cp.ExpectInput() cp.SendLine("python3 --version") diff --git a/test/integration/shells_int_test.go b/test/integration/shells_int_test.go index 06d1c5a81d..f911d813b0 100644 --- a/test/integration/shells_int_test.go +++ b/test/integration/shells_int_test.go @@ -2,12 +2,14 @@ package integration import ( "fmt" + "path/filepath" "runtime" "testing" "github.com/stretchr/testify/suite" "github.com/ActiveState/cli/internal/constants" + "github.com/ActiveState/cli/internal/fileutils" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" ) @@ -44,6 +46,11 @@ func (suite *ShellsIntegrationTestSuite) TestShells() { suite.T().Run(fmt.Sprintf("using_%s", shell), func(t *testing.T) { ts.SetT(t) + if shell == e2e.Zsh { + err := fileutils.Touch(filepath.Join(ts.Dirs.HomeDir, ".zshrc")) + suite.Require().NoError(err) + } + // Run the checkout in a particular shell. cp = ts.SpawnShellWithOpts(shell) cp.SendLine(e2e.QuoteCommand(shell, ts.ExecutablePath(), "checkout", "ActiveState-CLI/small-python", string(shell))) diff --git a/test/integration/uninstall_int_test.go b/test/integration/uninstall_int_test.go index 6f94c0ae2d..ae59a272e0 100644 --- a/test/integration/uninstall_int_test.go +++ b/test/integration/uninstall_int_test.go @@ -78,9 +78,7 @@ func (suite *UninstallIntegrationTestSuite) testUninstall(all bool) { if runtime.GOOS == "linux" { // When installed in a non-desktop environment (i.e. on a server), verify the user's ~/.profile was changed. - homeDir, err := user.HomeDir() - suite.Require().NoError(err) - profile := filepath.Join(homeDir, ".profile") + profile := filepath.Join(ts.Dirs.HomeDir, ".profile") suite.Contains(string(fileutils.ReadFileUnsafe(profile)), svcExe, "autostart should be configured for Linux server environment") } From 42866f06610c8cb953ae03bfd72ba81ab4407f1f Mon Sep 17 00:00:00 2001 From: mdrakos Date: Wed, 10 Jan 2024 10:08:37 -0800 Subject: [PATCH 2/6] Add events env var to failing tests --- test/integration/analytics_int_test.go | 1 + test/integration/condition_int_test.go | 2 ++ test/integration/events_int_test.go | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/test/integration/analytics_int_test.go b/test/integration/analytics_int_test.go index 9cf00bf195..9b6f5958a5 100644 --- a/test/integration/analytics_int_test.go +++ b/test/integration/analytics_int_test.go @@ -523,6 +523,7 @@ func (suite *AnalyticsIntegrationTestSuite) TestAttempts() { cp := ts.SpawnWithOpts( e2e.OptArgs("activate", "ActiveState-CLI/Alternate-Python"), e2e.OptAppendEnv(constants.DisableRuntime+"=false"), + e2e.OptAppendEnv(constants.DisableActivateEventsEnvVarName+"=false"), e2e.OptWD(ts.Dirs.Work), ) diff --git a/test/integration/condition_int_test.go b/test/integration/condition_int_test.go index 96115e083f..172cfdb9d0 100644 --- a/test/integration/condition_int_test.go +++ b/test/integration/condition_int_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/suite" + "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" ) @@ -36,6 +37,7 @@ func (suite *ConditionIntegrationTestSuite) TestCondition() { cp = ts.SpawnWithOpts( e2e.OptArgs("activate"), + e2e.OptAppendEnv(constants.DisableActivateEventsEnvVarName+"=false"), ) cp.Expect(`Activation Event Ran`) cp.ExpectInput() diff --git a/test/integration/events_int_test.go b/test/integration/events_int_test.go index febab9708a..f1f8567278 100644 --- a/test/integration/events_int_test.go +++ b/test/integration/events_int_test.go @@ -6,6 +6,7 @@ import ( "github.com/stretchr/testify/suite" + "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" ) @@ -44,7 +45,10 @@ events: `)) ts.PrepareCommitIdFile("fbc613d6-b0b1-4f84-b26e-4aa5869c4e54") - cp := ts.Spawn("activate") + cp := ts.SpawnWithOpts( + e2e.OptArgs("activate"), + e2e.OptAppendEnv(constants.DisableActivateEventsEnvVarName+"=false"), + ) cp.SendEnter() cp.Expect("before-script") cp.Expect("First activate event") @@ -54,7 +58,10 @@ events: cp.Expect("after-script") cp.ExpectExitCode(0) - cp = ts.Spawn("activate") + cp = ts.SpawnWithOpts( + e2e.OptArgs("activate"), + e2e.OptAppendEnv(constants.DisableActivateEventsEnvVarName+"=false"), + ) cp.Expect("Activate event") cp.ExpectInput() cp.SendLine("exit") From 3a70dc2fb8e23a69ef4f80768f393c3ffb969f26 Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Wed, 10 Jan 2024 12:19:18 -0800 Subject: [PATCH 3/6] Debug ole error --- internal/osutils/shortcut/shortcut_windows.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/osutils/shortcut/shortcut_windows.go b/internal/osutils/shortcut/shortcut_windows.go index 249c472f80..73bf62290f 100644 --- a/internal/osutils/shortcut/shortcut_windows.go +++ b/internal/osutils/shortcut/shortcut_windows.go @@ -68,6 +68,7 @@ func (s *Shortcut) Enable() error { if err != nil { oleErr := &ole.OleError{} if errors.As(err, &oleErr) { + logging.Debug("OLE Error details: %s\n%s\n%s\n%s\n%s", oleErr.Code(), oleErr.Description(), oleErr.Error(), oleErr.String(), oleErr.SubError()) return errs.Wrap(err, "oleutil CreateShortcut returned error: %s", oleErr.String()) } return errs.Wrap(err, "Could not call CreateShortcut on shell object") From 479983efce93fdc814d90965c3f468ec69c8a3dc Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Wed, 10 Jan 2024 12:22:10 -0800 Subject: [PATCH 4/6] Fix edit int test --- internal/testhelpers/e2e/dirs.go | 2 +- internal/testhelpers/e2e/env.go | 22 +++++++++++++++++++++- internal/testhelpers/e2e/env_windows.go | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/internal/testhelpers/e2e/dirs.go b/internal/testhelpers/e2e/dirs.go index 22af224c5c..82114fab7a 100644 --- a/internal/testhelpers/e2e/dirs.go +++ b/internal/testhelpers/e2e/dirs.go @@ -46,7 +46,7 @@ func NewDirs(base string) (*Dirs, error) { homeDir := filepath.Join(base, "home") tempDir := filepath.Join(base, "temp") - subdirs := []string{config, cache, bin, work, defaultBin} + subdirs := []string{config, cache, bin, work, defaultBin, sockRoot, homeDir, tempDir} for _, subdir := range subdirs { if err := os.MkdirAll(subdir, 0700); err != nil { return nil, err diff --git a/internal/testhelpers/e2e/env.go b/internal/testhelpers/e2e/env.go index 6ffc43060b..09324d3036 100644 --- a/internal/testhelpers/e2e/env.go +++ b/internal/testhelpers/e2e/env.go @@ -3,8 +3,10 @@ package e2e import ( "fmt" "os" + "os/exec" "path/filepath" "runtime" + "strings" "testing" "github.com/ActiveState/cli/internal/constants" @@ -24,6 +26,10 @@ func sandboxedTestEnvironment(t *testing.T, dirs *Dirs, updatePath bool, extraEn env = append(env, fmt.Sprintf("%s=%s", constants.ActiveStateCIEnvVarName, value)) } + // add go binary to PATH + goBinary := goBinaryPath(t) + basePath = fmt.Sprintf("%s%s%s", basePath, string(os.PathListSeparator), filepath.Dir(goBinary)) + env = append(env, []string{ constants.ConfigEnvVarName + "=" + dirs.Config, constants.CacheEnvVarName + "=" + dirs.Cache, @@ -36,7 +42,6 @@ func sandboxedTestEnvironment(t *testing.T, dirs *Dirs, updatePath bool, extraEn constants.ServiceSockDir + "=" + dirs.SockRoot, constants.HomeEnvVarName + "=" + dirs.HomeDir, systemHomeEnvVarName + "=" + dirs.HomeDir, - constants.DisableActivateEventsEnvVarName + "=true", "NO_COLOR=true", "CI=true", }...) @@ -93,5 +98,20 @@ func prepareHomeDir(dir string) error { } return nil +} +func goBinaryPath(t *testing.T) string { + locator := "which" + if runtime.GOOS == "windows" { + locator = "where" + } + cmd := exec.Command(locator, "go") + output, err := cmd.Output() + if err != nil { + t.Log("Could not find go binary") + return "" + } + goBinary := string(output) + goBinary = strings.TrimSpace(string(goBinary)) + return goBinary } diff --git a/internal/testhelpers/e2e/env_windows.go b/internal/testhelpers/e2e/env_windows.go index b16f5b3b50..2f7d8c93a1 100644 --- a/internal/testhelpers/e2e/env_windows.go +++ b/internal/testhelpers/e2e/env_windows.go @@ -35,6 +35,7 @@ func platformSpecificEnv(dirs *Dirs) []string { // Other environment variables are commonly set by CI systems, but this one is not. // This is requried for some tests in order to get the correct powershell output. fmt.Sprintf("PSModulePath=%s", os.Getenv("PSModulePath")), + fmt.Sprintf("LOCALAPPDATA=%s", dirs.TempDir), } } From 3b4c263626ffe2001f684aeb0c26b54de777c586 Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Wed, 10 Jan 2024 13:47:20 -0800 Subject: [PATCH 5/6] Disable events on Windows by default --- internal/testhelpers/e2e/env_windows.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/testhelpers/e2e/env_windows.go b/internal/testhelpers/e2e/env_windows.go index 2f7d8c93a1..8e3149405f 100644 --- a/internal/testhelpers/e2e/env_windows.go +++ b/internal/testhelpers/e2e/env_windows.go @@ -8,6 +8,7 @@ import ( "os" "github.com/ActiveState/cli/internal/condition" + "github.com/ActiveState/cli/internal/constants" ) const ( @@ -36,6 +37,7 @@ func platformSpecificEnv(dirs *Dirs) []string { // This is requried for some tests in order to get the correct powershell output. fmt.Sprintf("PSModulePath=%s", os.Getenv("PSModulePath")), fmt.Sprintf("LOCALAPPDATA=%s", dirs.TempDir), + fmt.Sprintf("%s=false", constants.DisableActivateEventsEnvVarName), } } From f8a9920b98d292003dff2c318689a2f391370af5 Mon Sep 17 00:00:00 2001 From: Mike Drakos Date: Wed, 10 Jan 2024 14:49:08 -0800 Subject: [PATCH 6/6] Actually disable events on Windows --- internal/testhelpers/e2e/env_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/testhelpers/e2e/env_windows.go b/internal/testhelpers/e2e/env_windows.go index 8e3149405f..0c7b72aeec 100644 --- a/internal/testhelpers/e2e/env_windows.go +++ b/internal/testhelpers/e2e/env_windows.go @@ -37,7 +37,7 @@ func platformSpecificEnv(dirs *Dirs) []string { // This is requried for some tests in order to get the correct powershell output. fmt.Sprintf("PSModulePath=%s", os.Getenv("PSModulePath")), fmt.Sprintf("LOCALAPPDATA=%s", dirs.TempDir), - fmt.Sprintf("%s=false", constants.DisableActivateEventsEnvVarName), + fmt.Sprintf("%s=true", constants.DisableActivateEventsEnvVarName), } }