From 0e508312c96c411c013fa70591d3fcfab4110ad1 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 17 Nov 2026 10:06:15 -0600 Subject: [PATCH] Dormant import honors dry (it wrote rows even with dry: true); e2e 125/125 Not deployed: ships with the go-live deploy. Co-Authored-By: Claude Opus 5.5 --- qa/e2e.mjs | 2 ++ server.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/qa/e2e.mjs b/qa/e2e.mjs index 7f6ea99..51d981d 100644 --- a/qa/e2e.mjs +++ b/qa/e2e.mjs @@ -248,6 +248,8 @@ async function main() { for (const [from, to] of [['/?oldmember', '/memberone'], ['/index.php?oldmember', '/memberone'], ['/splashpg.php?r=oldmember', '/memberone'], ['/lcp.php?r=oldmember', '/memberone'], ['/join.php?r=oldmember', '/memberone'], ['/login.php', '/my'], ['/faq.php', '/guides/faq'], ['/whatever.php', '/'], ['/?oldtwo', '/membertwo'], ['/?OLDTWO', '/membertwo'], ['/?dup', '/'], ['/?nobody', '/']]) { const x = await fetch(BASE + from, { redirect: 'manual' }); ok(x.status === 301 && x.headers.get('location') === to, 'old link ' + from + ' -> ' + to, x.headers.get('location')); } + { const dr = await admin('/api/admin/dormant', { dry: true, packets: [{ oldId: '10010', oldUsername: 'oldm2', hubId: 'h_' + '2'.repeat(16), name: 'Team Build Machine', url: 'https://teambuildmachine.example.com/oldm2', added: '2022-04-21' }] }); + const st = await admin('/api/admin/status'); ok(dr.dry && dr.created === 1 && st.packets.dormant === 0, 'dormant import dry run counts and writes nothing', [dr, st.packets]); } r = await admin('/api/admin/dormant', { packets: [{ oldId: '10010', oldUsername: 'oldm2', hubId: 'h_' + '2'.repeat(16), name: 'Team Build Machine', url: 'https://teambuildmachine.example.com/oldm2', added: '2022-04-21' }, { oldId: 'x', hubId: 'h_1', name: 'bad', url: 'nope' }] }); ok(r.created === 1 && r.skipped === 1, 'dormant import: 1 created, a bad row skipped', r); const my2 = await cM2.get('/api/my'); const dm = my2.j.dormant && my2.j.dormant[0]; diff --git a/server.js b/server.js index e90672b..07d5b5c 100644 --- a/server.js +++ b/server.js @@ -598,7 +598,8 @@ const server = http.createServer(async (req, res) => { if (!/^\d{1,9}$/.test(oldId) || !/^h_[0-9a-f]{16}$/.test(hubId) || store.packets().some(x => x.old && x.old.oldId === oldId)) { skipped++; continue; } const name = cleanText(r.name, C.packet.name).slice(0, C.packet.name); const url = String(r.url || '').trim().slice(0, 500); if (name.length < 2 || !/^https?:\/\//i.test(url)) { skipped++; continue; } - store.addPacket({ owner: '', ownerName: null, status: 'dormant', stage: 'sprouting', name, url: '', desc: '', old: { oldId, oldUsername: String(r.oldUsername || '').slice(0, 40), hubId, url, added: String(r.added || '').slice(0, 10) } }); created++; + if (!b.dry) store.addPacket({ owner: '', ownerName: null, status: 'dormant', stage: 'sprouting', name, url: '', desc: '', old: { oldId, oldUsername: String(r.oldUsername || '').slice(0, 40), hubId, url, added: String(r.added || '').slice(0, 10) } }); + created++; // with dry: counted, nothing written (it used to write anyway) } return json(res, 200, { ok: true, created, skipped, dry: !!b.dry }); }