-
Notifications
You must be signed in to change notification settings - Fork 268
Add external prompting support to Azure Developer CLI #6605
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
Merged
+1,607
−55
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
026aa97
fix security issue with playwright/test 1.49.1 (#6592)
vhvb1989 cb20d72
Merge branch 'main' of https://github.com/Azure/azure-dev
vhvb1989 6335069
Merge branch 'main' of https://github.com/Azure/azure-dev
vhvb1989 3696c9f
Checkpoint from VS Code for cloud agent session
vhvb1989 193532d
Update parameter popup border color to cyan in concurX extension
Copilot c60594d
Complete concurX parameter popup color update
Copilot 1ab8ca4
cspell
vhvb1989 4640197
Merge branch 'copilot/vscode-mkrqfyvm-kps6' of https://github.com/Azu…
vhvb1989 2d99040
Remove unintended changes to azure.ai.finetune extension
Copilot 6f1b3f6
azure.ai.agents - Set `CGO_ENABLED=0` for x64 Linux build (#6611)
JeffreyCA 3bee29e
Bump version to 0.1.8-preview (#6613)
JeffreyCA 2b2b50c
Extension update fixes/enhancements (#6604)
Copilot 0061e60
Fix bicep CLI uninitialized path in container app deployments (#6610)
Copilot 4b1f840
Add azure.ai.agent 0.1.8-preview to registry (#6615)
JeffreyCA a3f52af
Release 1.23.2 (#6616)
Copilot 7046a61
Increment CLI version after release (#6617)
azure-sdk d3bdb4d
Migrate to use new shared eng package (#6600)
bwateratmsft b96cb28
Fix VS Code extension commands failing with undefined fsPath in virtu…
Copilot 7f0d907
Add missing keys to `azd config options` (#6619)
Copilot 3fd6e76
Raising for missing method type (#6628)
achauhan-scc ec6e3f2
RFT grader fixes (#6629)
achauhan-scc 3369e1d
including .14-preview to main registry (#6630)
achauhan-scc d8a388b
Add a naive attempt at downloading manifest (#6631)
trangevi e4f6d36
Dev container feature - allow installing extensions (#6460)
stuartleeks e6967ca
Enable full figspec generation for extensions with metadata capabilit…
Copilot 0bb1b56
Add concurX binary to gitignore
Copilot 49d809e
Merge branch 'main' of https://github.com/Azure/azure-dev into copilo…
vhvb1989 5cab4b0
lint
vhvb1989 11b9885
Update TestAskerConsoleExternalPrompt to use new external prompt mech…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/internal" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/input" | ||
| "github.com/azure/azure-dev/cli/azd/pkg/output" | ||
| "github.com/spf13/cobra" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestExternalPromptFromEnvironmentVariables verifies that the console reads | ||
| // AZD_UI_PROMPT_ENDPOINT and AZD_UI_PROMPT_KEY environment variables and | ||
| // configures external prompting accordingly. | ||
| func TestExternalPromptFromEnvironmentVariables(t *testing.T) { | ||
| // Create a test HTTP server that simulates the external prompt endpoint | ||
| server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| // Return a success response | ||
| w.Header().Set("Content-Type", "application/json") | ||
| json.NewEncoder(w).Encode(map[string]any{ | ||
| "status": "success", | ||
| "value": "test-response", | ||
| }) | ||
| })) | ||
| defer server.Close() | ||
|
|
||
| testKey := "test-secret-key-12345" | ||
|
|
||
| // Set environment variables | ||
| t.Setenv("AZD_UI_PROMPT_ENDPOINT", server.URL) | ||
| t.Setenv("AZD_UI_PROMPT_KEY", testKey) | ||
|
|
||
| // Create a mock cobra command | ||
| cmd := &cobra.Command{} | ||
| cmd.SetIn(os.Stdin) | ||
| cmd.SetOut(os.Stdout) | ||
| cmd.SetErr(os.Stderr) | ||
|
|
||
| // Create root options | ||
| rootOptions := &internal.GlobalCommandOptions{ | ||
| NoPrompt: false, | ||
| } | ||
|
|
||
| // Create formatter | ||
| var formatter output.Formatter = nil | ||
|
|
||
| // This simulates what happens in container.go when registering the console | ||
| writer := cmd.OutOrStdout() | ||
|
|
||
| isTerminal := false // Force non-terminal for test | ||
|
|
||
| // Check for external prompt configuration from environment variables | ||
| // (This is the code we added to container.go) | ||
| var externalPromptCfg *input.ExternalPromptConfiguration | ||
| if endpoint := os.Getenv("AZD_UI_PROMPT_ENDPOINT"); endpoint != "" { | ||
| if key := os.Getenv("AZD_UI_PROMPT_KEY"); key != "" { | ||
| externalPromptCfg = &input.ExternalPromptConfiguration{ | ||
| Endpoint: endpoint, | ||
| Key: key, | ||
| Transporter: http.DefaultClient, | ||
| } | ||
vhvb1989 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
vhvb1989 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Verify the config was created | ||
| require.NotNil(t, externalPromptCfg, "External prompt config should be created from env vars") | ||
| require.Equal(t, server.URL, externalPromptCfg.Endpoint) | ||
| require.Equal(t, testKey, externalPromptCfg.Key) | ||
| require.NotNil(t, externalPromptCfg.Transporter) | ||
|
|
||
| // Create the console with external prompting configured | ||
| console := input.NewConsole( | ||
| rootOptions.NoPrompt, | ||
| isTerminal, | ||
| input.Writers{Output: writer}, | ||
| input.ConsoleHandles{ | ||
| Stdin: cmd.InOrStdin(), | ||
| Stdout: cmd.OutOrStdout(), | ||
| Stderr: cmd.ErrOrStderr(), | ||
| }, | ||
| formatter, | ||
| externalPromptCfg, | ||
| ) | ||
|
|
||
| require.NotNil(t, console) | ||
|
|
||
| // Note: Actually testing that the console uses external prompting would require | ||
| // calling Prompt/Select/Confirm methods, which is tested in console_test.go | ||
| // This test verifies the environment variable reading logic works correctly. | ||
| } | ||
|
|
||
| // TestExternalPromptNotConfiguredWithoutEnvVars verifies that when the | ||
| // environment variables are not set, no external prompt config is created. | ||
| func TestExternalPromptNotConfiguredWithoutEnvVars(t *testing.T) { | ||
| // Ensure env vars are not set | ||
| os.Unsetenv("AZD_UI_PROMPT_ENDPOINT") | ||
| os.Unsetenv("AZD_UI_PROMPT_KEY") | ||
|
|
||
| // Check for external prompt configuration from environment variables | ||
| var externalPromptCfg *input.ExternalPromptConfiguration | ||
| if endpoint := os.Getenv("AZD_UI_PROMPT_ENDPOINT"); endpoint != "" { | ||
| if key := os.Getenv("AZD_UI_PROMPT_KEY"); key != "" { | ||
| externalPromptCfg = &input.ExternalPromptConfiguration{ | ||
| Endpoint: endpoint, | ||
| Key: key, | ||
| Transporter: http.DefaultClient, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| require.Nil(t, externalPromptCfg, "External prompt config should be nil when env vars not set") | ||
| } | ||
|
|
||
| // TestExternalPromptRequiresBothEnvVars verifies that both environment | ||
| // variables must be set for external prompting to be configured. | ||
| func TestExternalPromptRequiresBothEnvVars(t *testing.T) { | ||
| t.Run("only endpoint set", func(t *testing.T) { | ||
| t.Setenv("AZD_UI_PROMPT_ENDPOINT", "http://localhost:8080") | ||
| os.Unsetenv("AZD_UI_PROMPT_KEY") | ||
|
|
||
| var externalPromptCfg *input.ExternalPromptConfiguration | ||
| if endpoint := os.Getenv("AZD_UI_PROMPT_ENDPOINT"); endpoint != "" { | ||
| if key := os.Getenv("AZD_UI_PROMPT_KEY"); key != "" { | ||
| externalPromptCfg = &input.ExternalPromptConfiguration{ | ||
| Endpoint: endpoint, | ||
| Key: key, | ||
| Transporter: http.DefaultClient, | ||
| } | ||
| } | ||
| } | ||
vhvb1989 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| require.Nil(t, externalPromptCfg, "Config should be nil when only endpoint is set") | ||
| }) | ||
|
|
||
| t.Run("only key set", func(t *testing.T) { | ||
| os.Unsetenv("AZD_UI_PROMPT_ENDPOINT") | ||
| t.Setenv("AZD_UI_PROMPT_KEY", "secret-key") | ||
|
|
||
| var externalPromptCfg *input.ExternalPromptConfiguration | ||
| if endpoint := os.Getenv("AZD_UI_PROMPT_ENDPOINT"); endpoint != "" { | ||
| if key := os.Getenv("AZD_UI_PROMPT_KEY"); key != "" { | ||
| externalPromptCfg = &input.ExternalPromptConfiguration{ | ||
| Endpoint: endpoint, | ||
| Key: key, | ||
| Transporter: http.DefaultClient, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| require.Nil(t, externalPromptCfg, "Config should be nil when only key is set") | ||
| }) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.