"""Preserve the initial files, clarify the deliverables, and audit the revision.""" from pathlib import Path from decimal import Decimal import csv import hashlib import runpy out = Path('output') archive = out / 'original_submission' archive.mkdir(exist_ok=True) names = ['recommendation.md', 'comparison.csv', 'build_comparison.py'] for name in names: dest = archive / name if not dest.exists(): dest.write_bytes((out/name).read_bytes()) # Preserve and check byte-identical original copies before any revision. original_hashes = {n: hashlib.sha256((archive/n).read_bytes()).hexdigest() for n in names} text = (archive/'recommendation.md').read_text(encoding='utf-8') text = text.replace('**Choose O2: Forge Studio 16, SKU F16-32, from Harbour Tech.**', '**Choose O2: Forge Studio 16, SKU F16-32, from Harbour Tech** for the Vancouver editor, under the GPU interpretation below.') text = text.replace('with no additional fees or discounts.', 'with no other fees; listed discounts are already applied.') text = text.replace('These interpretations underlie the qualification assessment.', 'All hardware-pass and qualification assessments below and in comparison.csv use this GPU interpretation, not an independently verified GPU-class flag. The CSV labels those assessments explicitly.') text = text.replace('seek a written delivery commitment by October 23 for O5, retaining its exact SKU and landed price within budget.', 'seek a written guarantee that O5 / P16-32 will arrive in Vancouver no later than October 23, 2026, retaining its exact SKU and landed price within budget.') (out/'recommendation.md').write_text(text, encoding='utf-8') script = (archive/'build_comparison.py').read_text(encoding='utf-8') script = script.replace("'hardware_pass'", "'hardware_pass_under_gpu_interpretation'") script = script.replace('hardware_pass=str(hw)', 'hardware_pass_under_gpu_interpretation=str(hw)') script = script.replace("'qualifies'", "'qualifies_under_gpu_interpretation'") script = script.replace('qualifies=str(hw and budget and timely)', 'qualifies_under_gpu_interpretation=str(hw and budget and timely)') script = script.replace("open(root/'inputs/S1-manufacturer-specs.csv', newline='')", "open(root/'inputs/S1-manufacturer-specs.csv', newline='', encoding='utf-8')") script = script.replace("open(root/'inputs/S2-store-offers.csv', newline='')", "open(root/'inputs/S2-store-offers.csv', newline='', encoding='utf-8')") script = script.replace("open(root/'output/comparison.csv','w',newline='')", "open(root/'output/comparison.csv','w',newline='',encoding='utf-8')") script = script.replace("open(root/'output/comparison.csv',newline='')", "open(root/'output/comparison.csv',newline='',encoding='utf-8')") script = script.replace(".read_text()", ".read_text(encoding='utf-8')") (out/'build_comparison.py').write_text(script, encoding='utf-8') runpy.run_path(str(out/'build_comparison.py')) # Independent CSV read-back, source joins, arithmetic, statuses and citations audit. def read_csv(path): with open(path, encoding='utf-8', newline='') as f: reader = csv.DictReader(f) fields = reader.fieldnames rows = list(reader) assert len(fields) == len(set(fields)) assert all(None not in r and all(v is not None for v in r.values()) for r in rows) return rows rows = read_csv(out/'comparison.csv') offers = {r['offer_id']: r for r in read_csv('inputs/S2-store-offers.csv')} specs = {r['sku']: r for r in read_csv('inputs/S1-manufacturer-specs.csv')} assert len(rows) == len(offers) == 6 assert len({r['offer_id'] for r in rows}) == 6 assert {r['offer_id'] for r in rows} == set(offers) expected_hardware = {'O1':True,'O2':True,'O3':False,'O4':False,'O5':True,'O6':True} for r in rows: offer = offers[r['offer_id']] spec = specs[offer['sku']] for k in ['sku','model','os','ram_gb','ssd_gb','gpu','vram_gb','weight_kg']: assert r[k] == spec[k] assert r['store'] == offer['store'] assert r['listing_note'] == offer['listing_note'] assert r['condition'] == 'new' # Calculate in integer cents independently of generator Decimal arithmetic. price_cents = int(offer['price_cad'])*100 ship_cents = int(offer['shipping_cad'])*100 subtotal = price_cents + ship_cents assert subtotal*12 % 100 == 0 tax = subtotal*12//100 total = subtotal+tax for field, cents in [('price_cad',price_cents),('shipping_cad',ship_cents),('tax_base_cad',subtotal),('tax_cad',tax),('landed_total_cad',total),('budget_headroom_cad',220000-total)]: assert Decimal(r[field])*100 == cents assert r['hardware_pass_under_gpu_interpretation'] == str(expected_hardware[r['offer_id']]).lower() assert r['budget_pass'] == str(total<=220000).lower() assert r['original_delivery'] == offer['delivery'] assert r['original_delivery_type'] == offer['delivery_type'] assert r['effective_delivery'] == ('2026-10-27' if r['offer_id']=='O6' else offer['delivery']) assert r['effective_delivery_type'] == offer['delivery_type'] assert r['confirmed_by_deadline'] == str(r['offer_id'] not in ['O5','O6']).lower() assert r['qualifies_under_gpu_interpretation'] == str(r['offer_id']=='O2').lower() assert spec['sku'] in r['hardware_source'] and r['offer_id'] in r['commercial_source'] for field in ['hardware_source','commercial_source','policy_source','correction_source']: if r[field]: assert Path(r[field].split(',')[0]).is_file() assert f'{Decimal(r["landed_total_cad"]):,.2f}' in text assert len(text.split())<=650 assert original_hashes == {n: hashlib.sha256((archive/n).read_bytes()).hexdigest() for n in names} log = ['PASS: Independent integer-cent tax, shipping, landed totals and budget headroom checks for all six offers.', 'PASS: All hardware fields, store identities and original listing notes match exact source records.', 'PASS: CSV parses as UTF-8 with unique headers, six unique offer records, and consistent field counts.', 'PASS: O3/O4 hardware conflicts, O5 uncommitted delivery, O6 corrected deadline and all statuses checked.', 'PASS: Referenced source files exist; recommendation landed totals agree with CSV.', f'PASS: Recommendation word count (whitespace-delimited): {len(text.split())}, below 650.', 'PASS: Archived original files retained with unchanged SHA-256 hashes during revision.', 'Original file SHA-256 hashes:'] log += [f'{n}: {h}' for n,h in original_hashes.items()] (out/'review_checks.txt').write_text('\n'.join(log)+'\n',encoding='utf-8') print('\n'.join(log))