"""Static packaging, preservation and independent decimal arithmetic review. Run from the workspace root: python3 output/review_checks.py. Browser behavior is recorded separately; this script does not execute JavaScript. """ from collections import Counter from decimal import Decimal from html.parser import HTMLParser from pathlib import Path import hashlib, json out = Path(__file__).resolve().parent workspace = out.parent class Page(HTMLParser): def __init__(self, source): super().__init__() self.text = [] self.elements = [] self.feed(source) def handle_data(self, data): if data.strip(): self.text.append(' '.join(data.split())) def handle_starttag(self, tag, attrs): self.elements.append((tag, dict(attrs))) old = Page((workspace/'site/index.html').read_text()) new = Page((out/'site/index.html').read_text()) assert not (Counter(old.text) - Counter(new.text)), 'Original visible text removed' ids = [attrs['id'] for _, attrs in new.elements if 'id' in attrs] assert len(ids) == len(set(ids)) assert {attrs['for'] for tag, attrs in new.elements if tag == 'label'} == {'name', 'email', 'seats'} assert all(value in ids for value in ['name', 'email', 'seats', 'total', 'status', 'signup']) assets = [attrs.get('src') or attrs.get('href') for tag, attrs in new.elements if tag in ['script', 'link']] assert assets == ['style.css', 'app.js'] assert all((out/'site'/asset).is_file() for asset in assets) assert {p.name for p in (out/'site').iterdir()} == {'index.html', 'style.css', 'app.js', 'server.py'} assert (out/'site/server.py').read_bytes() == (workspace/'site/server.py').read_bytes() assert all((out/'site'/name).read_bytes() == (workspace/'original_submission/site'/name).read_bytes() for name in ['index.html', 'style.css', 'app.js', 'server.py']) style = (out/'site/style.css').read_text() assert all(color in style for color in ['#152a45', '#e78136', '#edf1f5']) expected = {1:'268.80', 2:'537.60', 3:'725.76', 8:'1935.36'} calculations = [] for seats, value in expected.items(): subtotal = Decimal(seats) * Decimal('240') discount = subtotal * (Decimal('.10') if seats >= 3 else Decimal('0')) tax = (subtotal - discount) * Decimal('.12') total = subtotal - discount + tax assert f'{total:.2f}' == value calculations.append({'seats':seats, 'subtotal':f'{subtotal:.2f}', 'discount':f'{discount:.2f}', 'tax':f'{tax:.2f}', 'total':f'{total:.2f}'}) handler_report = json.loads((out/'server-checks.json').read_text()) assert len(handler_report['checks']) == 22 assert all(case['pass'] for case in handler_report['checks']) assert sum(case['status'] == 201 for case in handler_report['checks']) == 4 assert sum(case['status'] == 400 for case in handler_report['checks']) == 18 assert (out/'server-checks.json').read_bytes() == (workspace/'original_submission/server-checks.json').read_bytes() report = { 'scope':'Static review and independent Decimal arithmetic; not JavaScript execution, rendering or HTTP transport.', 'checks':{ 'all_original_html_text_preserved':True, 'unique_ids_and_matching_labels':True, 'local_assets_exist_no_external_asset_links':True, 'runnable_site_contains_only_four_required_files_no_test_leads':True, 'supplied_server_unchanged':True, 'all_four_site_files_unchanged_from_original_submission':True, 'original_palette_present':True, 'handler_test_rerun_matches_original_results_22_passes':True }, 'calculator_reference':'inputs/brief.md — Workshop site acceptance brief', 'decimal_calculations':calculations, 'site_sha256':{name:hashlib.sha256((out/'site'/name).read_bytes()).hexdigest() for name in ['index.html', 'style.css', 'app.js', 'server.py']} } (out/'review-checks.json').write_text(json.dumps(report, indent=2) + '\n') print(json.dumps(report, indent=2))