-
Notifications
You must be signed in to change notification settings - Fork 287
feat: add ASCII art banner and related tests #7214
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
00c100f
feat: add ASCII art banner and related tests for agent initialization
therealjohn d11c7ad
refactor: update printBanner call to use command output stream
therealjohn 766f91f
update extension manifest description to match.
therealjohn 509890b
fix lint errors, banner errors are non critical
therealjohn 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io" | ||
| "strings" | ||
|
|
||
| "azureaiagent/internal/version" | ||
|
|
||
| "github.com/fatih/color" | ||
| ) | ||
|
|
||
| // ASCII art using ANSI Shadow font for "FOUNDRY". | ||
| // Visual width is 61 columns; each box-drawing character is one display column | ||
| // but occupies multiple UTF-8 bytes, so len() over-counts. Tests use | ||
| // rune-aware width measurement. | ||
| const bannerArt = `███████╗ ██████╗ ██╗ ██╗███╗ ██╗██████╗ ██████╗ ██╗ ██╗ | ||
| ██╔════╝██╔═══██╗██║ ██║████╗ ██║██╔══██╗██╔══██╗╚██╗ ██╔╝ | ||
| █████╗ ██║ ██║██║ ██║██╔██╗ ██║██║ ██║██████╔╝ ╚████╔╝ | ||
| ██╔══╝ ██║ ██║██║ ██║██║╚██╗██║██║ ██║██╔══██╗ ╚██╔╝ | ||
| ██║ ╚██████╔╝╚██████╔╝██║ ╚████║██████╔╝██║ ██║ ██║ | ||
| ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ | ||
| ` | ||
|
|
||
| func printBanner(w io.Writer) { | ||
| purple := color.RGB(109, 53, 255).Add(color.Bold) | ||
| dim := color.New(color.Faint) | ||
| fmt.Fprintln(w) | ||
|
|
||
| for line := range strings.SplitSeq(bannerArt, "\n") { | ||
| purple.Fprintln(w, line) //nolint:gosec // G104 - banner output errors are non-critical | ||
| } | ||
|
|
||
| dim.Fprintf(w, "v%s", version.Version) //nolint:gosec // G104 - banner output errors are non-critical | ||
| fmt.Fprint(w, " ") | ||
| fmt.Fprintln(w) | ||
| dim.Fprintln(w, "Visit the docs at https://aka.ms/azd-ai-agent-docs") //nolint:gosec // G104 - banner output errors are non-critical | ||
| fmt.Fprintln(w) | ||
| } |
71 changes: 71 additions & 0 deletions
71
cli/azd/extensions/azure.ai.agents/internal/cmd/banner_test.go
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,71 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "strings" | ||
| "testing" | ||
| "unicode/utf8" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // displayWidth returns the number of runes (visual columns) in s. | ||
| // Box-drawing and block characters are each one column wide, but multi-byte | ||
| // in UTF-8, so we count runes instead of bytes. | ||
| func displayWidth(s string) int { | ||
| return utf8.RuneCountInString(s) | ||
| } | ||
|
|
||
| func TestBannerFitsWithin100Columns(t *testing.T) { | ||
| for i, line := range strings.Split(bannerArt, "\n") { | ||
| w := displayWidth(line) | ||
| assert.LessOrEqualf(t, w, 100, | ||
| "banner line %d exceeds 100 columns (%d runes): %q", i+1, w, line) | ||
| } | ||
| } | ||
|
|
||
| func TestPrintBannerWritesOutput(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| printBanner(&buf) | ||
|
|
||
| output := buf.String() | ||
| require.NotEmpty(t, output, "printBanner should produce output when writing to a buffer") | ||
| assert.Contains(t, output, "██", "banner should contain block-drawing characters") | ||
| assert.Contains(t, output, "https://aka.ms/azd-ai-agent-docs", "banner should contain the docs link") | ||
| } | ||
|
|
||
| func TestPrintBannerAllLinesFit100Cols(t *testing.T) { | ||
| var buf bytes.Buffer | ||
| printBanner(&buf) | ||
|
|
||
| for i, line := range strings.Split(buf.String(), "\n") { | ||
| clean := stripAnsi(line) | ||
| w := displayWidth(clean) | ||
| assert.LessOrEqualf(t, w, 100, | ||
| "rendered line %d exceeds 100 columns (%d runes): %q", i+1, w, clean) | ||
| } | ||
| } | ||
|
|
||
| // stripAnsi removes ANSI escape sequences from a string. | ||
| func stripAnsi(s string) string { | ||
| var out strings.Builder | ||
| inEsc := false | ||
| for _, r := range s { | ||
| if r == '\x1b' { | ||
| inEsc = true | ||
| continue | ||
| } | ||
| if inEsc { | ||
| if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') { | ||
| inEsc = false | ||
| } | ||
| continue | ||
| } | ||
| out.WriteRune(r) | ||
| } | ||
| return out.String() | ||
| } |
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
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.