code: def test_ci_move_from_passing_to_failing_to_flaky():
      """
      Test the entire lifecycle of a CI test when it moves from passing to failing.
      Check that the conditions are met for each state transition. Also check that
      gihub issues are created and closed correctly.
      """
      test = Test(name="test", team="ci")
      # start from passing
      assert test.get_state() == TestState.PASSING
  
      # passing to failing
      test.test_results = [
          TestResult.from_result(
              Result(status=ResultStatus.ERROR.value)
          ),
      ]
      CITestStateMachine(test).move()
      assert test.get_state() == TestState.FAILING
  
      # failing to consistently failing
      test.test_results.extend(
          [
              TestResult.from_result(
                  Result(status=ResultStatus.ERROR.value)
              ),
              TestResult.from_result(
                  Result(status=ResultStatus.ERROR.value)
              ),
          ]
      )
      CITestStateMachine(test).move()
      assert test.get_state() == TestState.CONSITENTLY_FAILING
      issue = MockIssueDB.issue_db[
          test.get(Test.KEY_GITHUB_ISSUE_NUMBER)
      ]
      assert issue.state == "open"
      assert "ci-test" in [label.name for label in issue.labels]
  
      # move from consistently failing to flaky
      test.test_results.extend(
          [
              TestResult.from_result(
                  Result(status=ResultStatus.ERROR.value)
              )
          ]
          * CONTINUOUS_FAILURE_TO_FLAKY
      )
      CITestStateMachine(test).move()
      assert test.get_state() == TestState.FLAKY
      assert issue.comments[-1] == FAILING_TO_FLAKY_MESSAGE
  
      # go back to passing
      test.test_results = [
          TestResult.from_result(
              Result(status=ResultStatus.SUCCESS.value)
          ),
      ] * CONTINUOUS_PASSING_TO_PASSING
      CITestStateMachine(test).move()
      assert test.get_state() == TestState.PASSING
      assert test.get(Test.KEY_GITHUB_ISSUE_NUMBER) is None
      assert issue.state == "closed"
  
imports: import sys
  from typing import List, Optional
  import pytest
  from ray_release.test import Test, TestResult, TestState
  from ray_release.result import Result, ResultStatus
  from ray_release.test_automation.release_state_machine import ReleaseTestStateMachine
  from ray_release.test_automation.ci_state_machine import CITestStateMachine, CONTINUOUS_FAILURE_TO_FLAKY, CONTINUOUS_PASSING_TO_PASSING, FAILING_TO_FLAKY_MESSAGE, JAILED_TAG, JAILED_MESSAGE
  from ray_release.test_automation.state_machine import TestStateMachine
label_desc: Use image node_id 2 for calling a global function with example usage: test_ci_move_from_passing_to_failing_to_flaky() without return types