TestModelEnvVarInjectionForDetectionJob tests that detection jobs get the correct model environment variable
(t *testing.T)
| 98 | |
| 99 | // TestModelEnvVarInjectionForDetectionJob tests that detection jobs get the correct model environment variable |
| 100 | func TestModelEnvVarInjectionForDetectionJob(t *testing.T) { |
| 101 | tests := []struct { |
| 102 | name string |
| 103 | engine string |
| 104 | expectedEnvVar string |
| 105 | expectedDefault string |
| 106 | expectedDefaultOverride string |
| 107 | }{ |
| 108 | { |
| 109 | name: "Claude detection uses GH_AW_MODEL_DETECTION_CLAUDE", |
| 110 | engine: "claude", |
| 111 | expectedEnvVar: constants.EnvVarModelDetectionClaude, |
| 112 | expectedDefault: "", // Claude has no default detection model |
| 113 | expectedDefaultOverride: compilerenv.DefaultModelClaude, |
| 114 | }, |
| 115 | { |
| 116 | name: "Codex detection uses GH_AW_MODEL_DETECTION_CODEX", |
| 117 | engine: "codex", |
| 118 | expectedEnvVar: constants.EnvVarModelDetectionCodex, |
| 119 | expectedDefault: constants.CodexDefaultModel, |
| 120 | expectedDefaultOverride: compilerenv.DefaultModelCodex, |
| 121 | }, |
| 122 | } |
| 123 | |
| 124 | for _, tt := range tests { |
| 125 | t.Run(tt.name, func(t *testing.T) { |
| 126 | // Create a minimal detection workflow (no SafeOutputs) |
| 127 | workflowData := &WorkflowData{ |
| 128 | Name: "test-detection", |
| 129 | AI: tt.engine, |
| 130 | SafeOutputs: nil, // This makes it a detection job |
| 131 | Tools: map[string]any{ |
| 132 | "bash": []any{"cat", "grep"}, |
| 133 | }, |
| 134 | } |
| 135 | |
| 136 | // Get the engine |
| 137 | engine, err := GetGlobalEngineRegistry().GetEngine(tt.engine) |
| 138 | if err != nil { |
| 139 | t.Fatalf("Failed to get engine: %v", err) |
| 140 | } |
| 141 | |
| 142 | // Get execution steps |
| 143 | steps := engine.GetExecutionSteps(workflowData, "/tmp/detection.log") |
| 144 | |
| 145 | // Convert steps to string for analysis |
| 146 | var stepsStr strings.Builder |
| 147 | for _, step := range steps { |
| 148 | for _, line := range step { |
| 149 | stepsStr.WriteString(line) |
| 150 | stepsStr.WriteString("\n") |
| 151 | } |
| 152 | } |
| 153 | stepsContent := stepsStr.String() |
| 154 | |
| 155 | // Check that the environment variable is present |
| 156 | if !strings.Contains(stepsContent, tt.expectedEnvVar+":") { |
| 157 | t.Errorf("Expected environment variable %s not found in detection steps:\n%s", tt.expectedEnvVar, stepsContent) |
nothing calls this directly
no test coverage detected