diff --git a/tools/push3-evolution/evaluate-seeds.sh b/tools/push3-evolution/evaluate-seeds.sh index feeeb2a..ece31dc 100755 --- a/tools/push3-evolution/evaluate-seeds.sh +++ b/tools/push3-evolution/evaluate-seeds.sh @@ -100,8 +100,11 @@ fi FAILURES=0 -# scores: associative array file -> score (bash 4+) -declare -A SCORES +# Scores are accumulated in a temp file as tab-separated "filename\tscore" +# lines. Using a file (rather than a shell associative array embedded in a +# heredoc) avoids injecting values into Python source code. +SCORES_FILE="$(mktemp)" +trap 'rm -f "$SCORES_FILE"' EXIT while IFS= read -r FNAME; do [ -z "$FNAME" ] && continue @@ -117,6 +120,13 @@ while IFS= read -r FNAME; do FITNESS_EC=0 SCORE=$("$FITNESS_SH" "$SEED_FILE") || FITNESS_EC=$? + if [ "$FITNESS_EC" -eq 2 ]; then + # Exit code 2 = infra error (Anvil down, missing tool, etc.). + # All subsequent evaluations will fail for the same reason; abort early. + log "ERROR: fitness.sh reported infra failure (exit 2) for $FNAME — aborting" + exit 2 + fi + if [ "$FITNESS_EC" -ne 0 ] || [ -z "$SCORE" ]; then log "WARNING: fitness.sh failed for $FNAME (exit $FITNESS_EC) — skipping" FAILURES=$((FAILURES + 1)) @@ -124,10 +134,10 @@ while IFS= read -r FNAME; do fi log " $FNAME → fitness=$SCORE" - SCORES["$FNAME"]="$SCORE" + printf '%s\t%s\n' "$FNAME" "$SCORE" >> "$SCORES_FILE" done <<< "$NULL_ENTRIES" -if [ "${#SCORES[@]}" -eq 0 ]; then +if [ ! -s "$SCORES_FILE" ]; then log "No seeds were successfully evaluated." exit 1 fi @@ -137,22 +147,25 @@ fi # ============================================================================= MANIFEST_TMP="$(mktemp "${MANIFEST}.XXXXXX")" -trap 'rm -f "$MANIFEST_TMP"' EXIT +# Update trap to clean up both temp files. +trap 'rm -f "$SCORES_FILE" "$MANIFEST_TMP"' EXIT -python3 - "$MANIFEST" "$MANIFEST_TMP" <