@@ -1168,6 +1168,77 @@ public void ActionVariables_SecretsPrecedenceForDebugUsingVars()
1168
1168
}
1169
1169
}
1170
1170
1171
+ [ Fact ]
1172
+ [ Trait ( "Level" , "L0" ) ]
1173
+ [ Trait ( "Category" , "Worker" ) ]
1174
+ public void InitializeJob_HydratesJobContextWithCheckRunId ( )
1175
+ {
1176
+ using ( TestHostContext hc = CreateTestContext ( ) )
1177
+ {
1178
+ // Arrange: Create a job request message and make sure the feature flag is enabled
1179
+ var variables = new Dictionary < string , VariableValue > ( )
1180
+ {
1181
+ [ Constants . Runner . Features . AddCheckRunIdToJobContext ] = new VariableValue ( "true" ) ,
1182
+ } ;
1183
+ var jobRequest = new Pipelines . AgentJobRequestMessage ( new TaskOrchestrationPlanReference ( ) , new TimelineReference ( ) , Guid . NewGuid ( ) , "some job name" , "some job name" , null , null , null , variables , new List < MaskHint > ( ) , new Pipelines . JobResources ( ) , new Pipelines . ContextData . DictionaryContextData ( ) , new Pipelines . WorkspaceOptions ( ) , new List < Pipelines . ActionStep > ( ) , null , null , null , null , null ) ;
1184
+ var pagingLogger = new Moq . Mock < IPagingLogger > ( ) ;
1185
+ var jobServerQueue = new Moq . Mock < IJobServerQueue > ( ) ;
1186
+ hc . EnqueueInstance ( pagingLogger . Object ) ;
1187
+ hc . SetSingleton ( jobServerQueue . Object ) ;
1188
+ var ec = new Runner . Worker . ExecutionContext ( ) ;
1189
+ ec . Initialize ( hc ) ;
1190
+
1191
+ // Arrange: Add check_run_id to the job context
1192
+ var jobContext = new Pipelines . ContextData . DictionaryContextData ( ) ;
1193
+ jobContext [ "check_run_id" ] = new NumberContextData ( 123456 ) ;
1194
+ jobRequest . ContextData [ "job" ] = jobContext ;
1195
+ jobRequest . ContextData [ "github" ] = new Pipelines . ContextData . DictionaryContextData ( ) ;
1196
+
1197
+ // Act
1198
+ ec . InitializeJob ( jobRequest , CancellationToken . None ) ;
1199
+
1200
+ // Assert
1201
+ Assert . NotNull ( ec . JobContext ) ;
1202
+ Assert . Equal ( 123456 , ec . JobContext . CheckRunId ) ;
1203
+ }
1204
+ }
1205
+
1206
+ // TODO: this test can be deleted when `AddCheckRunIdToJobContext` is fully rolled out
1207
+ [ Fact ]
1208
+ [ Trait ( "Level" , "L0" ) ]
1209
+ [ Trait ( "Category" , "Worker" ) ]
1210
+ public void InitializeJob_HydratesJobContextWithCheckRunId_FeatureFlagDisabled ( )
1211
+ {
1212
+ using ( TestHostContext hc = CreateTestContext ( ) )
1213
+ {
1214
+ // Arrange: Create a job request message and make sure the feature flag is disabled
1215
+ var variables = new Dictionary < string , VariableValue > ( )
1216
+ {
1217
+ [ Constants . Runner . Features . AddCheckRunIdToJobContext ] = new VariableValue ( "false" ) ,
1218
+ } ;
1219
+ var jobRequest = new Pipelines . AgentJobRequestMessage ( new TaskOrchestrationPlanReference ( ) , new TimelineReference ( ) , Guid . NewGuid ( ) , "some job name" , "some job name" , null , null , null , variables , new List < MaskHint > ( ) , new Pipelines . JobResources ( ) , new Pipelines . ContextData . DictionaryContextData ( ) , new Pipelines . WorkspaceOptions ( ) , new List < Pipelines . ActionStep > ( ) , null , null , null , null , null ) ;
1220
+ var pagingLogger = new Moq . Mock < IPagingLogger > ( ) ;
1221
+ var jobServerQueue = new Moq . Mock < IJobServerQueue > ( ) ;
1222
+ hc . EnqueueInstance ( pagingLogger . Object ) ;
1223
+ hc . SetSingleton ( jobServerQueue . Object ) ;
1224
+ var ec = new Runner . Worker . ExecutionContext ( ) ;
1225
+ ec . Initialize ( hc ) ;
1226
+
1227
+ // Arrange: Add check_run_id to the job context
1228
+ var jobContext = new Pipelines . ContextData . DictionaryContextData ( ) ;
1229
+ jobContext [ "check_run_id" ] = new NumberContextData ( 123456 ) ;
1230
+ jobRequest . ContextData [ "job" ] = jobContext ;
1231
+ jobRequest . ContextData [ "github" ] = new Pipelines . ContextData . DictionaryContextData ( ) ;
1232
+
1233
+ // Act
1234
+ ec . InitializeJob ( jobRequest , CancellationToken . None ) ;
1235
+
1236
+ // Assert
1237
+ Assert . NotNull ( ec . JobContext ) ;
1238
+ Assert . Null ( ec . JobContext . CheckRunId ) ; // with the feature flag disabled we should not have added a CheckRunId to the JobContext
1239
+ }
1240
+ }
1241
+
1171
1242
private bool ExpressionValuesAssertEqual ( DictionaryContextData expect , DictionaryContextData actual )
1172
1243
{
1173
1244
foreach ( var key in expect . Keys . ToList ( ) )
0 commit comments