From 4a4b89eb02b31e99dfd3f9736b842a4f8a516e97 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen Date: Wed, 8 Jul 2026 21:57:30 +0000 Subject: [PATCH] Fix phantom test failures from tool first-run spinners writing to os.Stdout The tool first-run middleware creates detect/install spinners via uxlib.NewSpinner without setting Writer, so they default to os.Stdout and emit cursor escape codes (\033[?25l / \033[?25h) during unit tests. Under 'go test -json' these raw bytes corrupt the event stream, causing phantom 'unknown'/FAIL results on this and adjacent middleware tests. Route both spinners through m.console.Handles().Stdout, matching the prompts in the same file. Under MockConsole this handle is io.Discard (no leakage in tests); in production it is the real stdout, so behavior is unchanged. --- cli/azd/cmd/middleware/tool_first_run.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cli/azd/cmd/middleware/tool_first_run.go b/cli/azd/cmd/middleware/tool_first_run.go index cabca55a8e6..9123ce15e52 100644 --- a/cli/azd/cmd/middleware/tool_first_run.go +++ b/cli/azd/cmd/middleware/tool_first_run.go @@ -230,6 +230,7 @@ func (m *ToolFirstRunMiddleware) runFirstRunExperience(ctx context.Context) erro detectSpinner := uxlib.NewSpinner(&uxlib.SpinnerOptions{ Text: "Detecting tools...", ClearOnStop: true, + Writer: m.console.Handles().Stdout, }) if err := detectSpinner.Run(ctx, func(ctx context.Context) error { var detectErr error @@ -416,6 +417,7 @@ func (m *ToolFirstRunMiddleware) offerInstall( installSpinner := uxlib.NewSpinner(&uxlib.SpinnerOptions{ Text: "Installing tools...", ClearOnStop: true, + Writer: m.console.Handles().Stdout, }) installErr := installSpinner.Run(ctx, func(ctx context.Context) error { var batchErr error