backfill: Tweak run_local_backfill.py to produce cleaner json diffs.
Recursively sort arrays to ensure that we're diffing values in order.
BUG=b:186211287
TEST=manual
Change-Id: Ie8100f5e5cd8ae793b1070aefe3b44f11abddafa
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/config/+/3050657
Commit-Queue: Sean McAllister <smcallis@google.com>
Reviewed-by: Navil Perez <navil@google.com>
diff --git a/scripts/common/utilities.py b/scripts/common/utilities.py
index a220b4c..c088e9d 100644
--- a/scripts/common/utilities.py
+++ b/scripts/common/utilities.py
@@ -66,19 +66,20 @@
return process.stdout, process.returncode
-def jqdiff(filea, fileb, filt="."):
+def jqdiff(filea, fileb):
"""Diff two json files using jq with ordered keys.
Args:
filea (str): first file to compare
fileb (str): second file to compare
- filt (str): if supplied, jq filter to apply to inputs before comparing
- The filter is quoted with '' for the user so take care when specifying.
Return:
Diff between jq output with -S (sorted keys) enabled
"""
+ # Enable recursive sort on arrays
+ filt = 'walk(if type == "array" then sort else . end)'
+
# if inputs aren't declared, use a file that will (almost surely) never
# exist and pass -N to diff so it treats it as an empty file and gives a
# full diff