Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Protos/Backups/parse-libsignal-comparator-failure.py
1 views
1
#!/usr/bin/env python3
2
3
"""
4
When a MessageBackupIntegrationTestCase fails due to non-matching
5
`LibSignalClient.ComparableBackup` instances representing the imported and
6
exported Backup .binprotos, those two `ComparableBackup` strings are logged.
7
8
This script expects to take, as stdin, those two lines of output. It then
9
parses that log output and opens a diff viewer.
10
"""
11
12
import json
13
import os
14
import sys
15
import tempfile
16
17
18
def dumpJsonToTempFile(jsonString: str, fileName: str) -> str:
19
(fd, filePath) = tempfile.mkstemp(suffix="_{}.json".format(fileName))
20
21
with open(fd, mode="w") as fileHandle:
22
jsonObj = json.loads(jsonString)
23
fileHandle.write(json.dumps(jsonObj, indent=4))
24
25
return filePath
26
27
28
def diffFiles(lhs: str, rhs: str):
29
editor = os.environ["EDITOR"]
30
if editor is None:
31
editor = "vim"
32
33
os.execvp(editor, [editor, "-d", lhs, rhs])
34
35
36
def parseComparisonFailure():
37
inputLines: list[str] = sys.stdin.readlines()
38
39
if len(inputLines) != 2:
40
print("Error: unexpected number of lines in input!")
41
exit(1)
42
43
sharedTestCaseBackup = inputLines[0]
44
exportedBackup = inputLines[1]
45
46
sharedTestCaseBackupCanonicalRepresentation = dumpJsonToTempFile(sharedTestCaseBackup, "sharedTestCase")
47
exportedBackupCanonicalRepresentation = dumpJsonToTempFile(exportedBackup, "exported")
48
49
diffFiles(sharedTestCaseBackupCanonicalRepresentation, exportedBackupCanonicalRepresentation)
50
51
52
if __name__ == "__main__":
53
parseComparisonFailure()
54
55