Where does the menu trail get added into the $data parameter in pathauto_tokens()? I have seen this post: where does $data come from in hook_tokens?, but that did not help me answer my question, maybe it could've but there's no way for me to interact with that post.

I am working in Drupal 8.5, using pathauto 8.x-1.1.

I am looking at pathauto.tokens.inc, here is the code for pathauto's hook_tokens():

function pathauto_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = array();

  if ($type == 'array' &amp;&amp; !empty($data['array'])) {
    $array = $data['array'];

    foreach ($tokens as $name =&gt; $original) {
      switch ($name) {
        case 'join-path':
          $values = array();
          foreach (token_element_children($array) as $key) {
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
            $value = \Drupal::service('pathauto.alias_cleaner')-&gt;cleanString($value, $options);
            $values[] = $value;
          }
          $replacements[$original] = implode('/', $values);
          break;
      }
    }
  }

  return $replacements;
}


I can't seem to find how the menu trail makes it into the $data parameter. I can see the menu trail in $data when I set a breakpoint at array = data['array']. 

My ultimate goal is to figure out why pages with a menu_position rule associated with them are not getting the joined-path history in their url alias.
Token resolving is recursive. The caller of replace() is responsible for providing the data.

As far as this token is considered, it's not an active trail, it's just an array with strings that is combined together.

Your token probably looks something like [node:menu-link:parents:join-path]. If this doesn't receive the right parents then you need to look at where the parents are fetched and passed on, which is in token.module: https://cgit.drupalcode.org/token/tree/token.tokens.inc#n721

And if it is a different token then you need to look up whatever intermediate tokens you are using