code: def find_sorted_task_dependencies(task, task_name, task_id):
      
      log.info("find_sorted_task_dependencies {} {}".format(task_name, task_id))
  
      cot_input_dependencies = [
          _craft_dependency_tuple(task_name, task_type, task_id)
          for task_type, task_id in task['extra'].get('chainOfTrust', {}).get('inputs', {}).items()
      ]
  
      upstream_artifacts_dependencies = [
          _craft_dependency_tuple(task_name, artifact_dict['taskType'], artifact_dict['taskId'])
          for artifact_dict in task.get('payload', {}).get('upstreamArtifacts', [])
      ]
  
      dependencies = [*cot_input_dependencies, *upstream_artifacts_dependencies]
      dependencies = _sort_dependencies_by_name_then_task_id(dependencies)
  
      parent_task_id = get_parent_task_id(task) or get_decision_task_id(task)
      parent_task_type = 'parent'
      # make sure we deal with the decision task first, or we may populate
      # signing:build0:decision before signing:decision
      parent_tuple = _craft_dependency_tuple(task_name, parent_task_type, parent_task_id)
      dependencies.insert(0, parent_tuple)
  
      log.info('found dependencies: {}'.format(dependencies))
      return dependencies
docs: Find the taskIds of the chain of trust dependencies of a given task.
  
      Args:
          task (dict): the task definition to inspect.
          task_name (str): the name of the task, for logging and naming children.
          task_id (str): the taskId of the task.
  
      Returns:
          list: tuples associating dependent task ``name`` to dependent task ``taskId``.