@Override
  public Result start(
      WorkflowSummary workflowSummary, Step step, StepRuntimeSummary runtimeSummary) {
    try {
      Artifact artifact = createArtifact(workflowSummary, runtimeSummary);
      return new Result(
          State.DONE,
          Collections.singletonMap(artifact.getType().key(), artifact),
          Collections.emptyList());
    } catch (Exception e) {
      LOG.error(
          "Failed to start foreach workflow step runtime for {}{}",
          workflowSummary.getIdentity(),
          runtimeSummary.getIdentity(),
          e);
      return new Result(
          State.FATAL_ERROR,
          Collections.emptyMap(),
          Collections.singletonList(
              TimelineDetailsEvent.from(
                  Details.create(
                      e, false, "Failed to start foreach workflow step runtime with an error"))));
    }
  }
@Test
  public void testForeachCreateArtifactWithRestartFromSpecificNotAlongRestartPath() {
    int restartIterationId = 2;
    Map<String, Object> evaluatedResult = new LinkedHashMap<>();
    evaluatedResult.put("loop_param", new long[] {1, 2, 3});

    Map<String, Parameter> params = new LinkedHashMap<>();
    params.put(
        "loop_params",
        MapParameter.builder()
            .evaluatedResult(evaluatedResult)
            .evaluatedTime(System.currentTimeMillis())
            .build());

    StepRetry stepRetry = new StepRetry();
    stepRetry.setRetryable(false);
    RestartConfig restartConfig =
        RestartConfig.builder()
            .addRestartNode("maestro-foreach-wf", restartIterationId, "job2")
            .addRestartNode("wf", 1, "job1")
            .restartPolicy(RunPolicy.RESTART_FROM_SPECIFIC)
            .build();
    StepRuntimeSummary runtimeSummary =
        StepRuntimeSummary.builder()
            .stepId(STEP_ID)
            .stepAttemptId(STEP_ATTEMPT_ID)
            .artifacts(new HashMap<>())
            .params(params)
            .stepRetry(stepRetry)
            .restartConfig(restartConfig)
            .build();

    ForeachArtifact prevArtifact = new ForeachArtifact();
    prevArtifact.setForeachWorkflowId("maestro-foreach-wf");
    prevArtifact.setNextLoopIndex(1);
    prevArtifact.setForeachOverview(new ForeachStepOverview());
    prevArtifact.getForeachOverview().addOne(1, WorkflowInstance.Status.FAILED, null);
    prevArtifact.getForeachOverview().refreshDetail();

    Mockito.when(stepInstanceDao.getLatestForeachArtifact(anyString(), anyLong(), anyString()))
        .thenReturn(prevArtifact);

    StepRuntime.Result res = foreachStepRuntime.start(workflowSummary, null, runtimeSummary);
    ForeachArtifact artifact = res.getArtifacts().get(Type.FOREACH.key()).asForeach();
    assertEquals(RunPolicy.RESTART_FROM_SPECIFIC, artifact.getRunPolicy());
    assertNull(artifact.getPendingAction());
  }