aboutsummaryrefslogtreecommitdiffstats
path: root/tools/comments-test.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-10-07 09:59:28 -0700
committerAdam Soltys <[email protected]>2026-10-07 09:59:28 -0700
commit6f3c5ac7f2accc2349c7bef9e5b06e9990fb194c (patch)
tree3895966e0db599c305880f036c3ff8bbfe346973 /tools/comments-test.js
parent95b72a73545cd2a3700b0e0866eee54e59d3b50e (diff)
downloadcoinosv3-6f3c5ac7f2accc2349c7bef9e5b06e9990fb194c.tar.gz
coinosv3-6f3c5ac7f2accc2349c7bef9e5b06e9990fb194c.zip
ark ui-test and comments-test: no more timing races
ark ui-test: wait for the selected balance card to stick before opening Receive (the carousel lands on a card's history, and a glide could settle back on Savings), wait for the first mailbox read before paying, paste addresses whole (typed a key at a time, a re-render mid-typing broke the checksum), and poll for alice's balance and the history rows. 8/8 runs. comments-test: the article and comments it fetched are handed to the app on every relay socket that asks, so it no longer depends on the app reaching the same public relays. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'tools/comments-test.js')
-rw-r--r--tools/comments-test.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/tools/comments-test.js b/tools/comments-test.js
index 01d47d5..6801f44 100644
--- a/tools/comments-test.js
+++ b/tools/comments-test.js
@@ -25,12 +25,31 @@ const html = await buildHtml({ minify: true, pwa: false });
const server = Bun.serve({ port: 5283, fetch: () => new Response(html, { headers: { 'content-type': 'text/html' } }) });
const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: 'new', args: ['--no-sandbox'] });
const page = await browser.newPage();
-await page.evaluateOnNewDocument(() => {
+// The article and its comments, fetched above, are also handed to the app
+// on every relay socket that asks for them: the app reaching the same public
+// relays as this script (one of them can be refusing this IP) is not what's
+// under test.
+await page.evaluateOnNewDocument((known) => {
window.__sent = [];
window.__all = [];
+ const matches = (f, e) => {
+ if (f.ids && !f.ids.includes(e.id)) return false;
+ if (f.kinds && !f.kinds.includes(e.kind)) return false;
+ if (f.authors && !f.authors.includes(e.pubkey)) return false;
+ for (const [k, vals] of Object.entries(f)) {
+ if (k[0] !== '#' || !Array.isArray(vals)) continue;
+ if (!e.tags.some((t) => t[0] === k.slice(1) && vals.includes(t[1]))) return false;
+ }
+ return !!(f.ids || Object.keys(f).some((k) => k[0] === '#'));
+ };
const send = WebSocket.prototype.send;
WebSocket.prototype.send = function (d) {
window.__all.push(this.url + ' ' + String(d).slice(0, 60));
+ if (typeof d === 'string' && d.startsWith('["REQ"')) {
+ const [, sub, ...filters] = JSON.parse(d);
+ const hits = known.filter((e) => filters.some((f) => matches(f, e)));
+ if (hits.length) setTimeout(() => { for (const e of hits) this.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(['EVENT', sub, e]) })); }, 30);
+ }
if (typeof d === 'string' && d.startsWith('["EVENT"')) { // every event: nothing leaves the test
const ev = JSON.parse(d)[1];
window.__sent.push(ev);
@@ -40,7 +59,7 @@ await page.evaluateOnNewDocument(() => {
}
return send.call(this, d);
};
-});
+}, [root, ...comments]);
const click = (t) => page.evaluate((x) => { const e = [...document.querySelectorAll('button')].find((n) => n.textContent.trim().toLowerCase().includes(x)); if (e) { e.click(); return true; } return false; }, t);
const waitText = async (x, ms = 25000) => { for (let i = 0; i < ms / 250; i++) { if ((await page.evaluate(() => document.body.innerText)).toLowerCase().includes(x)) return true; await sleep(250); } return false; };
const waitFor = async (fn, ms = 15000) => { for (let i = 0; i < ms / 200; i++) { if (await page.evaluate(fn)) return true; await sleep(200); } return false; };