From ab6d9fe0f60ad6ec9add982831f93e8e1ee7c79c Mon Sep 17 00:00:00 2001
From: Mathieu Hofman <mathieu@agoric.com>
Date: Fri, 26 Aug 2022 15:31:20 +0000
Subject: [PATCH] fix(scripts): Divergence artifact for xsnap-trace diff Always
 generate an artifact, possibly empty if no divergence

---
 scripts/process-integration-results.sh           | 10 ++++++----
 scripts/process-integration-swingstore-traces.sh |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/scripts/process-integration-results.sh b/scripts/process-integration-results.sh
index 5ce165c2fc2d..0b5ab89ceba6 100755
--- a/scripts/process-integration-results.sh
+++ b/scripts/process-integration-results.sh
@@ -17,7 +17,7 @@ clean_slog() {
 
 "$thisdir/process-integration-swingstore-traces.sh" "$RESULTSDIR"
 
-[ -f "$RESULTSDIR/divergent_snapshots" ] || exit 0
+# [ -f "$RESULTSDIR/divergent_snapshots" ] || exit 0
 
 cd "$RESULTSDIR"
 
@@ -99,7 +99,9 @@ for v in validator0-xsnap-trace/v*; do
   done
 done | grep -v "No newline at end of file" > monitor-vs-validator-xsnap-trace.diff || true
 [ "x${DEBUG-}" = "x1" ] && set -x
-to_backup="$to_backup monitor-vs-validator-xsnap-trace.diff"
+grep -e '^--- validator' <(cat validator-xsnap-trace.diff monitor-vs-validator-xsnap-trace.diff) | cut -d '/' -f 2 | uniq > divergent_xsnap_trace_vats || true
+
+to_backup="$to_backup monitor-vs-validator-xsnap-trace.diff divergent_xsnap_trace_vats"
 
 mkdir -p "xs-snapshots"
 cp -a validator0-xs-snapshots/* "xs-snapshots/" || true
@@ -118,7 +120,7 @@ for trace in chain-*-swingstore-trace validator*-swingstore-trace; do
   to_delete="$to_delete $snapshots_dir"
   for v in $({ grep -E 'set local\.v[0-9]+\.lastSnapshot' $trace || true; } | cut -d ' ' -f 2 | cut -d '.' -f 2 | sort | uniq ); do
     mkdir -p $snapshots_dir/$v
-    if grep -q -e "^$v\$" divergent_snapshot_vats; then
+    if grep -q -e "^$v\$" <(cat divergent_snapshot_vats divergent_xsnap_trace_vats); then
       to_backup="$to_backup $snapshots_dir/$v"
       v_divergent=1
     else
@@ -146,7 +148,7 @@ for trace in *-xsnap-trace; do
   for v in $trace/v*; do
     [ -h "$v" ] || continue
     v=${v#"$trace/"}
-    if grep -q -e "^$v\$" divergent_snapshot_vats; then
+    if grep -q -e "^$v\$" <(cat divergent_snapshot_vats divergent_xsnap_trace_vats); then
       v_divergent=1
       to_backup="$to_backup $trace/$v $trace/$(readlink $trace/$v)"
     else
diff --git a/scripts/process-integration-swingstore-traces.sh b/scripts/process-integration-swingstore-traces.sh
index 0d3a4e44e602..d2d324494a4e 100755
--- a/scripts/process-integration-swingstore-traces.sh
+++ b/scripts/process-integration-swingstore-traces.sh
@@ -46,7 +46,7 @@ if [ -f $RESULTSDIR/chain-stage-0-swingstore-trace ] ; then
   diffs="$diffs $RESULTSDIR/monitor-vs-validator-swingstore-trace.diff"
 fi
 
-[ $val_diff_ret -eq 0 -a $chain_diff_ret -eq 0 ] && exit 0
+# [ $val_diff_ret -eq 0 -a $chain_diff_ret -eq 0 ] && exit 0
 
 get_snapshots_from_diff <(cat $diffs) > $RESULTSDIR/divergent_snapshots
 get_vats_from_diff <(cat $diffs) > $RESULTSDIR/divergent_snapshot_vats