#!/usr/bin/env python3 """Keep the native apps in the web's words where they must match. Every native string whose key is one of the web's copy keys (chat.card.*, work.tl.*, roster.*) must equal copy.go's text for that key, so a merge card says exactly what the web says (sync proposal, parity row R-02), and Set aside and Undo say what the web's do (D5).""" import json, re, sys from pathlib import Path native = Path(__file__).resolve().parents[1] strings = json.loads((native / 'scripts/strings.json').read_text()) copy = (native.parent / 'internal/equipo/copy.go').read_text() problems, checked = [], 0 # Every outcome the web can show for a decision answered here needs native # words, or the answered card would silently show none. for pattern in (r'chat\.card\.merge_chose_\w+', r'chat\.card\.ships_chose_\w+'): for key in sorted(set(re.findall('"(' + pattern + ')":', copy))): if key not in strings: problems.append(f'{key}: the web has this outcome; native has no words for it') for key in sorted(set(re.findall(r'"(work\.reason\.[^"]+)":', copy))): if key not in strings: problems.append(f'{key}: native must carry every reviewed stop reason') for key, text in sorted(strings.items()): 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')): continue found = re.findall(r'"' + re.escape(key) + r'":\s*"((?:[^"\\]|\\.)*)"', copy) if len(found) != 1: problems.append(f'{key}: found {len(found)} times in copy.go, expected once'); continue web = json.loads('"' + found[0] + '"').replace('%s', '%@') checked += 1 if web != text: problems.append(f'{key}: native says {text!r}, the web says {web!r}') for p in problems: print(p) if problems: sys.exit(1) print(f'{checked} native strings match the web')