From 98e1e0e2791f6af6246afea79953ae2f2df5b362 Mon Sep 17 00:00:00 2001 From: William Mantly Date: Mon, 27 Jul 2026 23:57:41 -0400 Subject: [PATCH] Add regression test: no native alert()/confirm()/prompt() Native confirm() blocks all further browser events on the page (found live, mid browser-automation testing, on sso-manager-node's equivalent secret-rotate flow -- it froze the tab). This app has no such call sites (never did); this static check (scans views/ and public/js|lib/js for bare alert(/confirm(/prompt() calls) keeps it that way. Co-Authored-By: Claude Sonnet 5 --- nodejs/test/unit/no_native_dialogs.test.js | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 nodejs/test/unit/no_native_dialogs.test.js diff --git a/nodejs/test/unit/no_native_dialogs.test.js b/nodejs/test/unit/no_native_dialogs.test.js new file mode 100644 index 0000000..985a03b --- /dev/null +++ b/nodejs/test/unit/no_native_dialogs.test.js @@ -0,0 +1,43 @@ +'use strict'; + +// Regression guard: native alert()/confirm()/prompt() calls block all further +// browser events on the page (found live, mid browser-automation testing, on +// sso-manager-node's equivalent secret-rotate flow) and are visually +// inconsistent with the rest of the UI. This app has no such call sites; +// keep it that way. + +const { test } = require('node:test'); +const assert = require('node:assert'); +const fs = require('fs'); +const path = require('path'); + +const ROOTS = ['views', 'public/js', 'public/lib/js'].map((d) => path.join(__dirname, '..', '..', d)); + +const NATIVE_DIALOG_RE = /(^|[^.\w$])(alert|confirm|prompt)\s*\(/g; + +function walk(dir) { + let files = []; + if (!fs.existsSync(dir)) return files; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const full = path.join(dir, entry.name); + if (entry.isDirectory()) files = files.concat(walk(full)); + else if (/\.(ejs|js)$/.test(entry.name)) files.push(full); + } + return files; +} + +test('no view or client-side script calls native alert()/confirm()/prompt()', () => { + const offenders = []; + for (const root of ROOTS) { + for (const file of walk(root)) { + const src = fs.readFileSync(file, 'utf8'); + let m; + NATIVE_DIALOG_RE.lastIndex = 0; + while ((m = NATIVE_DIALOG_RE.exec(src))) { + const line = src.slice(0, m.index).split('\n').length; + offenders.push(`${path.relative(path.join(__dirname, '..', '..'), file)}:${line} — ${m[2]}(`); + } + } + } + assert.deepStrictEqual(offenders, []); +});