fix: disallow --name flag when adding multiple workflows at once#28195
fix: disallow --name flag when adding multiple workflows at once#28195
Conversation
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a25578bc-adfa-4662-9d96-202ed66c72ca Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a25578bc-adfa-4662-9d96-202ed66c72ca Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/b7ed7694-7a0d-49f2-b0d5-15df8bd4a149 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in 115cbc6. Also updated the help text and replaced the previous "silently apply to first" test with one that verifies the error. |
🧪 Test Quality Sentinel ReportTest Quality Score: 100/100✅ Excellent test quality
Test Classification Details
Language SupportTests analyzed:
Verdict
The new test 📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators. References: §24874320128
|
There was a problem hiding this comment.
Pull request overview
Adds CLI validation to prevent using a single --name value when adding multiple workflows via gh aw add, and updates tests and release notes accordingly.
Changes:
- Add an early
RunEvalidation error when--nameis used with multiple workflow arguments. - Update
gh aw addhelp text to clarify the--namerestriction. - Add a unit test covering
--namewith multiple workflow args; add a changeset entry.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/add_command.go |
Adds validation and updates help text for --name with multiple workflows. |
pkg/cli/add_command_test.go |
Adds a test asserting an error when --name is combined with multiple workflow args. |
.changeset/patch-add-multiple-workflows.md |
Documents the fix in release notes (currently mismatched with implemented behavior). |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 3
| if nameFlag != "" && len(workflows) > 1 { | ||
| return errors.New("--name flag cannot be used when adding multiple workflows at once") | ||
| } |
There was a problem hiding this comment.
The validation only triggers when nameFlag != "" and len(args) > 1, which still allows using --name in cases where a single argument resolves to multiple workflows (e.g., local wildcard patterns) and also allows --name="" since the value remains empty. To fully enforce “flag cannot be used when adding multiple workflows”, consider checking cmd.Flags().Changed("name") and validating against the number of resolved workflows (or pre-expanding local wildcards) rather than only len(args) and a non-empty string value.
| "gh-aw": patch | ||
| --- | ||
|
|
||
| Fix `--name` flag to only apply to the first workflow when adding multiple workflows with `gh aw add workflow1 workflow2 ...`. Previously the name was applied to all workflows, causing each to overwrite the previous one. |
There was a problem hiding this comment.
The changeset text says the fix makes --name “only apply to the first workflow when adding multiple workflows”, but this PR’s behavior (and the CLI help/error) disallows --name entirely when adding multiple workflows. The changeset should be updated to describe the actual behavior change (disallowing --name with multiple workflows) to avoid publishing incorrect release notes.
| cmd := NewAddCommand(validateEngineStub) | ||
|
|
||
| // Simulate calling the command with --name and multiple workflow arguments | ||
| cmd.SetArgs([]string{"workflow1", "workflow2", "--name", "custom-name"}) | ||
|
|
||
| err := cmd.Execute() | ||
| require.Error(t, err, "Should error when --name is used with multiple workflows") | ||
| assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction") |
There was a problem hiding this comment.
This test covers the multiple-args case, but it doesn’t exercise other “multiple workflows at once” paths that the new restriction likely intends to cover, such as a single local wildcard argument that resolves to multiple workflows, or --name="" (flag present but empty). Adding tests for these cases would help prevent regressions once the validation is tightened.
| cmd := NewAddCommand(validateEngineStub) | |
| // Simulate calling the command with --name and multiple workflow arguments | |
| cmd.SetArgs([]string{"workflow1", "workflow2", "--name", "custom-name"}) | |
| err := cmd.Execute() | |
| require.Error(t, err, "Should error when --name is used with multiple workflows") | |
| assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction") | |
| tests := []struct { | |
| name string | |
| args []string | |
| }{ | |
| { | |
| name: "non-empty name with multiple workflow arguments", | |
| args: []string{"workflow1", "workflow2", "--name", "custom-name"}, | |
| }, | |
| { | |
| name: "explicitly empty name with multiple workflow arguments", | |
| args: []string{"workflow1", "workflow2", "--name="}, | |
| }, | |
| } | |
| for _, tt := range tests { | |
| t.Run(tt.name, func(t *testing.T) { | |
| cmd := NewAddCommand(validateEngineStub) | |
| // Simulate calling the command with --name and multiple workflow arguments | |
| cmd.SetArgs(tt.args) | |
| err := cmd.Execute() | |
| require.Error(t, err, "Should error when --name is used with multiple workflows") | |
| assert.Contains(t, err.Error(), "--name flag cannot be used when adding multiple workflows", "Error should mention --name restriction") | |
| }) | |
| } |
|
Great work on this fix,
|
…tic-optimization-kit page - Update setup/cli.md: note that --name cannot be used when adding multiple workflows at once (from PR #28195); add multi-workflow add example and single-workflow --name example - Create patterns/agentic-optimization-kit.md: new reference page for the weekly Agentic Optimization Kit workflow covering its three phases, five diagnostic charts, report structure, escalation conditions, metric glossary, and relationship to the Observability Kit - Update astro.config.mjs: add Agentic Optimization Kit to sidebar Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
The
gh aw addcommand supports adding multiple workflows at once:This PR adds a validation error when the
--nameflag is used alongside multiple workflow arguments, since a single custom name cannot meaningfully apply to multiple workflows.Changes
pkg/cli/add_command.go: Added an early check inRunEthat returns an error if--nameis set and more than one workflow argument is provided. Updated the help text to state that--nameis not allowed when adding multiple workflows.pkg/cli/add_command_test.go: AddedTestAddMultipleWorkflowsNameFlagto verify the error is returned when--nameis combined with multiple workflow arguments..changeset/patch-add-multiple-workflows.md: Changeset entry for this fix.