Skip to content

Commit

Permalink
Revert: Update shell rcfiles to indicate the user is already in an ac…
Browse files Browse the repository at this point in the history
…tivated state.
  • Loading branch information
mitchell-as committed Oct 3, 2023
1 parent 7b0308d commit abc89d0
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 98 deletions.
3 changes: 0 additions & 3 deletions internal/assets/contents/shells/bashrc_append.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ export {{$K}}="{{$V}}:$PATH"
export {{$K}}="{{$V}}"
{{- end}}
{{- end}}
if [[ ! -z "${{.ActivatedEnv}}" && -f "${{.ActivatedEnv}}/{{.ConfigFile}}" ]]; then
echo "State Tool is operating on project ${{.ActivatedNamespaceEnv}}, located at ${{.ActivatedEnv}}"
fi
# {{.Stop}}
5 changes: 1 addition & 4 deletions internal/assets/contents/shells/fishrc_append.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ set -xg {{$K}} "{{$V}}:$PATH"
set -xg {{$K}} "{{$V}}"
{{- end}}
{{- end}}
if test ! -z "${{.ActivatedEnv}}"; test -f "${{.ActivatedEnv}}/{{.ConfigFile}}"
echo "State Tool is operating on project ${{.ActivatedNamespaceEnv}}, located at ${{.ActivatedEnv}}"
end
# {{.Stop}}
# {{.Stop}}
3 changes: 0 additions & 3 deletions internal/assets/contents/shells/tcshrc_append.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@ setenv {{$K}} "{{$V}}:$PATH"
{{- else}}
{{- end}}
{{- end}}
if ( "${{.ActivatedEnv}}" != "" && -f "${{.ActivatedEnv}}/{{.ConfigFile}}" ) then
echo "State Tool is operating on project ${{.ActivatedNamespaceEnv}}, located at ${{.ActivatedEnv}}"
endif
# {{.Stop}}
3 changes: 0 additions & 3 deletions internal/assets/contents/shells/zshrc_append.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ export {{$K}}="{{$V}}:$PATH"
export {{$K}}="{{$V}}"
{{- end}}
{{- end}}
if [[ ! -z "${{.ActivatedEnv}}" && -f "${{.ActivatedEnv}}/{{.ConfigFile}}" ]]; then
echo "State Tool is operating on project ${{.ActivatedNamespaceEnv}}, located at ${{.ActivatedEnv}}"
fi
# {{.Stop}}
3 changes: 0 additions & 3 deletions internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ const ActivatedStateEnvVarName = "ACTIVESTATE_ACTIVATED"
// ActivatedStateIDEnvVarName is the name of the environment variable that is set when in an activated state, its value will be a unique id identifying a specific instance of an activated state
const ActivatedStateIDEnvVarName = "ACTIVESTATE_ACTIVATED_ID"

// ActivatedStateProjectEnvVarName is the name of the environment variable that specifies the activated state's org/project namespace.
const ActivatedStateNamespaceEnvVarName = "ACTIVESTATE_ACTIVATED_NAMESPACE"

// ForwardedStateEnvVarName is the name of the environment variable that is set when in an activated state, its value will be the path of the project
const ForwardedStateEnvVarName = "ACTIVESTATE_FORWARDED"

Expand Down
2 changes: 1 addition & 1 deletion internal/runbits/activation/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func ActivateAndWait(
}
}

ve, err := venv.GetEnv(false, true, projectDir, proj.Namespace().String())
ve, err := venv.GetEnv(false, true, projectDir)
if err != nil {
return locale.WrapError(err, "error_could_not_activate_venv", "Could not retrieve environment information.")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/runners/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (s *Exec) Run(params *Params, args ...string) (rerr error) {
}
venv := virtualenvironment.New(rt)

env, err := venv.GetEnv(true, false, projectDir, projectNamespace)
env, err := venv.GetEnv(true, false, projectDir)
if err != nil {
return locale.WrapError(err, "err_exec_env", "Could not retrieve environment information for your runtime")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/scriptrun/scriptrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *ScriptRun) PrepareVirtualEnv() (rerr error) {
venv := virtualenvironment.New(rt)

projDir := filepath.Dir(s.project.Source().Path())
env, err := venv.GetEnv(true, true, projDir, s.project.Namespace().String())
env, err := venv.GetEnv(true, true, projDir)
if err != nil {
return errs.Wrap(err, "Could not get venv environment")
}
Expand All @@ -95,7 +95,7 @@ func (s *ScriptRun) PrepareVirtualEnv() (rerr error) {
}

// search the "clean" path first (PATHS that are set by venv)
env, err = venv.GetEnv(false, true, "", "")
env, err = venv.GetEnv(false, true, "")
if err != nil {
return errs.Wrap(err, "Could not get venv environment")
}
Expand Down
9 changes: 3 additions & 6 deletions internal/subshell/sscommon/rcfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,9 @@ func WriteRcFile(rcTemplateName string, path string, data RcIdentification, env
}

rcData := map[string]interface{}{
"Start": data.Start,
"Stop": data.Stop,
"Env": env,
"ActivatedEnv": constants.ActivatedStateEnvVarName,
"ConfigFile": constants.ConfigFileName,
"ActivatedNamespaceEnv": constants.ActivatedStateNamespaceEnvVarName,
"Start": data.Start,
"Stop": data.Stop,
"Env": env,
}

if err := CleanRcFile(path, data); err != nil {
Expand Down
22 changes: 3 additions & 19 deletions internal/subshell/sscommon/rcfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sscommon
import (
"fmt"
"reflect"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -44,25 +43,10 @@ func TestWriteRcFile(t *testing.T) {
path string
env map[string]string
}

fish := fmt.Sprintf(
`set -xg PATH "foo:$PATH"
if test ! -z "$%s"; test -f "$%s/%s"
echo "State Tool is operating on project $%s, located at $%s"
end`,
constants.ActivatedStateEnvVarName,
constants.ActivatedStateEnvVarName,
constants.ConfigFileName,
constants.ActivatedStateNamespaceEnvVarName,
constants.ActivatedStateEnvVarName)
if runtime.GOOS == "windows" {
fish = strings.ReplaceAll(fish, "\n", "\r\n")
}

tests := []struct {
name string
args args
want error
want error
wantContents string
}{
{
Expand All @@ -75,7 +59,7 @@ end`,
},
},
nil,
fakeContents("", fish, ""),
fakeContents("", `set -xg PATH "foo:$PATH"`, ""),
},
{
"Write RC update",
Expand All @@ -87,7 +71,7 @@ end`,
},
},
nil,
fakeContents(strings.Join([]string{"before", "after"}, fileutils.LineEnd), fish, ""),
fakeContents(strings.Join([]string{"before", "after"}, fileutils.LineEnd), `set -xg PATH "foo:$PATH"`, ""),
},
}
for _, tt := range tests {
Expand Down
3 changes: 1 addition & 2 deletions internal/virtualenvironment/virtualenvironment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func New(runtime *runtime.Runtime) *VirtualEnvironment {
}

// GetEnv returns a map of the cumulative environment variables for all active virtual environments
func (v *VirtualEnvironment) GetEnv(inherit bool, useExecutors bool, projectDir, namespace string) (map[string]string, error) {
func (v *VirtualEnvironment) GetEnv(inherit bool, useExecutors bool, projectDir string) (map[string]string, error) {
envMap := make(map[string]string)

// Source runtime environment information
Expand All @@ -44,7 +44,6 @@ func (v *VirtualEnvironment) GetEnv(inherit bool, useExecutors bool, projectDir,
if projectDir != "" {
envMap[constants.ActivatedStateEnvVarName] = projectDir
envMap[constants.ActivatedStateIDEnvVarName] = v.activationID
envMap[constants.ActivatedStateNamespaceEnvVarName] = namespace

// Get project from explicitly defined configuration file
configFile := filepath.Join(projectDir, constants.ConfigFileName)
Expand Down
51 changes: 0 additions & 51 deletions test/integration/shell_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/subshell"
"github.com/ActiveState/cli/internal/subshell/bash"
"github.com/ActiveState/cli/internal/subshell/sscommon"
"github.com/ActiveState/cli/internal/subshell/zsh"
"github.com/ActiveState/cli/internal/testhelpers/e2e"
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
Expand Down Expand Up @@ -267,8 +265,6 @@ func (suite *ShellIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
rcFile, err := subshell.RcFile()
suite.Require().NoError(err)

err = fileutils.TouchFileUnlessExists(rcFile)
suite.Require().NoError(err)
err = fileutils.CopyFile(rcFile, filepath.Join(ts.Dirs.HomeDir, filepath.Base(rcFile)))
suite.Require().NoError(err)

Expand All @@ -282,53 +278,6 @@ func (suite *ShellIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
suite.Require().NoError(err)
}

func (suite *ShellIntegrationTestSuite) TestNestedShellNotification() {
if runtime.GOOS == "windows" {
return // cmd.exe does not have an RC file to check for nested shells in
}
suite.OnlyRunForTags(tagsuite.Shell)
ts := e2e.New(suite.T(), false)
defer ts.Close()

var ss subshell.SubShell
var rcFile string
env := []string{"ACTIVESTATE_CLI_DISABLE_RUNTIME=false"}
switch runtime.GOOS {
case "darwin":
ss = &zsh.SubShell{}
ss.SetBinary("zsh")
rcFile = filepath.Join(ts.Dirs.HomeDir, ".zshrc")
suite.Require().NoError(sscommon.WriteRcFile("zshrc_append.sh", rcFile, sscommon.DefaultID, nil))
env = append(env, "SHELL=zsh") // override since CI tests are running on bash
case "linux":
ss = &bash.SubShell{}
ss.SetBinary("bash")
rcFile = filepath.Join(ts.Dirs.HomeDir, ".bashrc")
suite.Require().NoError(sscommon.WriteRcFile("bashrc_append.sh", rcFile, sscommon.DefaultID, nil))
default:
suite.Fail("Unsupported OS")
}
suite.Require().Equal(filepath.Dir(rcFile), ts.Dirs.HomeDir, "rc file not in test suite homedir")
suite.Require().Contains(string(fileutils.ReadFileUnsafe(rcFile)), "State Tool is operating on project")

cp := ts.Spawn("checkout", "ActiveState-CLI/small-python")
cp.Expect("Checked out project")
cp.ExpectExitCode(0)

cp = ts.SpawnWithOpts(
e2e.OptArgs("shell", "small-python"),
e2e.OptAppendEnv(env...))
cp.Expect("Activated", e2e.RuntimeSourcingTimeoutOpt)
suite.Assert().NotContains(cp.Output(), "State Tool is operating on project")
cp.SendLine(fmt.Sprintf(`export HOME="%s"`, ts.Dirs.HomeDir)) // some shells do not forward this

cp.SendLine(ss.Binary()) // platform-specific shell (zsh on macOS, bash on Linux, etc.)
cp.Expect("State Tool is operating on project ActiveState-CLI/small-python")
cp.SendLine("exit") // subshell within a subshell
cp.SendLine("exit")
cp.ExpectExitCode(0)
}

func (suite *ShellIntegrationTestSuite) TestRuby() {
if runtime.GOOS == "darwin" {
return // Ruby support is not yet enabled on the Platform
Expand Down

0 comments on commit abc89d0

Please sign in to comment.