Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 28, 2025

Fix ASCII escape codes in URLs when running in non-terminal environments (GitHub Actions)

Changes

  • Analyze the issue and codebase
  • Modify output.WithHyperlink() to check terminal state and return raw URLs when not in a terminal
  • Modify ux.Hyperlink() to check terminal state and return raw URLs when not in a terminal
  • Create new internal/terminal package with IsTerminal() function
  • Update all callers to use the centralized terminal detection logic
  • Remove wrapper function in input.IsTerminal() - callers now use terminal.IsTerminal() directly
  • Simplify non-terminal output to return only URL (ignore text parameter)
  • Revert unrelated changes in extensions folder
  • Test the changes with unit tests
  • Build and verify the changes work correctly
  • Run linters and tests
  • Address all code review feedback

Technical Details

The issue occurs in two functions that generate ANSI hyperlink escape codes:

  1. cli/azd/pkg/output/colors.go - WithHyperlink() function
  2. cli/azd/pkg/ux/ux.go - Hyperlink() function

Both functions unconditionally generate ANSI escape codes like \033]8;;URL\007TEXT\033]8;;\007 which appear as raw escape sequences in GitHub Actions logs.

Solution Implemented

Created a new lower-level package cli/azd/internal/terminal that contains the IsTerminal() function with all the terminal detection logic:

  • Checks AZD_FORCE_TTY environment variable for user override
  • Detects CI environments via resource.IsRunningOnCI() and forces non-TTY mode
  • Uses isatty.IsTerminal() for both stdout and stdin as fallback

Non-terminal output simplified: When not in a terminal, both hyperlink functions now return just the raw URL, ignoring the text parameter. This matches the expected behavior shown in the issue screenshots.

Updated all callers:

  • cmd/container.go - Updated to call terminal.IsTerminal() directly
  • pkg/input/console.go - Removed wrapper function, callers now use terminal.IsTerminal() directly
  • pkg/output/colors.go - Updated WithHyperlink() to return only URL in non-terminal mode
  • pkg/ux/ux.go - Updated Hyperlink() to return only URL in non-terminal mode

This eliminates code duplication and provides a single source of truth for terminal detection across the codebase.

Files Modified

  1. cli/azd/internal/terminal/terminal.go: Centralized IsTerminal() function
  2. cli/azd/cmd/container.go: Updated to use terminal.IsTerminal() directly
  3. cli/azd/pkg/input/console.go: Removed IsTerminal() wrapper function
  4. cli/azd/pkg/output/colors.go: Simplified non-terminal output to return only URL
  5. cli/azd/pkg/output/colors_test.go: Updated test expectations
  6. cli/azd/pkg/ux/ux.go: Simplified non-terminal output to return only URL
  7. cli/azd/pkg/ux/ux_test.go: Updated test expectations
  8. cli/azd/.vscode/cspell.yaml: Added "surveyterm" to dictionary

Testing

  • ✅ All unit tests pass
  • ✅ Build succeeds
  • ✅ Linting passes
  • ✅ Project package tests pass
  • ✅ No circular dependencies

Expected Output

Before (with escape codes in GitHub Actions):

- Endpoint: 8;;https://ca-dyfj7t2wpgpp2.calmpond-0ace7c7d.westus.azurecontainerapps.io/https://ca-dyfj7t2wpgpp2.calmpond-0ace7c7d.westus.azurecontainerapps.io/8;;

After (clean URL in GitHub Actions):

- Endpoint: https://ca-dyfj7t2wpgpp2.calmpond-0ace7c7d.westus.azurecontainerapps.io/
Original prompt

This section details on the original issue you should resolve

<issue_title>[Issue] Endpoint output from running azd deploy contains ASCII escape codes + duplicated in GitHub Action</issue_title>
<issue_description>- [ ] Make sure you've installed the latest version using instructions

Output from azd version
Latest release? 1.20.1. All workflows were working until pipeline run #13 kicked off on Oct23: 10:59am. All #1-12 were run from Oct 17 - Oct 21 3:29pm.

Describe the bug
Working on Blog 3 for Dev to Prod.

  • ran azd pipeline config
  • checked pipeline log and saw this:
Image

To Reproduce
azd up
azd pipeline config

Expected behavior

Image

Environment
Information on your environment:
* GitHub Action

Additional context
Add any other context about the problem here.
</issue_description>

<agent_instructions>When IsTerminal() returns false we should return raw URLs instead of hyperlinked encoded URLs.

This check should hopefully be able to happen inside the helper function that writes the hyperlink so that all usage is automatically addressed.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@wbreza When the `azd` `IsTerminal()` returns false we need to fallback to print out raw URLs without hyperlink encoding.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix endpoint output containing ASCII escape codes Fix hyperlink ANSI escape codes appearing in non-terminal output Oct 28, 2025
Copilot finished work on behalf of wbreza October 28, 2025 18:04
Copilot AI requested a review from wbreza October 28, 2025 18:04
Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but requires a couple updates.

…t unrelated extension changes

Co-authored-by: hemarina <[email protected]>
Copilot finished work on behalf of hemarina October 28, 2025 18:44
Copilot AI requested a review from hemarina October 28, 2025 18:44
Copilot finished work on behalf of hemarina October 28, 2025 18:48
Copilot AI requested a review from wbreza October 28, 2025 19:13
Copilot finished work on behalf of wbreza October 28, 2025 19:13
Copy link
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more changes.

Copilot finished work on behalf of hemarina October 29, 2025 01:44
Copilot finished work on behalf of hemarina October 29, 2025 01:47
@wbreza wbreza marked this pull request as ready for review October 29, 2025 19:10
Copy link
Member

@vhvb1989 vhvb1989 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JeffreyCA
Copy link
Contributor

/check-enforcer override

Copy link
Contributor

@hemarina hemarina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hemarina hemarina merged commit 66929bc into main Oct 29, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue] Endpoint output from running azd deploy contains ASCII escape codes + duplicated in GitHub Action

5 participants