Skip to content

fix: disallow --name flag when adding multiple workflows at once#28195

Merged
pelikhan merged 3 commits intomainfrom
copilot/add-support-multiple-workflows
Apr 24, 2026
Merged

fix: disallow --name flag when adding multiple workflows at once#28195
pelikhan merged 3 commits intomainfrom
copilot/add-support-multiple-workflows

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

Summary

The gh aw add command supports adding multiple workflows at once:

gh aw add workflow1 workflow2 ...

This PR adds a validation error when the --name flag is used alongside multiple workflow arguments, since a single custom name cannot meaningfully apply to multiple workflows.

Error: --name flag cannot be used when adding multiple workflows at once

Changes

  • pkg/cli/add_command.go: Added an early check in RunE that returns an error if --name is set and more than one workflow argument is provided. Updated the help text to state that --name is not allowed when adding multiple workflows.
  • pkg/cli/add_command_test.go: Added TestAddMultipleWorkflowsNameFlag to verify the error is returned when --name is combined with multiple workflow arguments.
  • .changeset/patch-add-multiple-workflows.md: Changeset entry for this fix.

Copy link
Copy Markdown
Collaborator

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot --name is not allowed when multiple workflows are specified.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 24, 2026

@copilot --name is not allowed when multiple workflows are specified.

Done in 115cbc6. --name now returns an error when multiple workflow arguments are provided:

Error: --name flag cannot be used when adding multiple workflows at once

Also updated the help text and replaced the previous "silently apply to first" test with one that verifies the error.

Copilot AI changed the title fix: apply --name flag only to first workflow when adding multiple (#add-multi-workflow) fix: disallow --name flag when adding multiple workflows at once Apr 24, 2026
Copilot AI requested a review from pelikhan April 24, 2026 05:03
@pelikhan pelikhan marked this pull request as ready for review April 24, 2026 05:44
Copilot AI review requested due to automatic review settings April 24, 2026 05:44
@github-actions
Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Test Quality Score: 100/100

Excellent test quality

Metric Value
New/modified tests analyzed 1
✅ Design tests (behavioral contracts) 1 (100%)
⚠️ Implementation tests (low value) 0 (0%)
Tests with error/edge cases 1 (100%)
Duplicate test clusters 0
Test inflation detected No
🚨 Coding-guideline violations None

Test Classification Details

Test File Classification Issues Detected
TestAddMultipleWorkflowsNameFlag pkg/cli/add_command_test.go:340 ✅ Design

Language Support

Tests analyzed:

  • 🐹 Go (*_test.go): 1 test — unit (//go:build !integration)

Verdict

Check passed. 0% of new tests are implementation tests (threshold: 30%).

The new test TestAddMultipleWorkflowsNameFlag verifies the behavioral contract directly: it invokes the command with --name and multiple workflow arguments and asserts that an error is returned with the appropriate message. Both require.Error and assert.Contains include descriptive messages. Build tag is correctly set. No mock libraries used.

📖 Understanding Test Classifications

Design Tests (High Value) verify what the system does:

  • Assert on observable outputs, return values, or state changes
  • Cover error paths and boundary conditions
  • Would catch a behavioral regression if deleted
  • Remain valid even after internal refactoring

Implementation Tests (Low Value) verify how the system does it:

  • Assert on internal function calls (mocking internals)
  • Only test the happy path with typical inputs
  • Break during legitimate refactoring even when behavior is correct
  • Give false assurance: they pass even when the system is wrong

Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.

References: §24874320128

🧪 Test quality analysis by Test Quality Sentinel · ● 363.3K ·

@github-actions github-actions Bot mentioned this pull request Apr 24, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 100/100. Test quality is excellent — 0% of new tests are implementation tests (threshold: 30%).

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 RunE validation error when --name is used with multiple workflow arguments.
  • Update gh aw add help text to clarify the --name restriction.
  • Add a unit test covering --name with 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

Comment thread pkg/cli/add_command.go
Comment on lines +105 to +107
if nameFlag != "" && len(workflows) > 1 {
return errors.New("--name flag cannot be used when adding multiple workflows at once")
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
"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.
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +343 to +350
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")
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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")
})
}

Copilot uses AI. Check for mistakes.
@github-actions github-actions Bot added the lgtm label Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Great work on this fix, @Copilot! 🎉 The validation for disallowing --name when multiple workflows are specified is clean, well-scoped, and includes a dedicated test case (TestAddMultipleWorkflowsNameFlag) along with an updated help string and changeset entry. This PR looks ready for maintainer review!

Generated by Contribution Check · ● 1.5M ·

@pelikhan pelikhan merged commit 0775d65 into main Apr 24, 2026
40 checks passed
@pelikhan pelikhan deleted the copilot/add-support-multiple-workflows branch April 24, 2026 05:54
github-actions Bot added a commit that referenced this pull request Apr 24, 2026
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants