evaluateStaleness function

StalenessAssessment evaluateStaleness(
  1. StalenessInputs inputs
)

Compares supplied observations without reading or writing external state.

Implementation

StalenessAssessment evaluateStaleness(StalenessInputs inputs) {
  final reasons = <String>[];
  if (inputs.currentManifestHash != inputs.recordedManifestHash) {
    reasons.add('Staging manifest hash mismatch.');
  }
  for (final entry in inputs.recordedNormalizedHashes.entries) {
    final current = inputs.currentNormalizedHashes[entry.key];
    if (current == null) {
      reasons.add('Missing staged artifact: ${entry.key}.');
    } else if (current != entry.value) {
      reasons.add('Changed staged artifact: ${entry.key}.');
    }
  }
  if (inputs.currentBlueprintHash != inputs.recordedBlueprintHash) {
    reasons.add('Blueprint or configuration changed.');
  }
  for (final entry in inputs.recordedRelevantPubspecHashes.entries) {
    final current = inputs.currentRelevantPubspecHashes[entry.key];
    if (current == null) {
      reasons.add('Missing relevant pubspec: ${entry.key}.');
    } else if (current != entry.value) {
      reasons.add('Changed relevant pubspec: ${entry.key}.');
    }
  }
  if (inputs.currentRecipeVersion != inputs.recordedRecipeVersion) {
    reasons.add('Recipe lock changed.');
  }
  if (inputs.currentEngineVersion != inputs.recordedEngineVersion) {
    reasons.add('Engine compatibility changed.');
  }
  return StalenessAssessment(
    blockingReasons: reasons,
    warnings: [
      for (final path in inputs.unrelatedChangedPaths)
        'Unrelated changed path: $path.',
    ],
  );
}