Skip to content

Commit ac43855

Browse files
Copilotpelikhan
andcommitted
Fix github:false edge case - skip fallback when GitHub MCP tool is explicitly disabled
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 8ade6cb commit ac43855

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

pkg/workflow/compiler_orchestrator_workflow.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,10 @@ func applyTopLevelGitHubAppFallbacks(data *WorkflowData) {
636636

637637
// Fallback for tools.github (MCP GitHub token minting).
638638
// Skip when a custom github-token is already configured for the MCP server (token takes priority).
639+
// Also skip when tools.github is explicitly disabled (github: false) — do not re-enable it.
639640
if data.ParsedTools != nil && data.ParsedTools.GitHub != nil &&
640-
data.ParsedTools.GitHub.GitHubApp == nil && data.ParsedTools.GitHub.GitHubToken == "" {
641+
data.ParsedTools.GitHub.GitHubApp == nil && data.ParsedTools.GitHub.GitHubToken == "" &&
642+
data.Tools["github"] != false {
641643
orchestratorWorkflowLog.Print("Applying top-level github-app fallback for tools.github")
642644
data.ParsedTools.GitHub.GitHubApp = fallback
643645
// Also update the raw tools map so applyDefaultTools (called from applyDefaults in
@@ -663,7 +665,7 @@ func applyTopLevelGitHubAppFallbacks(data *WorkflowData) {
663665
// Already a map; inject into existing settings.
664666
github["github-app"] = appMap
665667
} else {
666-
// Non-map value (e.g. true/false) — create a fresh map preserving the enabled signal.
668+
// Non-map value (e.g. true) — create a fresh map.
667669
data.Tools["github"] = map[string]any{"github-app": appMap}
668670
}
669671
}

pkg/workflow/top_level_github_app_import_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,52 @@ When tools.github.github-token is set, the top-level github-app fallback should
190190
"tools.github.github-app should NOT be set when github-token is configured")
191191
}
192192

193+
// TestTopLevelGitHubAppToolsGitHubFalseSkip tests that the fallback is NOT applied
194+
// to tools.github when github is explicitly disabled (github: false).
195+
func TestTopLevelGitHubAppToolsGitHubFalseSkip(t *testing.T) {
196+
compiler := NewCompilerWithVersion("1.0.0")
197+
198+
tmpDir := t.TempDir()
199+
workflowsDir := filepath.Join(tmpDir, ".github", "workflows")
200+
require.NoError(t, os.MkdirAll(workflowsDir, 0755))
201+
202+
// Workflow with top-level github-app but tools.github explicitly disabled
203+
workflowContent := `---
204+
on: issues
205+
permissions:
206+
contents: read
207+
github-app:
208+
app-id: ${{ vars.APP_ID }}
209+
private-key: ${{ secrets.APP_PRIVATE_KEY }}
210+
tools:
211+
github: false
212+
engine: copilot
213+
---
214+
215+
# Workflow With GitHub Tool Explicitly Disabled
216+
217+
When tools.github is set to false, the top-level github-app fallback should NOT re-enable it.
218+
`
219+
mdPath := filepath.Join(workflowsDir, "main.md")
220+
require.NoError(t, os.WriteFile(mdPath, []byte(workflowContent), 0644))
221+
222+
origDir, err := os.Getwd()
223+
require.NoError(t, err)
224+
require.NoError(t, os.Chdir(workflowsDir))
225+
defer func() { _ = os.Chdir(origDir) }()
226+
227+
data, err := compiler.ParseWorkflowFile("main.md")
228+
require.NoError(t, err)
229+
230+
// The top-level github-app should be resolved at the top level
231+
require.NotNil(t, data.TopLevelGitHubApp, "TopLevelGitHubApp should be populated")
232+
233+
// tools.github should remain disabled — applyDefaultTools removes the key when false.
234+
// After compilation, ParsedTools.GitHub should be nil (no GitHub MCP tool enabled).
235+
assert.Nil(t, data.ParsedTools.GitHub,
236+
"ParsedTools.GitHub should be nil when tools.github: false — fallback must not re-enable it")
237+
}
238+
193239
// workflow is propagated to the activation job (reactions/status comments).
194240
func TestTopLevelGitHubAppImportActivation(t *testing.T) {
195241
compiler := NewCompilerWithVersion("1.0.0")

0 commit comments

Comments
 (0)