[object Object]

← back to Tk 11331 Exec

TK-11392: reuse the D1 reorder executor for the 26 DW Bespoke Studio $12-sample products

8d31248b952e363c9bb593e6227e124bce7efaf2 · 2026-09-10 13:29:38 -0700 · Steve Abrams

- --set= / --restore= so a second product set can reuse the proven path
- --any-sample-price relaxes the hard $4.25 guard (default behaviour unchanged)
- isSample() now takes a variant and also matches the TITLE, since the Bespoke
  Studio samples are marked only in the title, not the SKU
- fix: the post-write verify passed a string into the new object predicate,
  which would have silently reported every product as PASS

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

Files touched

Diff

commit 8d31248b952e363c9bb593e6227e124bce7efaf2
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Sep 10 13:29:38 2026 -0700

    TK-11392: reuse the D1 reorder executor for the 26 DW Bespoke Studio $12-sample products
    
    - --set= / --restore= so a second product set can reuse the proven path
    - --any-sample-price relaxes the hard $4.25 guard (default behaviour unchanged)
    - isSample() now takes a variant and also matches the TITLE, since the Bespoke
      Studio samples are marked only in the title, not the SKU
    - fix: the post-write verify passed a string into the new object predicate,
      which would have silently reported every product as PASS
    
    Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---
 d1_reorder.mjs        |  30 ++++++++----
 data/tk11392_set.json | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 153 insertions(+), 9 deletions(-)

diff --git a/d1_reorder.mjs b/d1_reorder.mjs
index d25dd96..9a81fc4 100644
--- a/d1_reorder.mjs
+++ b/d1_reorder.mjs
@@ -4,14 +4,25 @@ import fs from 'fs';
 import {gql,sleep} from './lib.mjs';
 const APPLY=process.argv.includes('--apply');
 const LIMIT=parseInt((process.argv.find(a=>a.startsWith('--limit='))||'').split('=')[1]||'99999');
-const d1=JSON.parse(fs.readFileSync('data/d1_set.json','utf8')).slice(0,LIMIT);
-const RESTORE='data/d1-restore-map.jsonl';
+const arg=n=>(process.argv.find(a=>a.startsWith('--'+n+'='))||'').split('=')[1];
+// TK-11392: reuse this proven executor for the 26 DW Bespoke Studio products whose
+// position 1 is a $12 sample (not the $4.25 one this script was written for).
+const SET=arg('set')||'data/d1_set.json';
+const ANY_SAMPLE_PRICE=process.argv.includes('--any-sample-price');
+const d1=JSON.parse(fs.readFileSync(SET,'utf8')).slice(0,LIMIT);
+const RESTORE=arg('restore')||'data/d1-restore-map.jsonl';
 const rstream=fs.createWriteStream(RESTORE,{flags:'a'});
 const M=`mutation($pid:ID!,$moves:[ProductVariantPositionInput!]!){
   productVariantsBulkReorder(productId:$pid,positions:$moves){
     userErrors{field message} }}`;
-const VQ=`query($id:ID!){product(id:$id){variants(first:20){nodes{id sku position price}}}}`;
-const isSample=s=>{s=(s||'').toLowerCase();return s.endsWith('sample');};
+const VQ=`query($id:ID!){product(id:$id){variants(first:100){nodes{id sku title position price}}}}`;
+// Sample detection: SKU suffix is the original signal; TITLE match covers the DW Bespoke
+// Studio set, whose sample variants are marked only in the title ("... 2ft x 1ft Sample").
+const isSample=v=>{
+  const sku=(v.sku||'').toLowerCase();
+  if(sku.endsWith('sample')) return true;
+  return /\bsample\b/i.test(v.title||'');
+};
 
 let ok=0,fail=0,skipped=0; const fails=[];
 console.log(`${APPLY?'APPLY':'DRY-RUN'} D1 reorder — ${d1.length} products`);
@@ -19,13 +30,14 @@ for(const p of d1){
   // re-read live to be authoritative right before write
   const live=(await gql(VQ,{id:p.gid})).product.variants.nodes.sort((a,b)=>a.position-b.position);
   const p1=live[0];
-  const sellable=live.filter(v=>!isSample(v.sku));
-  if(!(isSample(p1.sku) && Math.round(parseFloat(p1.price)*100)===425 && sellable.length)){
+  const sellable=live.filter(v=>!isSample(v));
+  const priceOk=ANY_SAMPLE_PRICE||Math.round(parseFloat(p1.price)*100)===425;
+  if(!(isSample(p1) && priceOk && sellable.length)){
     skipped++; console.log(`  SKIP ${p.pid} (live no longer sample@pos1)`); continue;
   }
   // target order: sellable(s) first (keep their relative order), then samples
-  const nonSample=live.filter(v=>!isSample(v.sku));
-  const samples=live.filter(v=>isSample(v.sku));
+  const nonSample=sellable;
+  const samples=live.filter(v=>isSample(v));
   const target=[...nonSample,...samples];
   const moves=target.map((v,i)=>({id:v.id,position:i+1}));
   if(!APPLY){ console.log(`  would reorder ${p.pid}: sellable ${nonSample[0].sku} -> pos1`); ok++; continue; }
@@ -38,7 +50,7 @@ for(const p of d1){
   await sleep(400);
   // verify
   const after=(await gql(VQ,{id:p.gid})).product.variants.nodes.sort((a,b)=>a.position-b.position);
-  if(!isSample(after[0].sku)){ ok++; if(ok%50===0)console.log(`  ok ${ok}`); }
+  if(!isSample(after[0])){ ok++; if(ok%50===0)console.log(`  ok ${ok}`); }
   else { fail++; fails.push({pid:p.pid,reason:'verify-still-sample-pos1'}); console.log(`  VERIFY-FAIL ${p.pid}`);}
   await sleep(150);
 }
diff --git a/data/tk11392_set.json b/data/tk11392_set.json
new file mode 100644
index 0000000..c775e9f
--- /dev/null
+++ b/data/tk11392_set.json
@@ -0,0 +1,132 @@
+[
+ {
+  "pid": "7664490446899",
+  "gid": "gid://shopify/Product/7664490446899",
+  "handle": "sunshine-mode-plaid-wallpaper-1"
+ },
+ {
+  "pid": "7664625287219",
+  "gid": "gid://shopify/Product/7664625287219",
+  "handle": "dig_62441_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664629514291",
+  "gid": "gid://shopify/Product/7664629514291",
+  "handle": "dig_55380_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664630628403",
+  "gid": "gid://shopify/Product/7664630628403",
+  "handle": "dig_521103_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664510402611",
+  "gid": "gid://shopify/Product/7664510402611",
+  "handle": "1800-s-colonial-scene-on-demand-wall-paper-vin-400-1"
+ },
+ {
+  "pid": "7664493133875",
+  "gid": "gid://shopify/Product/7664493133875",
+  "handle": "elegant-light-pink-and-gold-stripes-wallpaper-1"
+ },
+ {
+  "pid": "7664630530099",
+  "gid": "gid://shopify/Product/7664630530099",
+  "handle": "dig_521139_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664621125683",
+  "gid": "gid://shopify/Product/7664621125683",
+  "handle": "dig_74792_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664618799155",
+  "gid": "gid://shopify/Product/7664618799155",
+  "handle": "dig_5130217_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664592355379",
+  "gid": "gid://shopify/Product/7664592355379",
+  "handle": "zappys-authentic-1970s-reproduction-vintage-wallpaper-1-1"
+ },
+ {
+  "pid": "7664593764403",
+  "gid": "gid://shopify/Product/7664593764403",
+  "handle": "happy-days-revival-authentic-1970s-vintage-wallpaper-1"
+ },
+ {
+  "pid": "7664638591027",
+  "gid": "gid://shopify/Product/7664638591027",
+  "handle": "happy-1970-s-inspired-patterns-49-1"
+ },
+ {
+  "pid": "7664490315827",
+  "gid": "gid://shopify/Product/7664490315827",
+  "handle": "its-the-roaring-20s-magic-cocktails-and-cards-red-wallpaper-1"
+ },
+ {
+  "pid": "7664638033971",
+  "gid": "gid://shopify/Product/7664638033971",
+  "handle": "happy-1970-s-inspired-patterns-92-1"
+ },
+ {
+  "pid": "7664593240115",
+  "gid": "gid://shopify/Product/7664593240115",
+  "handle": "sallys-authentic-scenic-vintage-1950s-wallpaper-2-1"
+ },
+ {
+  "pid": "7664652779571",
+  "gid": "gid://shopify/Product/7664652779571",
+  "handle": "familjen-swedish-picture-frames-pattern-design-lab-dig-10911-1"
+ },
+ {
+  "pid": "1502509990000",
+  "gid": "gid://shopify/Product/1502509990000",
+  "handle": "love-chid-toile-cor-23324"
+ },
+ {
+  "pid": "7664632856627",
+  "gid": "gid://shopify/Product/7664632856627",
+  "handle": "dig_5011120_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664623288371",
+  "gid": "gid://shopify/Product/7664623288371",
+  "handle": "dig_74707_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664632037427",
+  "gid": "gid://shopify/Product/7664632037427",
+  "handle": "dig_51230_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "7664638459955",
+  "gid": "gid://shopify/Product/7664638459955",
+  "handle": "happy-1970-s-inspired-patterns-57-1"
+ },
+ {
+  "pid": "7663711682611",
+  "gid": "gid://shopify/Product/7663711682611",
+  "handle": "watercolor-dots-adrian1"
+ },
+ {
+  "pid": "7664622960691",
+  "gid": "gid://shopify/Product/7664622960691",
+  "handle": "dig_74731_vintage_wallpaper_designer_wallcoverings-1"
+ },
+ {
+  "pid": "1502418468976",
+  "gid": "gid://shopify/Product/1502418468976",
+  "handle": "palm-paradise-cor-23053"
+ },
+ {
+  "pid": "1502431117424",
+  "gid": "gid://shopify/Product/1502431117424",
+  "handle": "burlap-coffee-sack-cor-23099"
+ },
+ {
+  "pid": "7664650158131",
+  "gid": "gid://shopify/Product/7664650158131",
+  "handle": "goldo-custom-wallpaper-custom-digitally-print-gold-mylar-pat-dig-80000-1"
+ }
+]
\ No newline at end of file

← cfeb030 auto-data-snapshot: 2026-09-10T11:43:04 (1 data files) — scr  ·  back to Tk 11331 Exec  ·  auto-data-snapshot: 2026-09-10T13:39:50 (1 data files) — dat 5e97b33 →