Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cli/azd/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ func setupInitAction(t *testing.T, mockContext *mocks.MockContext, flags *initFl

// Work in a temp directory so os.Getwd / godotenv.Overload operate in isolation.
tmpDir := t.TempDir()
origDir, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(tmpDir))
t.Cleanup(func() { os.Chdir(origDir) })
t.Chdir(tmpDir)

// Mock git so tools.EnsureInstalled succeeds.
mockContext.CommandRunner.MockToolInPath("git", nil)
Expand Down
9 changes: 2 additions & 7 deletions cli/azd/internal/agent/security/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ func TestSecurityManager_ValidatePath_DirectoryChange(t *testing.T) {
}

// Change to temp directory first
originalWd, _ := os.Getwd()
defer os.Chdir(originalWd)
os.Chdir(tempDir)
t.Chdir(tempDir)

// Test valid directory changes within security root
subDirPath := filepath.Join(tempDir, "subdir")
Expand Down Expand Up @@ -186,10 +184,7 @@ func TestResolvePath_ExistingFiles(t *testing.T) {
}

// Test with relative path to existing file
oldWd, _ := os.Getwd()
defer os.Chdir(oldWd)

os.Chdir(tempDir)
t.Chdir(tempDir)
resolved, err = resolvePath("test.txt")
if err != nil {
t.Errorf("resolvePath failed for relative path to existing file: %v", err)
Expand Down
24 changes: 6 additions & 18 deletions cli/azd/internal/mcp/tools/azd_yaml_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ func TestHandleAzdYamlSchema_ValidYaml(t *testing.T) {
tmpFile.Close()
yamlPath := tmpFile.Name()

oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)
t.Chdir(tmpDir)
os.Rename(yamlPath, "azure.yaml") //nolint:gosec // G703: test file rename with controlled paths
defer os.Remove("azure.yaml")

Expand All @@ -54,9 +52,7 @@ func TestHandleAzdYamlSchema_ValidYaml(t *testing.T) {
func TestHandleAzdYamlSchema_MissingYaml(t *testing.T) {
// Arrange
tmpDir := t.TempDir()
oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)
t.Chdir(tmpDir)

req := mcp.CallToolRequest{}
req.Params.Arguments = map[string]any{"path": "azure.yaml"}
Expand All @@ -82,9 +78,7 @@ func TestHandleAzdYamlSchema_InvalidYaml(t *testing.T) {
tmpFile.Close()
yamlPath := tmpFile.Name()

oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)
t.Chdir(tmpDir)
os.Rename(yamlPath, "azure.yaml") //nolint:gosec // G703: test file rename with controlled paths
defer os.Remove("azure.yaml")

Expand Down Expand Up @@ -112,9 +106,7 @@ func TestHandleAzdYamlSchema_YamlNotValidSyntax(t *testing.T) {
tmpFile.Close()
yamlPath := tmpFile.Name()

oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)
t.Chdir(tmpDir)
os.Rename(yamlPath, "azure.yaml") //nolint:gosec // G703: test file rename with controlled paths
defer os.Remove("azure.yaml")

Expand Down Expand Up @@ -143,9 +135,7 @@ func TestHandleAzdYamlSchema_YamlValidButSchemaInvalid(t *testing.T) {
tmpFile.Close()
yamlPath := tmpFile.Name()

oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)
t.Chdir(tmpDir)
os.Rename(yamlPath, "azure.yaml") //nolint:gosec // G703: test file rename with controlled paths
defer os.Remove("azure.yaml")

Expand Down Expand Up @@ -173,9 +163,7 @@ func TestHandleAzdYamlSchema_InvalidYaml_Structural(t *testing.T) {
tmpFile.Close()
yamlPath := tmpFile.Name()

oldWd, _ := os.Getwd()
os.Chdir(tmpDir)
defer os.Chdir(oldWd)
t.Chdir(tmpDir)
os.Rename(yamlPath, "azure.yaml") //nolint:gosec // G703: test file rename with controlled paths
defer os.Remove("azure.yaml")

Expand Down
Loading