-
Notifications
You must be signed in to change notification settings - Fork 267
Fix #3355: Add validation for environment names in azd env list #6463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
There was a problem hiding this 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
IsValidfield 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 listoutput 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) |
| 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") | ||
| }) |
Copilot
AI
Jan 7, 2026
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
vhvb1989
left a comment
There was a problem hiding this 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.
There was a problem hiding this 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.
|
|
||
| // Check cache first | ||
| cached, err := m.getFromCache(ctx, name) |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
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.
| // Check cache first | |
| cached, err := m.getFromCache(ctx, name) |
| 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") |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
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.
| require.Contains(t, err.Error(), "Valid names can only contain") | |
| require.Contains(t, err.Error(), "alphanumeric") |
wbreza
left a comment
There was a problem hiding this 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?
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 |
Fixes #3355