How is the hash for the files calculated? I am taking an HTML snapshot of a node in Drupal 8 every day at 4 am. Every night a Cron job kicks off this process. I have a service that handles the entire process.
Everything works for now, but I am worried that the referenced CSS and JavaScript files will break due to the filenames changed by the aggregation process.
How does Drupal 8 decide the name of the aggregated files? How can I reliably point the references to the right filenames?
The name of the aggregated files is the hash calculated from CssCollectionOptimizer::generateHash().
protected function generateHash(array $css_group) {
  $css_data = [];
  foreach ($css_group['items'] as $css_file) {
    $css_data[] = $css_file['data'];
  }
  return hash('sha256', serialize($css_data));
}

The method is called by CssCollectionOptimizer::optimize().
Without knowing to which group a resource is part of, and what other resources are part of that group, you cannot know the name of the file where the resources are aggregated.
There should not be any need to do that, as Drupal core takes care of removing any reference to aggregate files that don't exist anymore, and invalidate all the necessary cache bins.
The markup produced by Drupal core should never contain a reference to an aggregate file that doesn't exist anymore. If that happens, it's either a bug in Drupal core or in a third-party module.