MCPcopy Create free account
hub / github.com/github/gh-aw / TestExplicitModelConfigOverridesEnvVar

Function TestExplicitModelConfigOverridesEnvVar

pkg/workflow/model_env_vars_test.go:178–226  ·  view source on GitHub ↗

TestExplicitModelConfigOverridesEnvVar tests that explicit model configuration takes precedence

(t *testing.T)

Source from the content-addressed store, hash-verified

176
177// TestExplicitModelConfigOverridesEnvVar tests that explicit model configuration takes precedence
178func TestExplicitModelConfigOverridesEnvVar(t *testing.T) {
179 workflowData := &WorkflowData{
180 Name: "test-explicit-model",
181 AI: "copilot",
182 EngineConfig: &EngineConfig{
183 ID: "copilot",
184 Model: "gpt-4",
185 },
186 Tools: map[string]any{
187 "bash": []any{"echo"},
188 },
189 SafeOutputs: &SafeOutputsConfig{
190 // Just enough to make it an agent job
191 },
192 }
193
194 engine, err := GetGlobalEngineRegistry().GetEngine("copilot")
195 if err != nil {
196 t.Fatalf("Failed to get engine: %v", err)
197 }
198
199 steps := engine.GetExecutionSteps(workflowData, "/tmp/test.log")
200
201 // Convert steps to string
202 var stepsStr strings.Builder
203 for _, step := range steps {
204 for _, line := range step {
205 stepsStr.WriteString(line)
206 stepsStr.WriteString("\n")
207 }
208 }
209 stepsContent := stepsStr.String()
210
211 // When model is explicitly configured, the GH_AW_ fallback env var should NOT be present
212 if strings.Contains(stepsContent, constants.EnvVarModelAgentCopilot+":") {
213 t.Errorf("Fallback env var %s should not be present when model is explicitly configured", constants.EnvVarModelAgentCopilot)
214 }
215
216 // The model should be passed via the native COPILOT_MODEL env var (not via --model flag)
217 expectedEnvLine := constants.CopilotCLIModelEnvVar + ": gpt-4"
218 if !strings.Contains(stepsContent, expectedEnvLine) {
219 t.Errorf("Expected native env var line '%s' not found in steps:\n%s", expectedEnvLine, stepsContent)
220 }
221
222 // The --model flag should NOT appear in the shell command (model is via env var)
223 if strings.Contains(stepsContent, "--model gpt-4") {
224 t.Errorf("--model flag should not be in command when model is set via native env var:\n%s", stepsContent)
225 }
226}
227
228// TestCopilotFallbackModelMapsToNativeEnvVar tests that when model is not explicitly configured,
229// the Copilot engine maps the GitHub org variable to the native COPILOT_MODEL env var instead

Callers

nothing calls this directly

Calls 5

GetGlobalEngineRegistryFunction · 0.85
GetEngineMethod · 0.80
GetExecutionStepsMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected