from pathlib import Path import json import re p = Path('output') a = (p / 'article.md').read_text() m = json.loads((p / 'metadata.json').read_text()) assert set(m) == {'headline', 'excerpt', 'search_description'} assert a.splitlines()[0] == '# ' + m['headline'] body = a.split('\n', 1)[1].split('## Sources')[0] counts = { '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']), } assert 600 <= counts['article_body_words_including_section_headings'] <= 800 assert 600 <= counts['article_all_words_including_title_and_sources'] <= 800 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+)\]', a)) assert refs == {'1', '2', '3', '4', '5'} result = '\n'.join('- ' + k.replace('_', ' ') + ': ' + str(v) for k, v in counts.items()) notes_path = p / 'editor-notes.md' notes = notes_path.read_text() marker = '\n### Automated check results\n' notes = notes.split(marker)[0] notes_path.write_text(notes + marker + '\n' + result + '\n\nAll automated assertions passed. Word counts use whitespace separation; both the body-only and full Markdown counts fall within 600–800. These are format/arithmetic checks, not product tests.\n') print(result) print('All assertions passed.')