Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pkg/workflow/mcp_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (

"slices"

"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/logger"
)

Expand Down Expand Up @@ -189,6 +190,13 @@ func collectMCPEnvironmentVariables(tools map[string]any, mcpTools []string, wor
}
}

// Codex engine needs CODEX_HOME available in the gateway setup step so that
// the converted MCP config can be copied into the writable Codex home directory.
// This matches the value set on the agent step in codex_engine.go.
if workflowData != nil && workflowData.AI == string(constants.CodexEngine) {
envVars["CODEX_HOME"] = "/tmp/gh-aw/mcp-config"
}
Comment on lines +193 to +198
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

The CODEX_HOME env var is currently gated on workflowData.AI == "codex" (the logical engine ID). This will miss custom engine definitions that are backed by the Codex runtime via engine.definition.runtime-id (supported by the EngineCatalog), and those workflows would still hit the same empty ${CODEX_HOME} failure when the Codex runtime emits CODEX_HOME references in the gateway step. Consider keying this off the resolved runtime adapter instead (e.g., pass the CodingAgentEngine into collectMCPEnvironmentVariables and check engine.GetID() == string(constants.CodexEngine)).

Copilot uses AI. Check for mistakes.

return envVars
}

Expand Down
37 changes: 37 additions & 0 deletions pkg/workflow/mcp_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,40 @@ func TestOIDCEnvVarsNotInDockerCommandWithoutOIDCAuth(t *testing.T) {
assert.NotContains(t, output, "-e ACTIONS_ID_TOKEN_REQUEST_TOKEN",
"Docker command should NOT include OIDC env vars without github-oidc auth")
}

// TestCollectMCPEnvironmentVariables_CodexEngineIncludesCODEXHOME verifies that
// CODEX_HOME is included in the MCP gateway step environment for Codex engine workflows
func TestCollectMCPEnvironmentVariables_CodexEngineIncludesCODEXHOME(t *testing.T) {
tools := map[string]any{
"github": map[string]any{
"toolsets": []string{"repos"},
},
}
mcpTools := []string{"github"}
workflowData := &WorkflowData{AI: "codex"}

Comment on lines +187 to +189
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This test hardcodes the engine name as the string "codex". To avoid drift with the supported engine IDs, consider using string(constants.CodexEngine) (and similarly for the non-codex cases) so renames/aliases are caught at compile time.

Copilot uses AI. Check for mistakes.
envVars := collectMCPEnvironmentVariables(tools, mcpTools, workflowData, false)

assert.Equal(t, "/tmp/gh-aw/mcp-config", envVars["CODEX_HOME"],
"CODEX_HOME should be set to /tmp/gh-aw/mcp-config for Codex engine")
}

// TestCollectMCPEnvironmentVariables_NonCodexEngineExcludesCODEXHOME verifies that
// CODEX_HOME is NOT included for non-Codex engine workflows
func TestCollectMCPEnvironmentVariables_NonCodexEngineExcludesCODEXHOME(t *testing.T) {
tools := map[string]any{
"github": map[string]any{
"toolsets": []string{"repos"},
},
}
mcpTools := []string{"github"}

for _, engine := range []string{"copilot", "claude", ""} {
t.Run("engine="+engine, func(t *testing.T) {
workflowData := &WorkflowData{AI: engine}
envVars := collectMCPEnvironmentVariables(tools, mcpTools, workflowData, false)
assert.NotContains(t, envVars, "CODEX_HOME",
"CODEX_HOME should not be set for %s engine", engine)
})
}
}
Loading