108 lines
4.9 KiB
Python
108 lines
4.9 KiB
Python
"""Verify the bounded B05 research inventory against local immutable Git sources."""
|
|
import csv
|
|
import hashlib
|
|
import json
|
|
import subprocess
|
|
import unittest
|
|
from collections import Counter
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
ROOT = HERE.parents[2]
|
|
SOURCE = '5fd5c470452ae78ab46e74b7c1d8fb4336a7484d'
|
|
B03_SHA = '4298460dbc8b8e8d6dbc7e7a9663948274d01e0af989852a97e25854ca4bc98d'
|
|
CATALOGUE_SHA = 'fe57139831579f5bee482039a6bb15cb1eefb8e6f4f9263f8351d7465ac34cf6'
|
|
CONTROLLERS = {'EmailController', 'EmailDraftsController', 'CorrespondenceController',
|
|
'GmailController', 'MicrosoftGraphController', 'ImapController'}
|
|
PROVIDERS = {'GmailProvider', 'MicrosoftGraphProvider', 'ImapProvider'}
|
|
ROLES = {'endpoint-or-policy', 'identifier-or-format', 'persisted-display-ambiguity',
|
|
'provider-brand-or-identifier', 'private-search-expression', 'display-source',
|
|
'comment', 'opaque-provider-or-exception', 'template-markup'}
|
|
|
|
|
|
def rows(name):
|
|
with (HERE / name).open(encoding='utf-8', newline='') as source:
|
|
return list(csv.DictReader(source))
|
|
|
|
|
|
@lru_cache(maxsize=None)
|
|
def blob(commit, path):
|
|
return subprocess.check_output(['git', 'show', f'{commit}:{path}'], cwd=ROOT)
|
|
|
|
|
|
def research_json(name, digest):
|
|
data = (HERE / name).read_bytes().replace(b'\r\n', b'\n')
|
|
if hashlib.sha256(data).hexdigest() != digest:
|
|
raise ValueError(f'Unexpected research input: {name}')
|
|
return json.loads(data)
|
|
|
|
|
|
class MailInventory(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
prior = research_json('B03_CENSUS.json', B03_SHA)
|
|
cls.prior_commit = prior['sourceCommit']
|
|
cls.owners = {Path(row['source']).stem: row for row in prior['ownerCoverage']
|
|
if Path(row['source']).stem in CONTROLLERS | PROVIDERS}
|
|
cls.paths = {owner: row['source'] for owner, row in cls.owners.items()}
|
|
cls.paths['GmailParsing'] = 'JobTrackerApi/Services/GmailParsing.cs'
|
|
|
|
def test_complete_mail_frontier_and_unchanged_source(self):
|
|
self.assertEqual(set(self.owners), CONTROLLERS | PROVIDERS)
|
|
expected = Counter((owner, line) for owner, row in self.owners.items()
|
|
for line in row['otherQuotedLinesNotClassified'])
|
|
actual = Counter()
|
|
for row in rows('B05_MAIL_FRONTIER.csv'):
|
|
self.assertIn(row['role'], ROLES)
|
|
actual.update((row['owner'], int(n)) for n in row['lines'].split())
|
|
self.assertEqual(actual, expected)
|
|
self.assertEqual(len(expected), 149)
|
|
for owner in self.owners:
|
|
path = self.paths[owner]
|
|
with self.subTest(owner=owner):
|
|
self.assertEqual(blob(SOURCE, path), blob(self.prior_commit, path))
|
|
|
|
def test_display_occurrences_and_private_parameters(self):
|
|
found = set()
|
|
for row in rows('B05_MAIL_DISPLAY.csv'):
|
|
owner, line, message = row['owner'], int(row['line']), row['englishSource']
|
|
with self.subTest(owner=owner, line=line, message=message):
|
|
source_line = blob(SOURCE, self.paths[owner]).decode().splitlines()[line - 1]
|
|
self.assertIn(message, source_line)
|
|
self.assertNotIn((owner, line, message), found)
|
|
self.assertTrue(row['parameterContext'].strip())
|
|
if '{' in message:
|
|
self.assertRegex(row['parameterContext'], r'private|opaque')
|
|
found.add((owner, line, message))
|
|
self.assertEqual(len(found), 21)
|
|
self.assertEqual(sum('close this window' in message for _, _, message in found), 2)
|
|
|
|
def test_presenter_and_fallback_traces(self):
|
|
sites = {
|
|
'src/emailOAuth.ts': {20: 'event.source !== attempt.popup', 24: 'data.status !== "connected"',
|
|
26: 'message: data.message'},
|
|
'src/components/EmailProviderConnections.tsx': {
|
|
113: 'emailOAuthMessage(event, attempt)', 117: 'toast(data.message || t(',
|
|
120: 'toast(data.message || t('},
|
|
'src/views/CorrespondenceInboxPage.tsx': {838: 'item.externalFrom || item.from',
|
|
842: 't(item.direction === "inbound"'},
|
|
'src/views/GmailReviewPage.tsx': {266: '{thread.subject}'},
|
|
}
|
|
for path, probes in sites.items():
|
|
source = blob(SOURCE, f'job-tracker-ui/{path}').decode().splitlines()
|
|
for line, text in probes.items():
|
|
with self.subTest(path=path, line=line):
|
|
self.assertIn(text, source[line - 1])
|
|
|
|
def test_research_scope(self):
|
|
catalogue = research_json('LOCALE_CATALOG.json', CATALOGUE_SHA)
|
|
self.assertEqual(len(catalogue['locales']), 60)
|
|
for locale in catalogue['locales']:
|
|
with self.subTest(tag=locale['tag']):
|
|
self.assertEqual(locale['surfaces']['communications'], 'planned')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|