← back to Dw Yolo Loop
scripts/zero-sample-sweep/zero-sample-sweep.mjs
87 lines
// zero-sample-sweep — READ-ONLY, $0. Cycle 68 (DTD-picked A, unanimous).
// Sizes the c67 P1 by the OFFICER-SPECIFIED SIGNATURE across vendors:
// single-variant + variant title ~ "Sample" + price == $0.00 + available==true
// = an orderable $0 sample = free-checkout exposure (the RL bug, 111 found in c67).
// METHOD: (Phase 1) discovery scan of the reachable global /products.json (Shopify
// caps unauth at page 100 = ~25k of ~74k → coverage caveat NAMED), classify by signature,
// GROUP affected by vendor. (Phase 2) for each affected vendor, page its full
// /collections/<handle>/products.json for the COMPLETE per-vendor count (reaches products
// beyond the 25k cap). Secondary bucket: single-variant "Sample" at a non-$0/non-$4.25
// price (mis-seed in other directions). NEGATIVE CONTROL: count a healthy multi-variant
// priced product as NOT-defect + reproduce RL in the affected-vendor list.
// EXCLUDES Phillip Jeffries.
const WWW='https://www.designerwallcoverings.com';
const UA='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36';
const sleep=ms=>new Promise(r=>setTimeout(r,ms));
async function get(u){for(let a=0;a<5;a++){const r=await fetch(u,{headers:{'User-Agent':UA}});if(r.status===429){await sleep(2500*(a+1));continue;}return{status:r.status,text:await r.text()};}return{status:429,text:''};}
const PJ=/phillip[- ]?jeffries/i;
const isSample=t=>/sample/i.test(t||'');
function classify(p){
const vs=p.variants||[];
if(vs.length!==1) return 'multi';
const v=vs[0]; const price=parseFloat(v.price);
if(isNaN(price)) return 'multi';
if(!isSample(v.title)) return price===0?'zero-nonsample':'ok-single';
// single-variant Sample:
if(price===0) return 'zero-sample'; // THE P1 signature
if(price===4.25) return 'ok-sample-425'; // legit showroom-line
return 'abnormal-sample'; // mis-seed other direction
}
// ---- Phase 1: discovery scan of reachable /products.json (cap ~page 100) ----
console.log(`=== zero-sample-sweep (READ-ONLY, $0) ===\nPhase 1: discovery scan of reachable /products.json (cap ~25k of ~74k)\n`);
let scanned=0, zeroSample=0, abnormalSample=0, zeroNonsample=0, okSingle=0, ok425=0, multi=0, pjSkip=0;
const vendZero={}, vendAbnormal={}; const zeroExamples=[], multiCtrl=[];
for(let page=1; page<=100; page++){
const r=await get(`${WWW}/products.json?limit=250&page=${page}`);
let ps=[]; try{ps=JSON.parse(r.text).products||[];}catch{}
if(ps.length===0) break;
for(const p of ps){
if(PJ.test(p.vendor||'')){ pjSkip++; continue; }
scanned++;
const c=classify(p);
if(c==='zero-sample'){ zeroSample++; vendZero[p.vendor]=(vendZero[p.vendor]||0)+1; if(zeroExamples.length<8) zeroExamples.push({h:p.handle,vendor:p.vendor,avail:p.variants[0].available}); }
else if(c==='abnormal-sample'){ abnormalSample++; vendAbnormal[p.vendor]=(vendAbnormal[p.vendor]||0)+1; }
else if(c==='zero-nonsample') zeroNonsample++;
else if(c==='ok-single') okSingle++;
else if(c==='ok-sample-425') ok425++;
else { multi++; if(multiCtrl.length<4) multiCtrl.push({h:p.handle,prices:(p.variants||[]).map(v=>v.price)}); }
}
if(page%20===0) console.log(` page ${page}/100 scanned=${scanned} zero-sample=${zeroSample}`);
await sleep(250);
}
console.log(`\n--- Phase 1 results (${scanned} products scanned, ~${(100*scanned/74000).toFixed(0)}% of fleet) ---`);
console.log(` zero-sample (P1 signature): ${zeroSample}`);
console.log(` abnormal-sample (non-$0,non-$4.25): ${abnormalSample}`);
console.log(` zero-NONsample (single $0, not titled Sample): ${zeroNonsample}`);
console.log(` ok single-variant: ${okSingle} | ok $4.25 sample: ${ok425} | multi-variant: ${multi} | PJ-skip: ${pjSkip}`);
console.log(`\n vendors with zero-sample bug (in-scan counts):`);
Object.entries(vendZero).sort((a,b)=>b[1]-a[1]).forEach(([v,n])=>console.log(` ${v}: ${n}`));
// ---- Phase 2: per affected vendor, full collection count ----
console.log(`\nPhase 2: full per-vendor collection counts (reaches beyond the 25k cap)`);
const vendHandle=v=>(v||'').toLowerCase().trim().replace(/&/g,'').replace(/[^a-z0-9]+/g,'-').replace(/^-|-$/g,'');
const vendorFull={};
for(const v of Object.keys(vendZero)){
const h=vendHandle(v); let total=0, zs=0, page=1, ok=false;
while(page<=12){ const r=await get(`${WWW}/collections/${h}/products.json?limit=250&page=${page}`); let ps=[]; try{ps=JSON.parse(r.text).products||[];}catch{break;} if(ps.length===0)break; ok=true;
for(const p of ps){ if(PJ.test(p.vendor||''))continue; total++; if(classify(p)==='zero-sample') zs++; } page++; await sleep(250); }
vendorFull[v]={handle:h, collectionFound:ok, total, zeroSample:zs};
console.log(` ${v} (/collections/${h}): ${ok?`${zs} zero-sample of ${total} total`:'collection-handle not found → in-scan count only'}`);
}
const grandZeroFull=Object.values(vendorFull).reduce((s,x)=>s+(x.collectionFound?x.zeroSample:0),0);
const inScanOnlyVendors=Object.values(vendorFull).filter(x=>!x.collectionFound);
console.log(`\n=== TOTALS ===`);
console.log(`zero-sample (P1) — full count for vendors w/ resolvable collection: ${grandZeroFull}`);
console.log(`zero-sample — Phase-1 in-scan total (lower bound, all vendors): ${zeroSample}`);
if(inScanOnlyVendors.length) console.log(`(${inScanOnlyVendors.length} affected vendor(s) had no resolvable collection handle → counted only within the 25k scan)`);
console.log(`\n-- NEGATIVE CONTROL --`);
console.log(` healthy multi-variant priced (NOT flagged) examples:`); multiCtrl.forEach(m=>console.log(` ${m.h.slice(0,40)} prices=${JSON.stringify(m.prices)}`));
console.log(` zero-sample examples (flagged, available shown):`); zeroExamples.forEach(z=>console.log(` ${z.h.slice(0,40)} [${z.vendor}] available=${z.avail}`));
console.log(` RL reproduced in affected list: ${Object.keys(vendZero).some(v=>/ralph/i.test(v))?'YES':'no (check coverage)'}`);
import fs from 'fs';
fs.writeFileSync('/tmp/zero-sample-sweep.json',JSON.stringify({ts:new Date().toISOString(),scanned,zeroSample,abnormalSample,zeroNonsample,okSingle,ok425,multi,pjSkip,vendZero,vendAbnormal,vendorFull,grandZeroFull,zeroExamples,multiCtrl},null,2));
console.log('\nwrote /tmp/zero-sample-sweep.json');