import csv from decimal import Decimal from pathlib import Path root = Path('.') with open(root/'inputs/S1-manufacturer-specs.csv', newline='', encoding='utf-8') as f: specs = {r['sku']: r for r in csv.DictReader(f)} with open(root/'inputs/S2-store-offers.csv', newline='', encoding='utf-8') as f: offers = list(csv.DictReader(f)) issues = { 'O1': 'FAIL: CAD 38.88 over budget', 'O2': 'PASS: all hard requirements under stated GPU interpretation', 'O3': 'FAIL: 16 GB RAM and 512 GB SSD; listing title is not verified hardware', 'O4': 'FAIL: 6 GB VRAM; listing title is not verified hardware', 'O5': 'UNKNOWN: delivery by deadline not committed; does not qualify', 'O6': 'FAIL: corrected guaranteed delivery October 27 misses October 23 deadline', } fields = ['offer_id','sku','model','store','condition','os','ram_gb','ssd_gb','gpu','vram_gb','gpu_class_interpretation','weight_kg','price_cad','shipping_cad','tax_base_cad','tax_cad','landed_total_cad','budget_headroom_cad','original_delivery','original_delivery_type','effective_delivery','effective_delivery_type','hardware_pass_under_gpu_interpretation','budget_pass','confirmed_by_deadline','qualifies_under_gpu_interpretation','hard_failures_or_unknowns','listing_note','hardware_source','commercial_source','policy_source','correction_source','test_evidence'] rows=[] for o in offers: s=specs[o['sku']] base=Decimal(o['price_cad'])+Decimal(o['shipping_cad']) tax=(base*Decimal('0.12')).quantize(Decimal('0.01')) total=base+tax corrected=o['offer_id']=='O6' date='2026-10-27' if corrected else o['delivery'] hw=int(s['ram_gb'])>=32 and int(s['ssd_gb'])>=1000 and int(s['vram_gb'])>=8 and s['os']=='Windows 11' budget=total<=Decimal('2200') timely=o['delivery_type']=='guaranteed' and date<='2026-10-23' r={k:s[k] for k in ['sku','model','os','ram_gb','ssd_gb','gpu','vram_gb','weight_kg']} r.update({k:o[k] for k in ['offer_id','store','listing_note']}) r.update(condition='new',gpu_class_interpretation='Discrete inferred from named GX GPU and separate VRAM; no explicit S1 class flag',price_cad=f"{Decimal(o['price_cad']):.2f}",shipping_cad=f"{Decimal(o['shipping_cad']):.2f}",tax_base_cad=f'{base:.2f}',tax_cad=f'{tax:.2f}',landed_total_cad=f'{total:.2f}',budget_headroom_cad=f'{Decimal("2200")-total:.2f}',original_delivery=o['delivery'],original_delivery_type=o['delivery_type'],effective_delivery=date,effective_delivery_type=o['delivery_type'],hardware_pass_under_gpu_interpretation=str(hw).lower(),budget_pass=str(budget).lower(),confirmed_by_deadline=str(timely).lower(),qualifies_under_gpu_interpretation=str(hw and budget and timely).lower(),hard_failures_or_unknowns=issues[o['offer_id']],hardware_source='inputs/S1-manufacturer-specs.csv, SKU '+o['sku'],commercial_source='inputs/S2-store-offers.csv, '+o['offer_id'],policy_source='inputs/00-source-register.md, Scenario sources — captured October 19, 2026, 09:00 Pacific',correction_source='inputs/S3-store-correction.md, S3 — Direct Aspen correction — October 19, 2026, 08:45 Pacific; O6 / A15-32' if corrected else '',test_evidence='inputs/S4-independent-test.md, S4 — Edit Bench lab note — October 17, 2026: F16-32; one plugged-in 12-minute UHD H.264 Premiere Pro export in 8m40s; noticeable fans; not comparative' if o['offer_id']=='O2' else 'No test supplied for this exact SKU') rows.append(r) with open(root/'output/comparison.csv','w',newline='',encoding='utf-8') as f: w=csv.DictWriter(f,fieldnames=fields) w.writeheader() w.writerows(rows) # Read back and validate generated deliverables. with open(root/'output/comparison.csv',newline='',encoding='utf-8') as f: actual=list(csv.DictReader(f)) assert len(actual)==6 assert {r['offer_id'] for r in actual}=={o['offer_id'] for o in offers} assert [r['offer_id'] for r in actual if r['qualifies_under_gpu_interpretation']=='true']==['O2'] assert [r['landed_total_cad'] for r in actual]==['2238.88','2098.88','1790.88','1902.88','2126.88','2037.28'] assert actual[5]['effective_delivery']=='2026-10-27' assert actual[4]['confirmed_by_deadline']=='false' text=(root/'output/recommendation.md').read_text(encoding='utf-8') assert len(text.split())<=650 for r in actual: assert f"{Decimal(r['landed_total_cad']):,.2f}" in text print('PASS: all six offers covered; Decimal tax and totals checked; only O2 qualifies under stated GPU interpretation; O6 correction and O5 unconfirmed delivery reflected; recommendation totals agree with CSV.') print('Recommendation whitespace-delimited word count:',len(text.split()))