import json import re from pathlib import Path root = Path('output') article = (root / 'article.md').read_text() meta = json.loads((root / 'metadata.json').read_text()) body = article.split('\n', 1)[1] prose = re.sub(r'\[inputs/[^\]]+\]', '', body) counts = { 'article_words_excluding_headline_including_citations': len(body.split()), 'article_words_excluding_headline_and_citations': len(prose.split()), 'headline_characters': len(meta['headline']), 'excerpt_words': len(meta['excerpt'].split()), 'search_description_characters': len(meta['search_description']) } assert set(meta) == {'headline', 'excerpt', 'search_description'} assert article.splitlines()[0] == '# ' + meta['headline'] assert 600 <= counts['article_words_excluding_headline_including_citations'] <= 800 assert 600 <= counts['article_words_excluding_headline_and_citations'] <= 800 assert 50 <= counts['headline_characters'] <= 70 assert counts['excerpt_words'] <= 45 assert 140 <= counts['search_description_characters'] <= 160 citations = re.findall(r'(inputs/[\w.-]+) — ([^;\]]+)', article) for path, sections in citations: source = Path(path).read_text() for section in sections.split(', '): assert re.search(r'^#+ ' + re.escape(section) + r'\s*$', source, re.M), (path, section) assert 29 * 3 == 87 assert 87 + 12 == 99 assert (50 - 20) / 50 * 100 == 60 print(json.dumps({'counts': counts, 'citation_groups_checked': len(citations), 'status': 'PASS', 'checks': ['JSON schema keys and parsing', 'headline matches article', 'length constraints', 'cited files and section headings exist', 'price and percentage arithmetic']}, indent=2))