Skip to content

Commit

Permalink
Merge pull request #2721 from ActiveState/beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan authored Aug 22, 2023
2 parents 2367dd2 + c83ee5a commit c63b1c3
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 38 deletions.
16 changes: 16 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### 0.40.1

### Added

* State tool will now warn users if its executables are deleted during
installation, indicating a false-positive action from antivirus software.

### Fixed

* Fixed auto updates not being run (if you are on an older version:
run `state update`).
* Fixed a rare parsing panic that would happen when running particularly complex
builds.
* Fixed race condition during artifact installation that could lead to errors
like "Could not unpack artifact .. file already exists".

### 0.40.0

### Added
Expand Down
6 changes: 2 additions & 4 deletions cmd/state/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ func isEnabled(cfg *config.Instance) bool {
}

func shouldRunAutoUpdate(args []string, cfg *config.Instance, an analytics.Dispatcher) bool {
var (
shouldUpdate bool
label string
)
shouldUpdate := true
label := anaConst.UpdateLabelTrue

switch {
// In a forward
Expand Down
8 changes: 7 additions & 1 deletion internal/installation/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ type InstallMarkerMeta struct {
Version string `json:"version"`
}

type StateExeDoesNotExistError struct{ *errs.WrapperError }

func IsStateExeDoesNotExistError(err error) bool {
return errs.Matches(err, &StateExeDoesNotExistError{})
}

func DefaultInstallPath() (string, error) {
return InstallPathForBranch(constants.BranchName)
}
Expand Down Expand Up @@ -84,7 +90,7 @@ func InstallPathFromReference(dir string) (string, error) {

stateExe := filepath.Join(binPath, cmdName)
if !fileutils.TargetExists(stateExe) {
return "", errs.New("Installation bin directory does not contain %s", stateExe)
return "", &StateExeDoesNotExistError{errs.New("Installation bin directory does not contain %s", stateExe)}
}

return filepath.Dir(binPath), nil
Expand Down
7 changes: 7 additions & 0 deletions internal/locale/locales/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,13 @@ svcctl_file_not_found:
If this problem persists please report it on our forums: [ACTIONABLE]{{.V0}}[/RESET]
err_autostart_app:
other: Could not create new autostart app
err_install_state_exe_does_not_exist:
other: |
Could not install State Tool. One or more of the installed executables appears to have been deleted during installation. Please check with your antivirus to see if it might have triggered a false-positive.
Please consider letting us know what antivirus you are running so that we can address this false-positive: [ACTIONABLE]{{.V0}}[/RESET].
Note the source code of the State Tool is open source, and you can review it yourself should you have concerns: [ACTIONABLE]https://github.com/ActiveState/cli[/RESET]
install_remote_title:
other: This will install the State Tool
err_already_checked_out:
Expand Down
4 changes: 4 additions & 0 deletions internal/runners/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/globaldefault"
"github.com/ActiveState/cli/internal/installation"
"github.com/ActiveState/cli/internal/installation/storage"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
Expand Down Expand Up @@ -113,6 +114,9 @@ func (r *Prepare) Run(cmd *captain.Command) error {
// OS specific preparations
err := r.prepareOS()
if err != nil {
if installation.IsStateExeDoesNotExistError(err) && runtime.GOOS == "windows" {
return locale.WrapInputError(err, "err_install_state_exe_does_not_exist", "", constants.ForumsURL)
}
return errs.Wrap(err, "Could not prepare OS")
}

Expand Down
6 changes: 3 additions & 3 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ func (s *Session) LogoutUser() {
p.ExpectExitCode(0)
}

func (s *Session) CreateNewUser() string {
func (s *Session) CreateNewUser() (string, string) {
uid, err := uuid.NewRandom()
require.NoError(s.t, err)

username := fmt.Sprintf("user-%s", uid.String()[0:8])
password := username
password := uid.String()[8:]
email := fmt.Sprintf("%[email protected]", username)

p := s.Spawn(tagsuite.Auth, "signup", "--prompt")
Expand All @@ -363,7 +363,7 @@ func (s *Session) CreateNewUser() string {

s.users = append(s.users, username)

return username
return username, password
}

// NotifyProjectCreated indicates that the given project was created on the Platform and needs to
Expand Down
35 changes: 26 additions & 9 deletions pkg/platform/runtime/buildexpression/buildexpression.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/ActiveState/cli/internal/errs"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/logging"
"github.com/ActiveState/cli/internal/multilog"
"github.com/ActiveState/cli/internal/rtutils/ptr"
"github.com/ActiveState/cli/internal/sliceutils"
Expand Down Expand Up @@ -54,10 +55,11 @@ type Var struct {
}

type Value struct {
Ap *Ap
List *[]*Value
Str *string
Null *Null
Ap *Ap
List *[]*Value
Str *string
Null *Null
Float *float64

Assignment *Var
Object *[]*Var
Expand Down Expand Up @@ -248,7 +250,11 @@ func newValue(path []string, valueInterface interface{}) (*Value, error) {
value.Str = ptr.To(v)
}

case float64:
value.Float = ptr.To(v)

default:
logging.Debug("Unknown type: %T at path %s", v, strings.Join(path, "."))
// An empty value is interpreted as JSON null.
value.Null = &Null{}
}
Expand All @@ -265,15 +271,24 @@ func newAp(path []string, m map[string]interface{}) (*Ap, error) {
}
}()

// Look in the given object for the function's name and argument object or list.
// m is a mapping of function name to arguments. There should only be one
// set of arugments. Since the arguments are key-value pairs, it should be
// a map[string]interface{}.
if len(m) > 1 {
return nil, errs.New("Function call has more than one argument mapping")
}

// Look in the given object for the function's name and argument mapping.
var name string
var argsInterface interface{}
for key, value := range m {
if isAp(path, value.(map[string]interface{})) {
name = key
argsInterface = value
break
_, ok := value.(map[string]interface{})
if !ok {
return nil, errs.New("Function call's argument is not a map[string]interface{}")
}

name = key
argsInterface = value
}

args := []*Value{}
Expand Down Expand Up @@ -729,6 +744,8 @@ func (v *Value) MarshalJSON() ([]byte, error) {
return json.Marshal(nil)
case v.Assignment != nil:
return json.Marshal(v.Assignment)
case v.Float != nil:
return json.Marshal(*v.Float)
case v.Object != nil:
m := make(map[string]interface{})
for _, assignment := range *v.Object {
Expand Down
16 changes: 9 additions & 7 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,15 @@ func (s *Setup) fetchAndInstallArtifactsFromDir(installFunc artifactInstaller) (
installedArtifacts[i] = artifactID

// Submit the artifact for setup and install.
wp.Submit(func() {
as := alternative.NewArtifactSetup(artifactID, s.store) // offline installer artifacts are in this format
err = installFunc(artifactID, filename, as)
if err != nil {
errors <- locale.WrapError(err, "artifact_setup_failed", "", artifactID.String(), "")
}
})
func(filename string, artifactID strfmt.UUID) {
wp.Submit(func() {
as := alternative.NewArtifactSetup(artifactID, s.store) // offline installer artifacts are in this format
err = installFunc(artifactID, filename, as)
if err != nil {
errors <- locale.WrapError(err, "artifact_setup_failed", "", artifactID.String(), "")
}
})
}(filename, artifactID) // avoid referencing loop variables inside goroutine closures
}

wp.StopWait()
Expand Down
8 changes: 4 additions & 4 deletions test/integration/auth_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ func (suite *AuthIntegrationTestSuite) TestAuth() {
suite.OnlyRunForTags(tagsuite.Auth, tagsuite.Critical)
ts := e2e.New(suite.T(), false)
defer ts.Close()
username := ts.CreateNewUser()
username, password := ts.CreateNewUser()
ts.LogoutUser()
suite.interactiveLogin(ts, username)
suite.interactiveLogin(ts, username, password)
ts.LogoutUser()
suite.loginFlags(ts, username)
suite.ensureLogout(ts)
Expand All @@ -58,12 +58,12 @@ func (suite *AuthIntegrationTestSuite) TestAuthToken() {
suite.ensureLogout(ts)
}

func (suite *AuthIntegrationTestSuite) interactiveLogin(ts *e2e.Session, username string) {
func (suite *AuthIntegrationTestSuite) interactiveLogin(ts *e2e.Session, username, password string) {
cp := ts.Spawn(tagsuite.Auth, "--prompt")
cp.Expect("username:")
cp.Send(username)
cp.Expect("password:")
cp.Send(username)
cp.Send(password)
cp.Expect("logged in", 40*time.Second)
cp.ExpectExitCode(0)

Expand Down
2 changes: 1 addition & 1 deletion test/integration/fork_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (suite *ForkIntegrationTestSuite) TestFork() {
ts := e2e.New(suite.T(), false)
defer suite.cleanup(ts)

username := ts.CreateNewUser()
username, _ := ts.CreateNewUser()

cp := ts.Spawn("fork", "ActiveState-CLI/Python3", "--name", "Test-Python3", "--org", username)
cp.Expect("fork has been successfully created")
Expand Down
20 changes: 17 additions & 3 deletions test/integration/package_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (suite *PackageIntegrationTestSuite) TestPackage_import() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

username := ts.CreateNewUser()
username, _ := ts.CreateNewUser()
namespace := fmt.Sprintf("%s/%s", username, "Python3")

cp := ts.Spawn("init", "--language", "python", namespace, ts.Dirs.Work)
Expand Down Expand Up @@ -375,7 +375,7 @@ func (suite *PackageIntegrationTestSuite) TestPackage_operation() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

username := ts.CreateNewUser()
username, _ := ts.CreateNewUser()
namespace := fmt.Sprintf("%s/%s", username, "python3-pkgtest")

cp := ts.Spawn("fork", "ActiveState-CLI/Packages", "--org", username, "--name", "python3-pkgtest")
Expand Down Expand Up @@ -504,13 +504,19 @@ func (suite *PackageIntegrationTestSuite) TestNormalize() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

cp := ts.Spawn("checkout", "ActiveState-CLI/small-python", ".")
dir := filepath.Join(ts.Dirs.Work, "normalized")
suite.Require().NoError(fileutils.Mkdir(dir))
cp := ts.SpawnWithOpts(
e2e.WithArgs("checkout", "ActiveState-CLI/small-python", "."),
e2e.WithWorkDirectory(dir),
)
cp.Expect("Skipping runtime setup")
cp.Expect("Checked out project")
cp.ExpectExitCode(0)

cp = ts.SpawnWithOpts(
e2e.WithArgs("install", "Charset_normalizer"),
e2e.WithWorkDirectory(dir),
e2e.AppendEnv("ACTIVESTATE_CLI_DISABLE_RUNTIME=false"),
)
cp.Expect("charset-normalizer")
Expand All @@ -520,6 +526,14 @@ func (suite *PackageIntegrationTestSuite) TestNormalize() {

anotherDir := filepath.Join(ts.Dirs.Work, "not-normalized")
suite.Require().NoError(fileutils.Mkdir(anotherDir))
cp = ts.SpawnWithOpts(
e2e.WithArgs("checkout", "ActiveState-CLI/small-python", "."),
e2e.WithWorkDirectory(anotherDir),
)
cp.Expect("Skipping runtime setup")
cp.Expect("Checked out project")
cp.ExpectExitCode(0)

cp = ts.SpawnWithOpts(
e2e.WithArgs("install", "charset-normalizer"),
e2e.WithWorkDirectory(anotherDir),
Expand Down
7 changes: 3 additions & 4 deletions test/integration/push_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (
"testing"
"time"

"github.com/ActiveState/cli/internal/fileutils"
"github.com/stretchr/testify/suite"

"github.com/ActiveState/cli/internal/constants"
"github.com/ActiveState/cli/internal/fileutils"
"github.com/ActiveState/cli/internal/strutils"
"github.com/ActiveState/cli/internal/testhelpers/e2e"
"github.com/ActiveState/cli/internal/testhelpers/tagsuite"
"github.com/ActiveState/cli/pkg/project"
"github.com/ActiveState/cli/pkg/projectfile"
"github.com/stretchr/testify/suite"
)

type PushIntegrationTestSuite struct {
Expand Down Expand Up @@ -158,7 +157,7 @@ func (suite *PushIntegrationTestSuite) TestPush_NoPermission_NewProject() {
suite.OnlyRunForTags(tagsuite.Push)
ts := e2e.New(suite.T(), false)
defer ts.Close()
username := ts.CreateNewUser()
username, _ := ts.CreateNewUser()
pname := strutils.UUID()

cp := ts.SpawnWithOpts(e2e.WithArgs("activate", suite.baseProject, "--path", ts.Dirs.Work))
Expand Down
2 changes: 1 addition & 1 deletion test/integration/vscode_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (suite *PushIntegrationTestSuite) TestInitAndPush_VSCode() {

ts := e2e.New(suite.T(), false)
defer ts.Close()
username := ts.CreateNewUser()
username, _ := ts.CreateNewUser()

namespace := fmt.Sprintf("%s/%s", username, "Perl")
cp := ts.Spawn(
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.40.0-RC4
0.40.1-RC1

0 comments on commit c63b1c3

Please sign in to comment.