| 1 | #!/usr/bin/env python3 |
| 2 | """Keep the native apps in the web's words where they must match. |
| 3 | |
| 4 | Every native string whose key is one of the web's copy keys (chat.card.*, |
| 5 | work.tl.*, roster.*) must equal copy.go's text for that key, so a merge card |
| 6 | says exactly what the web says (sync proposal, parity row R-02), and Set |
| 7 | aside and Undo say what the web's do (D5).""" |
| 8 | import json, re, sys |
| 9 | from pathlib import Path |
| 10 | |
| 11 | native = Path(__file__).resolve().parents[1] |
| 12 | strings = json.loads((native / 'scripts/strings.json').read_text()) |
| 13 | copy = (native.parent / 'internal/equipo/copy.go').read_text() |
| 14 | problems, checked = [], 0 |
| 15 | # Every outcome the web can show for a decision answered here needs native |
| 16 | # words, or the answered card would silently show none. |
| 17 | for pattern in (r'chat\.card\.merge_chose_\w+', r'chat\.card\.ships_chose_\w+'): |
| 18 | for key in sorted(set(re.findall('"(' + pattern + ')":', copy))): |
| 19 | if key not in strings: |
| 20 | problems.append(f'{key}: the web has this outcome; native has no words for it') |
| 21 | for key in sorted(set(re.findall(r'"(work\.reason\.[^"]+)":', copy))): |
| 22 | if key not in strings: |
| 23 | problems.append(f'{key}: native must carry every reviewed stop reason') |
| 24 | for key, text in sorted(strings.items()): |
| 25 | if not key.startswith(('settings.discard', 'chat.day.today', 'runner.verdict.skipped', 'work.', 'placement.', 'chat.card.', 'chat.paste.', 'chat.attach.', 'work.tl.', 'roster.', 'projects.', 'work.star.', 'api.', 'nav.projects', 'chat.connections.connected', 'chat.connections.dismiss', 'counts.unavailable', 'team.close', 'work.pause.', 'work.reason.', 'work.needs.', 'chat.held.', 'work.hold.', 'work.stage.', 'time.', 'work.hold.run_now', 'work.recover')): |
| 26 | continue |
| 27 | found = re.findall(r'"' + re.escape(key) + r'":\s*"((?:[^"\\]|\\.)*)"', copy) |
| 28 | if len(found) != 1: |
| 29 | problems.append(f'{key}: found {len(found)} times in copy.go, expected once'); continue |
| 30 | web = json.loads('"' + found[0] + '"').replace('%s', '%@') |
| 31 | checked += 1 |
| 32 | if web != text: |
| 33 | problems.append(f'{key}: native says {text!r}, the web says {web!r}') |
| 34 | for p in problems: print(p) |
| 35 | if problems: sys.exit(1) |
| 36 | print(f'{checked} native strings match the web') |
| 37 | |