"""Validate the revised package locally; no product or network testing.""" import hashlib import json import re from decimal import Decimal from pathlib import Path p = Path(__file__).resolve().parent workspace = p.parent article = (p / 'article.md').read_text(encoding='utf-8') metadata = json.loads((p / 'metadata.json').read_text(encoding='utf-8')) notes = (p / 'editor-notes.md').read_text(encoding='utf-8') assert article.strip() and notes.strip() assert set(metadata) == {'headline', 'excerpt', 'search_description'} assert all(isinstance(v, str) and v.strip() for v in metadata.values()) assert article.splitlines()[0] == '# ' + metadata['headline'] body = article.split('\n', 1)[1] citation_pattern = r'\([^()]*`inputs/[^()]*\)' no_citations = re.sub(citation_pattern, '', body) prose = re.sub(r'^#{1,6}\s+', '', no_citations, flags=re.MULTILINE) counts = { 'Body whitespace tokens including heading markers and citations': len(body.split()), 'Body whitespace tokens excluding citations, including heading markers': len(no_citations.split()), 'Body words excluding citations and Markdown heading markers': len(prose.split()), 'Headline characters': len(metadata['headline']), 'Excerpt words': len(metadata['excerpt'].split()), 'Search description characters': len(metadata['search_description']), } for count in (len(body.split()), len(no_citations.split()), len(prose.split())): assert 600 <= count <= 800 assert 50 <= len(metadata['headline']) <= 70 assert len(metadata['excerpt'].split()) <= 45 assert 140 <= len(metadata['search_description']) <= 160 # Check every article source filename and quoted section heading within citations. source_count = 0 section_count = 0 for citation in re.findall(citation_pattern, article): refs = list(re.finditer(r'`(inputs/[^`]+)`', citation)) for i, ref in enumerate(refs): source = workspace / ref.group(1) text = source.read_text(encoding='utf-8') headings = set(re.findall(r'^#{1,6}\s+(.+)$', text, re.MULTILINE)) end = refs[i + 1].start() if i + 1 < len(refs) else len(citation) quoted_sections = re.findall(r'“([^”]+)”', citation[ref.end():end]) assert quoted_sections, 'Missing section for ' + ref.group(1) for section in quoted_sections: assert section in headings, (ref.group(1), section) section_count += 1 source_count += 1 seat = Decimal('29') base = 3 * seat assert base == 87 assert base + Decimal('12') == 99 assert base + (750 - 500) * Decimal('0.08') == 107 assert 50 - 20 == 30 assert Decimal(50 - 20) / Decimal(50) * 100 == 60 manifest_path = p / 'preservation-manifest.json' manifest = json.loads(manifest_path.read_text(encoding='utf-8')) for name, digest in manifest['original_submission_sha256'].items(): assert hashlib.sha256((p / 'original-submission' / name).read_bytes()).hexdigest() == digest for name, digest in manifest['input_sha256_at_review_start'].items(): assert hashlib.sha256((workspace / name).read_bytes()).hexdigest() == digest lines = [f'{key}: {value}' for key, value in counts.items()] lines += [ f'Article source references checked: {source_count}; section headings checked: {section_count}.', 'PASS: UTF-8 reads, nonempty deliverables, JSON schema keys/string values, headline match, length limits and arithmetic.', 'PASS: article citation filenames/section headings, original-submission hashes and input hashes unchanged since review began.', 'Scope: file/editorial validation only; no product, privacy, OCR or workflow tests. Claim support requires manual review.', ] report = '\n'.join(lines) + '\n' (p / 'check-results.txt').write_text(report, encoding='utf-8') print(report, end='')