@@ -39,85 +39,37 @@ func TestOSWorkflow_LegacyFlow(t *testing.T) {
39
39
assert .NoError (t , err )
40
40
}
41
41
42
- // TestOSWorkflow_UnifiedTestFlag tests the workflow when run with the unified test flag.
43
- func TestOSWorkflow_UnifiedTestFlag (t * testing.T ) {
44
- // Setup - Unified test flag set to true
45
- ctrl := gomock .NewController (t )
46
- defer ctrl .Finish ()
47
-
48
- mockEngine := mocks .NewMockEngine (ctrl )
49
- mockInvocationCtx := createMockInvocationCtxWithURL (t , ctrl , mockEngine , mockServerURL )
50
-
51
- // Set the unified test flag and required risk score feature flags
52
- mockInvocationCtx .GetConfiguration ().Set (flags .FlagUnifiedTestAPI , true )
53
- mockInvocationCtx .GetConfiguration ().Set (ostest .FeatureFlagRiskScore , true )
54
- mockInvocationCtx .GetConfiguration ().Set (ostest .FeatureFlagRiskScoreInCLI , true )
55
-
56
- // Mock the depgraph workflow
57
- mockEngine .EXPECT ().
58
- InvokeWithConfig (gomock .Any (), gomock .Any ()).
59
- Return (nil , assert .AnError ).
60
- Times (1 )
61
-
62
- // Execute
63
- _ , err := ostest .OSWorkflow (mockInvocationCtx , []workflow.Data {})
64
-
65
- // Verify - Should return error from depgraph workflow
66
- assert .Error (t , err )
67
- assert .Contains (t , err .Error (), "failed to create depgraph" )
68
- }
69
-
70
- // TestOSWorkflow_RiskScoreThreshold tests the workflow when run with a risk score threshold.
71
- func TestOSWorkflow_RiskScoreThreshold (t * testing.T ) {
72
- // Setup - Risk score threshold set
73
- ctrl := gomock .NewController (t )
74
- defer ctrl .Finish ()
75
-
76
- mockEngine := mocks .NewMockEngine (ctrl )
77
- mockInvocationCtx := createMockInvocationCtxWithURL (t , ctrl , mockEngine , mockServerURL )
78
-
79
- // Set a risk score threshold
80
- mockInvocationCtx .GetConfiguration ().Set (flags .FlagRiskScoreThreshold , 700 )
81
- // Enable Risk Score feature flags for this test case
82
- mockInvocationCtx .GetConfiguration ().Set (ostest .FeatureFlagRiskScore , true )
83
- mockInvocationCtx .GetConfiguration ().Set (ostest .FeatureFlagRiskScoreInCLI , true )
84
-
85
- // Mock the depgraph workflow
86
- mockEngine .EXPECT ().
87
- InvokeWithConfig (gomock .Any (), gomock .Any ()).
88
- Return (nil , assert .AnError ).
89
- Times (1 )
90
-
91
- // Execute
92
- _ , err := ostest .OSWorkflow (mockInvocationCtx , []workflow.Data {})
93
-
94
- // Verify - Should return error from depgraph workflow
95
- assert .Error (t , err )
96
- assert .Contains (t , err .Error (), "failed to create depgraph" )
97
- }
98
-
99
- // TestOSWorkflow_SBOMReachabilityFlag_MissingFF tests requirement of the SBOM reachability feature flag.
100
- func TestOSWorkflow_SBOMReachabilityFlag_MissingFF (t * testing.T ) {
101
- // Setup - Unified test flag set to true
102
- ctrl := gomock .NewController (t )
103
- defer ctrl .Finish ()
104
-
105
- mockEngine := mocks .NewMockEngine (ctrl )
106
- mockInvocationCtx := createMockInvocationCtxWithURL (t , ctrl , mockEngine , mockServerURL )
107
-
108
- // Set the sbom reachability flags
109
- mockInvocationCtx .GetConfiguration ().Set (flags .FlagReachability , true )
110
- mockInvocationCtx .GetConfiguration ().Set (flags .FlagSBOM , "bom.json" )
111
-
112
- // Execute
113
- _ , err := ostest .OSWorkflow (mockInvocationCtx , []workflow.Data {})
114
-
115
- // Verify - Should return feature not permitted error
116
- assert .Error (t , err )
117
- assert .Contains (t , err .Error (), "The feature you are trying to use is not available for your organization" )
42
+ func TestOSWorkflow_ForceLegacyFlowWithEnvVar (t * testing.T ) {
43
+ t .Run ("forces legacy flow when env var is set, even with unified flow flags" , func (t * testing.T ) {
44
+ ctrl := gomock .NewController (t )
45
+ defer ctrl .Finish ()
46
+
47
+ mockEngine := mocks .NewMockEngine (ctrl )
48
+ mockInvocationCtx := createMockInvocationCtxWithURL (t , ctrl , mockEngine , mockServerURL )
49
+
50
+ // Setup: set the env var and all flags that would normally trigger the unified flow
51
+ config := mockInvocationCtx .GetConfiguration ()
52
+ config .Set (ostest .ForceLegacyCLIEnvVar , true )
53
+ config .Set (ostest .FeatureFlagRiskScore , true )
54
+ config .Set (ostest .FeatureFlagRiskScoreInCLI , true )
55
+ config .Set (flags .FlagRiskScoreThreshold , 500 )
56
+
57
+ // Mock the legacy flow, which should be called despite the unified flow flags
58
+ mockEngine .EXPECT ().
59
+ InvokeWithConfig (gomock .Any (), gomock .Any ()).
60
+ Return ([]workflow.Data {}, nil ).
61
+ Times (1 )
62
+
63
+ // Execute
64
+ _ , err := ostest .OSWorkflow (mockInvocationCtx , []workflow.Data {})
65
+
66
+ // Verify
67
+ assert .NoError (t , err )
68
+ })
118
69
}
119
70
120
- // TODO: Test combinations with sbom and reachability flags.
71
+ // TestOSWorkflow_FlagCombinations tests various flag combinations to ensure correct routing
72
+ // between the legacy, unified, and reachability test flows.
121
73
func TestOSWorkflow_FlagCombinations (t * testing.T ) {
122
74
tests := []struct {
123
75
name string
@@ -127,7 +79,6 @@ func TestOSWorkflow_FlagCombinations(t *testing.T) {
127
79
{
128
80
name : "Unified test API flag set to true, expects depgraph error" ,
129
81
setup : func (config configuration.Configuration , mockEngine * mocks.MockEngine ) {
130
- config .Set (flags .FlagUnifiedTestAPI , true )
131
82
config .Set (ostest .FeatureFlagRiskScore , true )
132
83
config .Set (ostest .FeatureFlagRiskScoreInCLI , true )
133
84
mockEngine .EXPECT ().
@@ -167,20 +118,6 @@ func TestOSWorkflow_FlagCombinations(t *testing.T) {
167
118
},
168
119
expectedError : "failed to create depgraph" ,
169
120
},
170
- {
171
- name : "Both unified test and risk score set" ,
172
- setup : func (config configuration.Configuration , mockEngine * mocks.MockEngine ) {
173
- config .Set (flags .FlagUnifiedTestAPI , true )
174
- config .Set (flags .FlagRiskScoreThreshold , 700 )
175
- config .Set (ostest .FeatureFlagRiskScore , true )
176
- config .Set (ostest .FeatureFlagRiskScoreInCLI , true )
177
- mockEngine .EXPECT ().
178
- InvokeWithConfig (gomock .Any (), gomock .Any ()).
179
- Return (nil , assert .AnError ).
180
- Times (1 )
181
- },
182
- expectedError : "failed to create depgraph" ,
183
- },
184
121
{
185
122
name : "SBOM reachability without feature flag" ,
186
123
setup : func (config configuration.Configuration , _ * mocks.MockEngine ) {
@@ -193,7 +130,8 @@ func TestOSWorkflow_FlagCombinations(t *testing.T) {
193
130
{
194
131
name : "Severity threshold set with unified test flag, expects depgraph error" ,
195
132
setup : func (config configuration.Configuration , mockEngine * mocks.MockEngine ) {
196
- config .Set (flags .FlagUnifiedTestAPI , true )
133
+ config .Set (ostest .FeatureFlagRiskScore , true )
134
+ config .Set (ostest .FeatureFlagRiskScoreInCLI , true )
197
135
config .Set (flags .FlagSeverityThreshold , "high" )
198
136
mockEngine .EXPECT ().
199
137
InvokeWithConfig (gomock .Any (), gomock .Any ()).
@@ -227,6 +165,30 @@ func TestOSWorkflow_FlagCombinations(t *testing.T) {
227
165
},
228
166
expectedError : "" , // No error, should succeed via legacy path
229
167
},
168
+ {
169
+ name : "Only one risk score FF enabled, uses legacy flow" ,
170
+ setup : func (config configuration.Configuration , mockEngine * mocks.MockEngine ) {
171
+ config .Set (ostest .FeatureFlagRiskScore , true )
172
+ // ffRiskScoreInCLI is false by default
173
+ mockEngine .EXPECT ().
174
+ InvokeWithConfig (gomock .Any (), gomock .Any ()).
175
+ Return ([]workflow.Data {}, nil ).
176
+ Times (1 )
177
+ },
178
+ expectedError : "" , // No error, should succeed via legacy path
179
+ },
180
+ {
181
+ name : "Only CLI risk score FF enabled, uses legacy flow" ,
182
+ setup : func (config configuration.Configuration , mockEngine * mocks.MockEngine ) {
183
+ config .Set (ostest .FeatureFlagRiskScoreInCLI , true )
184
+ // ffRiskScore is false by default
185
+ mockEngine .EXPECT ().
186
+ InvokeWithConfig (gomock .Any (), gomock .Any ()).
187
+ Return ([]workflow.Data {}, nil ).
188
+ Times (1 )
189
+ },
190
+ expectedError : "" , // No error, should succeed via legacy path
191
+ },
230
192
}
231
193
232
194
for _ , test := range tests {
@@ -266,7 +228,6 @@ func createMockInvocationCtxWithURL(t *testing.T, ctrl *gomock.Controller, engin
266
228
mockConfig .Set (configuration .API_URL , sbomServiceURL )
267
229
268
230
// Initialize with default values for our flags
269
- mockConfig .Set (flags .FlagUnifiedTestAPI , false )
270
231
mockConfig .Set (flags .FlagRiskScoreThreshold , - 1 )
271
232
mockConfig .Set (flags .FlagFile , "test-file.txt" ) // Add default test file
272
233
0 commit comments