-
Notifications
You must be signed in to change notification settings - Fork 28
Show available workflows when workflow not found in add command #3402
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,207 @@ | ||||||||||
| package cli | ||||||||||
|
|
||||||||||
| import ( | ||||||||||
| "bytes" | ||||||||||
| "os" | ||||||||||
| "path/filepath" | ||||||||||
| "strings" | ||||||||||
| "testing" | ||||||||||
| ) | ||||||||||
|
|
||||||||||
| // TestDisplayAvailableWorkflows tests that displayAvailableWorkflows shows the list of available workflows | ||||||||||
| func TestDisplayAvailableWorkflows(t *testing.T) { | ||||||||||
| // Create a temporary packages directory structure | ||||||||||
| tempDir := t.TempDir() | ||||||||||
|
|
||||||||||
| // Override packages directory for testing | ||||||||||
| oldHome := os.Getenv("HOME") | ||||||||||
| os.Setenv("HOME", tempDir) | ||||||||||
| defer os.Setenv("HOME", oldHome) | ||||||||||
|
|
||||||||||
| // Create a mock package structure | ||||||||||
| packagePath := filepath.Join(tempDir, ".aw", "packages", "test-owner", "test-repo") | ||||||||||
| workflowsDir := filepath.Join(packagePath, "workflows") | ||||||||||
| if err := os.MkdirAll(workflowsDir, 0755); err != nil { | ||||||||||
| t.Fatalf("Failed to create test directories: %v", err) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Create some mock workflow files with valid frontmatter | ||||||||||
| validWorkflowContent := `--- | ||||||||||
| on: push | ||||||||||
| --- | ||||||||||
| # Test Workflow | ||||||||||
| ` | ||||||||||
|
|
||||||||||
| workflows := []string{ | ||||||||||
| "ci-doctor.md", | ||||||||||
| "daily-plan.md", | ||||||||||
| "weekly-summary.md", | ||||||||||
| } | ||||||||||
|
|
||||||||||
| for _, wf := range workflows { | ||||||||||
| wfPath := filepath.Join(workflowsDir, wf) | ||||||||||
| if err := os.WriteFile(wfPath, []byte(validWorkflowContent), 0644); err != nil { | ||||||||||
| t.Fatalf("Failed to create workflow file %s: %v", wf, err) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Capture stderr output | ||||||||||
| oldStderr := os.Stderr | ||||||||||
| r, w, _ := os.Pipe() | ||||||||||
| os.Stderr = w | ||||||||||
|
|
||||||||||
| // Call displayAvailableWorkflows | ||||||||||
| err := displayAvailableWorkflows("test-owner/test-repo", "", false) | ||||||||||
|
|
||||||||||
| // Restore stderr and capture output | ||||||||||
| w.Close() | ||||||||||
| os.Stderr = oldStderr | ||||||||||
| var buf bytes.Buffer | ||||||||||
| buf.ReadFrom(r) | ||||||||||
|
||||||||||
| buf.ReadFrom(r) | |
| if _, err := buf.ReadFrom(r); err != nil { | |
| t.Fatalf("Failed to read from pipe: %v", err) | |
| } |
pelikhan marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Nov 7, 2025
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.
Missing error check: The return value from buf.ReadFrom(r) is not checked. While this is unlikely to fail in tests, it's best practice to check errors, especially since other I/O operations in the same tests do check errors.
| buf.ReadFrom(r) | |
| if _, err := buf.ReadFrom(r); err != nil { | |
| t.Fatalf("Failed to read from pipe: %v", err) | |
| } |
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.
Duplicated workflow name extraction logic: The logic for extracting workflow names from paths (lines 320-326) is duplicated almost identically in lines 344-348 for the example workflow. Consider extracting this into a small helper function to avoid code duplication and make the logic easier to maintain.