code: def check_graph_is_sorted(g, sorted_nodes, removed_edges):
      incoming_edges = {
          k: [s for s, vs in g.items() if k in vs] for k in g.keys()
      }
  
      visited = set()
      for n in sorted_nodes:
          deps = incoming_edges.get(n, [])
          # checks that all incoming edges are from nodes we have already visited
          assert all(
              [d in visited or (d, n) in removed_edges for d in deps]
          ), "Found an incoming edge from a node that wasn't visited yet!"
          visited.add(n)
  
file_path: rasa/tests/shared/core/training_data/test_graph.py
imports: from rasa.shared.core.training_data.structures import StoryGraph
  import rasa.shared.core.training_data.loading
  from rasa.shared.core.domain import Domain
label_desc: Use image node_id 1 for calling a global function with example usage: check_graph_is_sorted(g, sorted_nodes, removed_edges) without return types