import csv, re, os from decimal import Decimal, ROUND_HALF_UP def find(p): for base in ('.', '..'): q = os.path.join(base, p) if os.path.exists(q): return q raise SystemExit('missing ' + p) offers = list(csv.DictReader(open(find('inputs/S2-store-offers.csv')))) specs = {r['sku']: r for r in csv.DictReader(open(find('inputs/S1-manufacturer-specs.csv')))} comp = {r['offer_id']: r for r in csv.DictReader(open(find('output/comparison.csv')))} q = lambda d: d.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP) ok = True ncols = {len(r) for r in csv.reader(open(find('output/comparison.csv')))} print('column counts per row:', ncols) for o in offers: s = specs[o['sku']] sub = Decimal(o['price_cad']) + Decimal(o['shipping_cad']) tax = q(sub * Decimal('0.12')) total = q(sub * Decimal('1.12')) deliv = '2026-10-27' if o['offer_id'] == 'O6' else o['delivery'] exp = { 'pre_tax_subtotal_cad': str(q(sub)), 'tax_12pct_cad': str(tax), 'landed_total_cad': str(total), 'budget_margin_cad': str(q(Decimal('2200') - total)), 'budget_ok': 'PASS' if total <= 2200 else 'FAIL', 'ram_gb_S1': s['ram_gb'], 'ram_ok': 'PASS' if int(s['ram_gb']) >= 32 else 'FAIL', 'ssd_gb_S1': s['ssd_gb'], 'ssd_ok': 'PASS' if int(s['ssd_gb']) >= 1024 else 'FAIL', 'vram_gb_S1': s['vram_gb'], 'vram_ok': 'PASS' if int(s['vram_gb']) >= 8 else 'FAIL', 'os_ok': 'PASS' if s['os'] == 'Windows 11' else 'FAIL', 'gpu_S1': s['gpu'], 'weight_kg_S1': s['weight_kg'], 'model': s['model'], 'store': o['store'], 'delivery_date_effective': deliv, 'delivery_type': o['delivery_type'], 'delivery_ok': 'PASS' if (o['delivery_type'] == 'guaranteed' and deliv <= '2026-10-23') else 'FAIL', } c = comp[o['offer_id']] for k, v in exp.items(): if c[k] != v: ok = False print('MISMATCH', o['offer_id'], k, c[k], v) allpass = all(exp[k] == 'PASS' for k in exp if k.endswith('_ok')) print(o['offer_id'], total, 'ALL PASS' if allpass else 'fails', '|', c['status']) print('comparison.csv matches recomputation:', ok) txt = open(find('output/recommendation.md')).read() print('wc-style words:', len(txt.split())) for o in offers: t = q((Decimal(o['price_cad']) + Decimal(o['shipping_cad'])) * Decimal('1.12')) print(o['offer_id'], 'total in md:', f'{t:,}' in txt)