from pathlib import Path import hashlib import json import re p = Path(__file__).resolve().parent root = p.parent a = (p / 'article.md').read_text(encoding='utf-8') m = json.loads((p / 'metadata.json').read_text(encoding='utf-8')) assert set(m) == {'headline', 'excerpt', 'search_description'} assert all(isinstance(v, str) and v.strip() for v in m.values()) assert a.splitlines()[0] == '# ' + m['headline'] body, sources = a.split('\n', 1)[1].split('## Sources', 1) prose = '\n'.join(line for line in body.splitlines() if not line.startswith('#')) prose = re.sub(r'\[\d+\]', '', prose) counts = { 'article_prose_words_excluding_headings_and_citation_markers': len(prose.split()), 'article_body_words_including_section_headings': len(body.split()), 'article_all_words_including_title_and_sources': len(a.split()), 'headline_characters': len(m['headline']), 'excerpt_words': len(m['excerpt'].split()), 'search_description_characters': len(m['search_description']), } for key in list(counts)[:3]: assert 600 <= counts[key] <= 800, (key, counts[key]) assert 50 <= counts['headline_characters'] <= 70 assert counts['excerpt_words'] <= 45 assert 140 <= counts['search_description_characters'] <= 160 assert 3 * 29 == 87 and 3 * 29 + 12 == 99 assert (50 - 20) / 50 == .6 refs = set(re.findall(r'\[(\d+)\]', body)) defs = re.findall(r'^\[(\d+)\]', sources, re.M) assert refs == set(defs) == {'1', '2', '3', '4', '5'} assert len(defs) == len(set(defs)) for line in sources.splitlines(): match = re.match(r'^\[\d+\] `(inputs/[^`]+)`', line) if match: source = (root / match.group(1)).read_text(encoding='utf-8') for heading in re.findall('“([^”]+)”', line): assert '## ' + heading in source, (match.group(1), heading) archive = p / 'original-submission' manifest = json.loads((archive / 'manifest.json').read_text(encoding='utf-8')) for name, digest in manifest.items(): assert hashlib.sha256((archive / name).read_bytes()).hexdigest() == digest result = '\n'.join('- ' + k.replace('_', ' ') + ': ' + str(v) for k, v in counts.items()) notes_path = p / 'editor-notes.md' notes = notes_path.read_text(encoding='utf-8').split('\n### Automated check results\n')[0] notes_path.write_text(notes + '\n### Automated check results\n\n' + result + '\n\nAll automated assertions passed, including JSON fields, matching headline, length limits, citation definitions and source headings, arithmetic, and original-submission manifest verification. Word counts use whitespace separation. These are format/arithmetic/archive-integrity checks, not product tests.\n', encoding='utf-8') print(result) print('All assertions passed.')