host: Playwright check for the relate picker (+ 2 bugs it caught)
Wire a browser check for the picker, run it against an ephemeral host server, and fix the two real bugs it surfaced. - lib/host/playwright/relate-picker.spec.js — drives login-redirect-return, JS candidate load + infinite scroll, debounced filter, and click-to-relate (asserting the relation shows on the post page). - lib/host/playwright/run-picker-check.sh — spins up an ephemeral host server (this worktree's binary + lib, temp persist), seeds a host post + 25 candidates, runs the spec in the main worktree's Playwright/chromium, tears everything down. No live-site dependency, no live-data pollution. 4/4 pass. Bugs the check caught: 1. Query params weren't %-decoded — dream's form parser decodes but its query parser doesn't, so a filter "Item 13" arrived as "Item%2013" and matched nothing. Fix: decode q with dream's own dr/url-decode in host/blog-relate- options. (+ conformance test for a spaced filter.) 2. A filter typed while a load was in flight got dropped (busy guard returned with no trailing fetch). Fix: a `pending` flag re-runs the load when the in-flight one finishes, coalescing to the latest query. 239/239 conformance; JS node --check clean. Verified live: spaced filter returns matches; served JS carries the pending-reload fix. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -155,7 +155,10 @@
|
||||
(define host/blog-relate-options
|
||||
(fn (req)
|
||||
(let ((slug (dream-param req "slug"))
|
||||
(q (or (dream-query-param req "q") ""))
|
||||
;; dream's query parser does not %-decode values (its form parser does),
|
||||
;; so a filter like "Item 13" arrives as "Item%2013" — decode it with
|
||||
;; dream's own dr/url-decode before matching.
|
||||
(q (dr/url-decode (or (dream-query-param req "q") "")))
|
||||
(offset (host/query-int req "offset" 0)))
|
||||
(let ((page (take (drop (host/blog--relate-candidates slug q) offset)
|
||||
host/blog--picker-limit)))
|
||||
@@ -167,7 +170,7 @@
|
||||
;; host serves static HTML (no SX hydration), so the interactive layer is a small
|
||||
;; vanilla script served from this route (read once, cached).
|
||||
(define host/blog-picker-js-src
|
||||
"(function(){var f=document.getElementById('relate-filter');if(!f)return;var r=document.getElementById('relate-results');var slug=f.getAttribute('data-slug'),off=0,q='',busy=false,done=false,t;function load(reset){if(busy||(!reset&&done))return;busy=true;if(reset){off=0;done=false;}fetch('/'+slug+'/relate-options?q='+encodeURIComponent(q)+'&offset='+off).then(function(x){return x.text();}).then(function(h){var d=document.createElement('div');d.innerHTML=h;var n=d.children.length;if(reset)r.innerHTML='';while(d.firstChild)r.appendChild(d.firstChild);off+=n;done=n<20;busy=false;}).catch(function(){busy=false;});}f.addEventListener('input',function(){clearTimeout(t);t=setTimeout(function(){q=f.value.trim();load(true);},200);});r.addEventListener('scroll',function(){if(r.scrollTop+r.clientHeight>=r.scrollHeight-40){load(false);}});load(true);})();")
|
||||
"(function(){var f=document.getElementById('relate-filter');if(!f)return;var r=document.getElementById('relate-results');var slug=f.getAttribute('data-slug'),off=0,q='',busy=false,done=false,pending=false,t;function load(reset){if(busy){if(reset)pending=true;return;}if(!reset&&done)return;busy=true;if(reset){off=0;done=false;}fetch('/'+slug+'/relate-options?q='+encodeURIComponent(q)+'&offset='+off).then(function(x){return x.text();}).then(function(h){var d=document.createElement('div');d.innerHTML=h;var n=d.children.length;if(reset)r.innerHTML='';while(d.firstChild)r.appendChild(d.firstChild);off+=n;done=n<20;busy=false;if(pending){pending=false;load(true);}}).catch(function(){busy=false;if(pending){pending=false;load(true);}});}f.addEventListener('input',function(){clearTimeout(t);t=setTimeout(function(){q=f.value.trim();load(true);},200);});r.addEventListener('scroll',function(){if(r.scrollTop+r.clientHeight>=r.scrollHeight-40){load(false);}});load(true);})();")
|
||||
(define host/blog-picker-js
|
||||
(fn (req)
|
||||
(dream-response 200 {:content-type "application/javascript; charset=utf-8"}
|
||||
|
||||
Reference in New Issue
Block a user