Skip to content

Commit 8ceb4dc

Browse files
[code-simplifier] refactor: extract resolveProxyContainerImage helper in compiler_difc_proxy (#25419) (#25435)
1 parent efde1b5 commit 8ceb4dc

2 files changed

Lines changed: 64 additions & 16 deletions

File tree

pkg/workflow/compiler_difc_proxy.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ func getDIFCProxyPolicyJSON(githubTool any) string {
201201
return string(jsonBytes)
202202
}
203203

204+
// resolveProxyContainerImage returns the full container image reference (container:version)
205+
// for the DIFC/CLI proxy, falling back to the default MCP gateway version if none is configured.
206+
func resolveProxyContainerImage(gatewayConfig *MCPGatewayRuntimeConfig) string {
207+
version := gatewayConfig.Version
208+
if version == "" {
209+
version = string(constants.DefaultMCPGatewayVersion)
210+
}
211+
return gatewayConfig.Container + ":" + version
212+
}
213+
204214
// buildStartDIFCProxyStepYAML returns the YAML for the "Start DIFC proxy" step,
205215
// or an empty string if proxy injection is not needed or the policy cannot be built.
206216
// This is the shared implementation used by both the main job and the indexing job.
@@ -223,14 +233,7 @@ func (c *Compiler) buildStartDIFCProxyStepYAML(data *WorkflowData) string {
223233
// Resolve the container image from the MCP gateway configuration
224234
// (proxy uses the same image as the gateway, just in "proxy" mode)
225235
ensureDefaultMCPGatewayConfig(data)
226-
gatewayConfig := data.SandboxConfig.MCP
227-
228-
containerImage := gatewayConfig.Container
229-
if gatewayConfig.Version != "" {
230-
containerImage += ":" + gatewayConfig.Version
231-
} else {
232-
containerImage += ":" + string(constants.DefaultMCPGatewayVersion)
233-
}
236+
containerImage := resolveProxyContainerImage(data.SandboxConfig.MCP)
234237

235238
var sb strings.Builder
236239
sb.WriteString(" - name: Start DIFC proxy for pre-agent gh calls\n")
@@ -388,14 +391,7 @@ func (c *Compiler) buildStartCliProxyStepYAML(data *WorkflowData) string {
388391

389392
// Resolve the container image from the MCP gateway configuration
390393
ensureDefaultMCPGatewayConfig(data)
391-
gatewayConfig := data.SandboxConfig.MCP
392-
393-
containerImage := gatewayConfig.Container
394-
if gatewayConfig.Version != "" {
395-
containerImage += ":" + gatewayConfig.Version
396-
} else {
397-
containerImage += ":" + string(constants.DefaultMCPGatewayVersion)
398-
}
394+
containerImage := resolveProxyContainerImage(data.SandboxConfig.MCP)
399395

400396
var sb strings.Builder
401397
sb.WriteString(" - name: Start CLI proxy\n")

pkg/workflow/compiler_difc_proxy_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/github/gh-aw/pkg/constants"
910
"github.com/stretchr/testify/assert"
1011
"github.com/stretchr/testify/require"
1112
)
@@ -758,3 +759,54 @@ func TestBuildStartCliProxyStepYAML(t *testing.T) {
758759
assert.Contains(t, result, "start_cli_proxy.sh", "should reference the start script")
759760
})
760761
}
762+
763+
// TestResolveProxyContainerImage verifies that the helper builds the correct container
764+
// image reference from the gateway config, falling back to the default version when
765+
// no version is specified.
766+
func TestResolveProxyContainerImage(t *testing.T) {
767+
tests := []struct {
768+
name string
769+
config *MCPGatewayRuntimeConfig
770+
expected string
771+
}{
772+
{
773+
name: "uses default version when version is empty",
774+
config: &MCPGatewayRuntimeConfig{
775+
Container: constants.DefaultMCPGatewayContainer,
776+
Version: "",
777+
},
778+
expected: constants.DefaultMCPGatewayContainer + ":" + string(constants.DefaultMCPGatewayVersion),
779+
},
780+
{
781+
name: "uses explicit version when set",
782+
config: &MCPGatewayRuntimeConfig{
783+
Container: constants.DefaultMCPGatewayContainer,
784+
Version: "v1.2.3",
785+
},
786+
expected: constants.DefaultMCPGatewayContainer + ":v1.2.3",
787+
},
788+
{
789+
name: "custom container with default version fallback",
790+
config: &MCPGatewayRuntimeConfig{
791+
Container: "ghcr.io/myorg/my-proxy",
792+
Version: "",
793+
},
794+
expected: "ghcr.io/myorg/my-proxy:" + string(constants.DefaultMCPGatewayVersion),
795+
},
796+
{
797+
name: "custom container with explicit version",
798+
config: &MCPGatewayRuntimeConfig{
799+
Container: "ghcr.io/myorg/my-proxy",
800+
Version: "latest",
801+
},
802+
expected: "ghcr.io/myorg/my-proxy:latest",
803+
},
804+
}
805+
806+
for _, tt := range tests {
807+
t.Run(tt.name, func(t *testing.T) {
808+
got := resolveProxyContainerImage(tt.config)
809+
assert.Equal(t, tt.expected, got, "resolveProxyContainerImage(%+v)", tt.config)
810+
})
811+
}
812+
}

0 commit comments

Comments
 (0)