public RunResponse restart(RunRequest runRequest, boolean blocking) {
    if (!runRequest.isFreshRun()
        && runRequest.getCurrentPolicy() != RunPolicy.RESTART_FROM_SPECIFIC) {
      updateRunRequestForRestartFromInlineRoot(runRequest);
    }

    RunResponse runResponse = actionHandler.restartRecursively(runRequest);
    if (runResponse.getStatus() == RunResponse.Status.DELEGATED) {
      return restartDirectly(runResponse, runRequest, blocking);
    }
    return runResponse;
  }
@Test
  public void testInvalidRestartFromInlineRoot() {
    when(instanceDao.getWorkflowInstance(
            "sample-minimal-wf", 1, Constants.LATEST_INSTANCE_RUN, true))
        .thenReturn(instance);
    when(instance.getStatus()).thenReturn(WorkflowInstance.Status.IN_PROGRESS);
    when(instance.getInitiator()).thenReturn(new ForeachInitiator());
    RunRequest runRequest =
        RunRequest.builder()
            .requester(user)
            .currentPolicy(RunPolicy.RESTART_FROM_INCOMPLETE)
            .restartConfig(
                RestartConfig.builder()
                    .addRestartNode("sample-minimal-wf2", 1, "job1")
                    .addRestartNode("sample-minimal-wf", 1, "job1")
                    .build())
            .build();
    AssertHelper.assertThrows(
        "Cannot restart from inline root for non-terminal root",
        IllegalArgumentException.class,
        "instance [null] is in non-terminal state [IN_PROGRESS]",
        () -> stepActionHandler.restart(runRequest, true));

    when(instance.getStatus()).thenReturn(WorkflowInstance.Status.FAILED);
    WorkflowInstanceAggregatedInfo aggregatedInfo = mock(WorkflowInstanceAggregatedInfo.class);
    when(instance.getAggregatedInfo()).thenReturn(aggregatedInfo);
    StepAggregatedView aggregatedView = mock(StepAggregatedView.class);
    when(aggregatedInfo.getStepAggregatedViews()).thenReturn(singletonMap("job1", aggregatedView));
    when(aggregatedView.getStatus()).thenReturn(StepInstance.Status.RUNNING);
    AssertHelper.assertThrows(
        "Cannot restart from inline root for non-terminal step",
        IllegalArgumentException.class,
        "step null[job1] is in non-terminal state [RUNNING]",
        () -> stepActionHandler.restart(runRequest, true));

    when(aggregatedView.getStatus()).thenReturn(StepInstance.Status.FATALLY_FAILED);
    AssertHelper.assertThrows(
        "Cannot restart from inline root for invalid restart path",
        IllegalArgumentException.class,
        "restart-path size is not 1",
        () -> stepActionHandler.restart(runRequest, true));
  }