-
Notifications
You must be signed in to change notification settings - Fork 307
Set default max to 1 for assign-to-agent safe-output #14867
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
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,208 @@ | ||
| //go:build !integration | ||
|
|
||
| package workflow | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/github/gh-aw/pkg/testutil" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestAssignToAgentDefaultMax tests that assign-to-agent has a default max of 1 | ||
| func TestAssignToAgentDefaultMax(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "assign-to-agent-default-max-test") | ||
|
|
||
| // Create a workflow with assign-to-agent but no explicit max | ||
| workflow := `--- | ||
| on: issues | ||
| engine: copilot | ||
| permissions: | ||
| contents: read | ||
| safe-outputs: | ||
| assign-to-agent: | ||
| name: copilot | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| This workflow tests the default max for assign-to-agent. | ||
| ` | ||
| testFile := filepath.Join(tmpDir, "test-assign-to-agent.md") | ||
| err := os.WriteFile(testFile, []byte(workflow), 0644) | ||
| require.NoError(t, err, "Failed to write test workflow") | ||
|
|
||
| // Parse the workflow | ||
| compiler := NewCompilerWithVersion("1.0.0") | ||
| workflowData, err := compiler.ParseWorkflowFile(testFile) | ||
| require.NoError(t, err, "Failed to parse workflow") | ||
|
|
||
| // Verify assign-to-agent config exists and has default max of 1 | ||
| require.NotNil(t, workflowData.SafeOutputs, "SafeOutputs should not be nil") | ||
| require.NotNil(t, workflowData.SafeOutputs.AssignToAgent, "AssignToAgent should not be nil") | ||
| assert.Equal(t, 1, workflowData.SafeOutputs.AssignToAgent.Max, "Default max should be 1") | ||
| } | ||
|
|
||
| // TestDispatchWorkflowDefaultMax tests that dispatch-workflow has a default max of 1 | ||
| func TestDispatchWorkflowDefaultMax(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "dispatch-workflow-default-max-test") | ||
| workflowsDir := filepath.Join(tmpDir, ".github", "workflows") | ||
|
|
||
| err := os.MkdirAll(workflowsDir, 0755) | ||
| require.NoError(t, err, "Failed to create workflows directory") | ||
|
|
||
| // Create a target workflow with workflow_dispatch | ||
| targetWorkflow := `name: Target | ||
| on: | ||
| workflow_dispatch: | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: echo "Target workflow" | ||
| ` | ||
| targetFile := filepath.Join(workflowsDir, "target.lock.yml") | ||
| err = os.WriteFile(targetFile, []byte(targetWorkflow), 0644) | ||
| require.NoError(t, err, "Failed to write target workflow") | ||
|
|
||
| // Create a dispatcher workflow with dispatch-workflow but no explicit max | ||
| workflow := `--- | ||
| on: issues | ||
| engine: copilot | ||
| permissions: | ||
| contents: read | ||
| safe-outputs: | ||
| dispatch-workflow: | ||
| - target | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| This workflow tests the default max for dispatch-workflow. | ||
| ` | ||
| testFile := filepath.Join(tmpDir, "test-dispatch.md") | ||
| err = os.WriteFile(testFile, []byte(workflow), 0644) | ||
| require.NoError(t, err, "Failed to write test workflow") | ||
|
|
||
| // Parse the workflow | ||
| compiler := NewCompilerWithVersion("1.0.0") | ||
| workflowData, err := compiler.ParseWorkflowFile(testFile) | ||
| require.NoError(t, err, "Failed to parse workflow") | ||
|
|
||
| // Verify dispatch-workflow config exists and has default max of 1 | ||
| require.NotNil(t, workflowData.SafeOutputs, "SafeOutputs should not be nil") | ||
| require.NotNil(t, workflowData.SafeOutputs.DispatchWorkflow, "DispatchWorkflow should not be nil") | ||
| assert.Equal(t, 1, workflowData.SafeOutputs.DispatchWorkflow.Max, "Default max should be 1") | ||
| } | ||
|
|
||
| // TestAssignToAgentExplicitMax tests that explicit max overrides the default | ||
| func TestAssignToAgentExplicitMax(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "assign-to-agent-explicit-max-test") | ||
|
|
||
| // Create a workflow with assign-to-agent with explicit max | ||
| workflow := `--- | ||
| on: issues | ||
| engine: copilot | ||
| permissions: | ||
| contents: read | ||
| safe-outputs: | ||
| assign-to-agent: | ||
| name: copilot | ||
| max: 5 | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| This workflow tests explicit max for assign-to-agent. | ||
| ` | ||
| testFile := filepath.Join(tmpDir, "test-assign-to-agent.md") | ||
| err := os.WriteFile(testFile, []byte(workflow), 0644) | ||
| require.NoError(t, err, "Failed to write test workflow") | ||
|
|
||
| // Parse the workflow | ||
| compiler := NewCompilerWithVersion("1.0.0") | ||
| workflowData, err := compiler.ParseWorkflowFile(testFile) | ||
| require.NoError(t, err, "Failed to parse workflow") | ||
|
|
||
| // Verify assign-to-agent config has explicit max of 5 | ||
| require.NotNil(t, workflowData.SafeOutputs, "SafeOutputs should not be nil") | ||
| require.NotNil(t, workflowData.SafeOutputs.AssignToAgent, "AssignToAgent should not be nil") | ||
| assert.Equal(t, 5, workflowData.SafeOutputs.AssignToAgent.Max, "Explicit max should be 5") | ||
| } | ||
|
|
||
| // TestDispatchWorkflowExplicitMax tests that explicit max overrides the default | ||
| func TestDispatchWorkflowExplicitMax(t *testing.T) { | ||
| tmpDir := testutil.TempDir(t, "dispatch-workflow-explicit-max-test") | ||
| workflowsDir := filepath.Join(tmpDir, ".github", "workflows") | ||
|
|
||
| err := os.MkdirAll(workflowsDir, 0755) | ||
| require.NoError(t, err, "Failed to create workflows directory") | ||
|
|
||
| // Create a target workflow with workflow_dispatch | ||
| targetWorkflow := `name: Target | ||
| on: | ||
| workflow_dispatch: | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - run: echo "Target workflow" | ||
| ` | ||
| targetFile := filepath.Join(workflowsDir, "target.lock.yml") | ||
| err = os.WriteFile(targetFile, []byte(targetWorkflow), 0644) | ||
| require.NoError(t, err, "Failed to write target workflow") | ||
|
|
||
| // Create a dispatcher workflow with explicit max | ||
| workflow := `--- | ||
| on: issues | ||
| engine: copilot | ||
| permissions: | ||
| contents: read | ||
| safe-outputs: | ||
| dispatch-workflow: | ||
| workflows: | ||
| - target | ||
| max: 3 | ||
| --- | ||
|
|
||
| # Test Workflow | ||
|
|
||
| This workflow tests explicit max for dispatch-workflow. | ||
| ` | ||
| testFile := filepath.Join(tmpDir, "test-dispatch.md") | ||
| err = os.WriteFile(testFile, []byte(workflow), 0644) | ||
| require.NoError(t, err, "Failed to write test workflow") | ||
|
|
||
| // Parse the workflow | ||
| compiler := NewCompilerWithVersion("1.0.0") | ||
| workflowData, err := compiler.ParseWorkflowFile(testFile) | ||
| require.NoError(t, err, "Failed to parse workflow") | ||
|
|
||
| // Verify dispatch-workflow config has explicit max of 3 | ||
| require.NotNil(t, workflowData.SafeOutputs, "SafeOutputs should not be nil") | ||
| require.NotNil(t, workflowData.SafeOutputs.DispatchWorkflow, "DispatchWorkflow should not be nil") | ||
| assert.Equal(t, 3, workflowData.SafeOutputs.DispatchWorkflow.Max, "Explicit max should be 3") | ||
| } | ||
|
|
||
| // TestGenerateAssignToAgentConfigDefaultMax tests the config generation with default max | ||
| func TestGenerateAssignToAgentConfigDefaultMax(t *testing.T) { | ||
| // Test with max=0 (should use default of 1) | ||
| config := generateAssignToAgentConfig(0, 1, "copilot", "", nil) | ||
| assert.Equal(t, 1, config["max"], "Should use default max of 1 when max is 0") | ||
| assert.Equal(t, "copilot", config["default_agent"], "Should have default agent") | ||
|
|
||
| // Test with explicit max (should override default) | ||
| config = generateAssignToAgentConfig(5, 1, "copilot", "", nil) | ||
| assert.Equal(t, 5, config["max"], "Should use explicit max of 5") | ||
| assert.Equal(t, "copilot", config["default_agent"], "Should have default agent") | ||
|
|
||
| // Test with target and allowed | ||
| config = generateAssignToAgentConfig(0, 1, "copilot", "issues", []string{"copilot", "custom"}) | ||
| assert.Equal(t, 1, config["max"], "Should use default max of 1") | ||
| assert.Equal(t, "copilot", config["default_agent"], "Should have default agent") | ||
| assert.Equal(t, "issues", config["target"], "Should have target") | ||
| assert.Equal(t, []string{"copilot", "custom"}, config["allowed"], "Should have allowed list") | ||
| } |
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 error handling path returns an empty AssignToAgentConfig without setting Max to the default value of 1. While the config generation layer will apply the default later, it would be more consistent with other parsers like assign-to-user (line 31-33 in assign_to_user.go) to set the default in the error case as well. Consider:
return &AssignToAgentConfig{BaseSafeOutputConfig: BaseSafeOutputConfig{Max: 1}}See below for a potential fix: