-
Notifications
You must be signed in to change notification settings - Fork 374
Add audit command suggestion to run command output #4445
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
2 commits
Select commit
Hold shift + click to select a range
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,128 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/githubnext/gh-aw/pkg/constants" | ||
| ) | ||
|
|
||
| // TestAuditSuggestionMessage tests that the audit suggestion message | ||
| // has the expected format and includes the CLI command prefix | ||
| func TestAuditSuggestionMessage(t *testing.T) { | ||
| // Sample run ID | ||
| runID := int64(1234567890) | ||
|
|
||
| // Generate the audit suggestion message | ||
| auditSuggestion := fmt.Sprintf("💡 To analyze this run, use: %s audit %d", constants.CLIExtensionPrefix, runID) | ||
|
|
||
| // Verify the message contains the expected elements | ||
| expectedElements := []string{ | ||
| "💡", // Lightbulb emoji for friendly suggestion | ||
| "To analyze this run", | ||
| "use:", | ||
| constants.CLIExtensionPrefix, // Should be "gh aw" | ||
| "audit", | ||
| fmt.Sprintf("%d", runID), | ||
| } | ||
|
|
||
| for _, element := range expectedElements { | ||
| if !strings.Contains(auditSuggestion, element) { | ||
| t.Errorf("Expected audit suggestion to contain %q, got: %s", element, auditSuggestion) | ||
| } | ||
| } | ||
|
|
||
| // Verify the full command format | ||
| expectedCommand := fmt.Sprintf("%s audit %d", constants.CLIExtensionPrefix, runID) | ||
| if !strings.Contains(auditSuggestion, expectedCommand) { | ||
| t.Errorf("Expected audit suggestion to contain full command %q, got: %s", expectedCommand, auditSuggestion) | ||
| } | ||
| } | ||
|
|
||
| // TestAuditSuggestionMessageFormat tests the exact format of the audit suggestion | ||
| func TestAuditSuggestionMessageFormat(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| runID int64 | ||
| expected string | ||
| }{ | ||
| { | ||
| name: "small run ID", | ||
| runID: 123, | ||
| expected: "💡 To analyze this run, use: gh aw audit 123", | ||
| }, | ||
| { | ||
| name: "large run ID", | ||
| runID: 9876543210, | ||
| expected: "💡 To analyze this run, use: gh aw audit 9876543210", | ||
| }, | ||
| { | ||
| name: "typical run ID", | ||
| runID: 1234567890, | ||
| expected: "💡 To analyze this run, use: gh aw audit 1234567890", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| // Generate the audit suggestion message | ||
| auditSuggestion := fmt.Sprintf("💡 To analyze this run, use: %s audit %d", constants.CLIExtensionPrefix, tt.runID) | ||
|
|
||
| // Verify exact format | ||
| if auditSuggestion != tt.expected { | ||
| t.Errorf("Expected audit suggestion %q, got %q", tt.expected, auditSuggestion) | ||
| } | ||
|
|
||
| // Verify it's agent-friendly (clear, actionable, no ambiguity) | ||
| if !strings.HasPrefix(auditSuggestion, "💡") { | ||
| t.Error("Expected audit suggestion to start with lightbulb emoji for friendliness") | ||
| } | ||
|
|
||
| if !strings.Contains(auditSuggestion, "To analyze this run") { | ||
| t.Error("Expected audit suggestion to clearly state the purpose") | ||
| } | ||
|
|
||
| if !strings.Contains(auditSuggestion, "use:") { | ||
| t.Error("Expected audit suggestion to provide clear action keyword 'use:'") | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // TestAuditSuggestionAgentFriendliness tests that the message is suitable for AI agents | ||
| func TestAuditSuggestionAgentFriendliness(t *testing.T) { | ||
| runID := int64(1234567890) | ||
| auditSuggestion := fmt.Sprintf("💡 To analyze this run, use: %s audit %d", constants.CLIExtensionPrefix, runID) | ||
|
|
||
| // Agent-friendly characteristics: | ||
| // 1. Clear action verb ("use") | ||
| if !strings.Contains(auditSuggestion, "use:") { | ||
| t.Error("Expected clear action verb 'use:'") | ||
| } | ||
|
|
||
| // 2. Specific command (not just a hint) | ||
| if !strings.Contains(auditSuggestion, "gh aw audit") { | ||
| t.Error("Expected specific command 'gh aw audit'") | ||
| } | ||
|
|
||
| // 3. Includes the run ID (no need to look it up) | ||
| if !strings.Contains(auditSuggestion, fmt.Sprintf("%d", runID)) { | ||
| t.Error("Expected run ID to be included in the command") | ||
| } | ||
|
|
||
| // 4. Not too wordy (agents prefer concise) | ||
| wordCount := len(strings.Fields(auditSuggestion)) | ||
| if wordCount > 15 { | ||
| t.Errorf("Expected concise message (< 15 words), got %d words", wordCount) | ||
| } | ||
|
|
||
| // 5. No ambiguous pronouns or references | ||
| // Note: "this run" is acceptable as it refers to the just-triggered workflow run | ||
| auditSuggestionLower := strings.ToLower(auditSuggestion) | ||
| if strings.Contains(auditSuggestionLower, " it ") || | ||
| strings.Contains(auditSuggestionLower, "this one") || | ||
| strings.Contains(auditSuggestionLower, " that ") { | ||
| t.Error("Expected no ambiguous references like 'it', 'this one', 'that'") | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codebase uses
console.FormatInfoMessage()for informational messages with emojis to maintain consistent styling across the CLI. This pattern is used in other parts of the codebase (e.g.,mcp_inspect_mcp.goline 533, 568).Consider using:
This ensures the message uses the standard info message styling (with ℹ prefix) applied by
FormatInfoMessage().