Skip to content

Conversation

@spboyer
Copy link
Member

@spboyer spboyer commented Jan 7, 2026

  • Add IsValid field to EnvListEnvironment contract
  • Update LocalFileDataStore.List to validate environment names
  • Add STATUS column to env list table output
  • Display warning message for invalid environment names
  • Add validation to manager.Get() to reject invalid names
  • Add tests for invalid environment name scenarios

Fixes #3355

- Add IsValid field to EnvListEnvironment contract
- Update LocalFileDataStore.List to validate environment names
- Add STATUS column to env list table output
- Display warning message for invalid environment names
- Add validation to manager.Get() to reject invalid names
- Add tests for invalid environment name scenarios
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #3355 by adding validation for environment names in the azd env list command. The implementation enhances user experience by clearly identifying invalid environment names that may cause issues with azd commands.

Key changes:

  • Adds IsValid field to the environment list contract to track validation status
  • Implements early validation in manager.Get() to reject operations on invalid environment names
  • Enhances azd env list output with a STATUS column showing validation status and a warning message for invalid environments

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
cli/azd/pkg/contracts/env_list.go Adds IsValid boolean field to the EnvListEnvironment contract to indicate whether an environment name passes validation
cli/azd/pkg/environment/local_file_data_store.go Updates List() method to populate the IsValid field by calling IsValidEnvironmentName() for each environment directory
cli/azd/pkg/environment/local_file_data_store_test.go Adds comprehensive test validating that environments with valid and invalid names are correctly marked in the list results
cli/azd/pkg/environment/manager.go Adds validation check in Get() to reject invalid environment names early, and propagates IsValid field in List() for both local and remote environments
cli/azd/pkg/environment/manager_test.go Adds test cases verifying that manager.Get() rejects various invalid environment name patterns
cli/azd/cmd/env.go Adds STATUS column to table output showing validation status with icons, and displays warning message when invalid environments are detected (table format only)

Comment on lines +285 to +308
t.Run("InvalidEnvironmentName", func(t *testing.T) {
localDataStore := &MockDataStore{}

manager := newManagerForTest(azdContext, mockContext.Console, localDataStore, nil)

// Test various invalid names
invalidNames := []string{
"#invalid",
"$bad%name",
"no spaces",
"no*asterisk",
}

for _, invalidName := range invalidNames {
env, err := manager.Get(*mockContext.Context, invalidName)
require.Error(t, err, "Should error for invalid name: %s", invalidName)
require.Nil(t, env)
require.Contains(t, err.Error(), "invalid")
require.Contains(t, err.Error(), "Valid names can only contain")
}

// localDataStore.Get should never be called for invalid names
localDataStore.AssertNotCalled(t, "Get")
})
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test implementation doesn't follow the table-driven testing pattern which is a standard practice in this codebase (as mentioned in the coding guidelines). Consider refactoring this test to use a table-driven approach for better maintainability and easier addition of new test cases. The test should be structured with a slice of test cases containing name, input, and expected error patterns.

Copilot generated this review using guidance from repository custom instructions.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

spboyer and others added 2 commits January 8, 2026 12:38
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@vhvb1989 vhvb1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tks. We might need to look into azd env select as well.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +416 to 418

// Check cache first
cached, err := m.getFromCache(ctx, name)
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code contains duplicate lines. Lines 414-415 and lines 417-418 are identical. The comment "Check cache first" and the variable assignment "cached, err := m.getFromCache(ctx, name)" appear twice. Please remove lines 414-415 to eliminate the duplication.

Suggested change
// Check cache first
cached, err := m.getFromCache(ctx, name)

Copilot uses AI. Check for mistakes.
require.Error(t, err, "Should error for invalid name: %s", invalidName)
require.Nil(t, env)
require.Contains(t, err.Error(), "invalid")
require.Contains(t, err.Error(), "Valid names can only contain")
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test expects the error message to contain "Valid names can only contain", but the actual error message returned by invalidEnvironmentNameMsg() says "it should contain only alphanumeric characters and hyphens". This test will fail because the error message doesn't match the expected substring. The test expectation should be updated to match the actual error message, for example by checking for "invalid" and "alphanumeric" instead.

Suggested change
require.Contains(t, err.Error(), "Valid names can only contain")
require.Contains(t, err.Error(), "alphanumeric")

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure this is solving some customer pain point... Yes - users could manually create an environment that is invalid - but is this something users are strugging with?

@vhvb1989
Copy link
Member

I'm not quite sure this is solving some customer pain point... Yes - users could manually create an environment that is invalid - but is this something users are strugging with?

I think that in most cases it is not the user manually creating the environment, but some automation. Like AI agents skipping the call to azd env new .... and directly trying to write the expected files. I see this change as a protection against nils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

azd env list listing can contain invalid names

3 participants