Path: blob/main/SignalServiceKit/Protos/Backups/parse-libsignal-comparator-failure.py
1 views
#!/usr/bin/env python312"""3When a MessageBackupIntegrationTestCase fails due to non-matching4`LibSignalClient.ComparableBackup` instances representing the imported and5exported Backup .binprotos, those two `ComparableBackup` strings are logged.67This script expects to take, as stdin, those two lines of output. It then8parses that log output and opens a diff viewer.9"""1011import json12import os13import sys14import tempfile151617def dumpJsonToTempFile(jsonString: str, fileName: str) -> str:18(fd, filePath) = tempfile.mkstemp(suffix="_{}.json".format(fileName))1920with open(fd, mode="w") as fileHandle:21jsonObj = json.loads(jsonString)22fileHandle.write(json.dumps(jsonObj, indent=4))2324return filePath252627def diffFiles(lhs: str, rhs: str):28editor = os.environ["EDITOR"]29if editor is None:30editor = "vim"3132os.execvp(editor, [editor, "-d", lhs, rhs])333435def parseComparisonFailure():36inputLines: list[str] = sys.stdin.readlines()3738if len(inputLines) != 2:39print("Error: unexpected number of lines in input!")40exit(1)4142sharedTestCaseBackup = inputLines[0]43exportedBackup = inputLines[1]4445sharedTestCaseBackupCanonicalRepresentation = dumpJsonToTempFile(sharedTestCaseBackup, "sharedTestCase")46exportedBackupCanonicalRepresentation = dumpJsonToTempFile(exportedBackup, "exported")4748diffFiles(sharedTestCaseBackupCanonicalRepresentation, exportedBackupCanonicalRepresentation)495051if __name__ == "__main__":52parseComparisonFailure()535455