From d1a2a47bfbabfcf32f4c42c4d66590405c8c36fa Mon Sep 17 00:00:00 2001 From: Wallace Breza Date: Thu, 9 Apr 2026 13:38:52 -0700 Subject: [PATCH] fix: add default case to installDeps switch for unrecognized dep files Log unrecognized dependency file types in the Python executor's installDeps() switch statement instead of silently succeeding. Makes the coupling between knownProjectFiles and installDeps explicit for future maintainability. Fixes #7612 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- cli/azd/pkg/tools/language/python_executor.go | 6 ++++ .../tools/language/python_executor_test.go | 36 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/cli/azd/pkg/tools/language/python_executor.go b/cli/azd/pkg/tools/language/python_executor.go index 2f8d55ec322..fa9b2b426fc 100644 --- a/cli/azd/pkg/tools/language/python_executor.go +++ b/cli/azd/pkg/tools/language/python_executor.go @@ -7,6 +7,7 @@ import ( "context" "errors" "fmt" + "log" "os" "path/filepath" "runtime" @@ -246,6 +247,11 @@ func (e *pythonExecutor) installDeps( err, ) } + default: + log.Printf( + "unsupported dependency file %q - skipping install", + depFile, + ) } return nil } diff --git a/cli/azd/pkg/tools/language/python_executor_test.go b/cli/azd/pkg/tools/language/python_executor_test.go index 72597f32ffd..5a414d2ccd2 100644 --- a/cli/azd/pkg/tools/language/python_executor_test.go +++ b/cli/azd/pkg/tools/language/python_executor_test.go @@ -4,8 +4,10 @@ package language import ( + "bytes" "context" "errors" + "log" "os" "path/filepath" "runtime" @@ -263,6 +265,40 @@ func TestPythonPrepare_VenvAlreadyExists(t *testing.T) { assert.NotEmpty(t, e.venvPath) } +func TestPythonInstallDeps_UnrecognizedFile(t *testing.T) { + cli := &mockPythonTools{} + e := newPythonExecutorInternal( + &mockCommandRunner{}, cli, + ) + + // Capture log output to verify the default-case message. + var buf bytes.Buffer + log.SetOutput(&buf) + defer log.SetOutput(os.Stderr) + + err := e.installDeps( + t.Context(), t.TempDir(), + "some_env", "unknown.cfg", nil, + ) + + require.NoError(t, err, + "unrecognized dep file should not return an error", + ) + assert.False(t, cli.installReqCalled, + "should not call InstallRequirements", + ) + assert.False(t, cli.installProjCalled, + "should not call InstallProject", + ) + assert.Contains(t, buf.String(), + "unsupported dependency file", + "should log a skip message for unrecognized files", + ) + assert.Contains(t, buf.String(), "unknown.cfg", + "log message should include the file name", + ) +} + // --------------------------------------------------------------------------- // Execute tests // ---------------------------------------------------------------------------