Repository navigation
[do not merge] measure parse depth limits on 18.1.5 vs main per OS #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| const { it } = require('node:test'); | ||
| const { execSync } = require('node:child_process'); | ||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
|
|
||
| const forms = { | ||
| 'function calls': (n) => 'SELECT ' + 'f('.repeat(n) + '1' + ')'.repeat(n), | ||
| 'subqueries': (n) => 'SELECT ' + '(SELECT '.repeat(n) + '1' + ')'.repeat(n), | ||
| 'chained +1': (n) => 'SELECT 1' + '+1'.repeat(n), | ||
| 'plpgsql IF': (n) => 'CREATE FUNCTION f() RETURNS void LANGUAGE plpgsql AS $$ BEGIN ' + 'IF true THEN '.repeat(n) + 'NULL;' + ' END IF;'.repeat(n) + ' END $$', | ||
| }; | ||
| const fns = { 'function calls': ['parseSync', 'normalizeSync'], 'subqueries': ['parseSync', 'normalizeSync'], 'chained +1': ['parseSync', 'normalizeSync'], 'plpgsql IF': ['parsePlPgSQLSync'] }; | ||
|
|
||
| async function measure(lib) { | ||
| await lib.loadModule(); | ||
| const rows = []; | ||
| for (const [form, make] of Object.entries(forms)) { | ||
| for (const fn of fns[form]) { | ||
| let lo = 1, hi = 20000, err = ''; | ||
| const ok = (n) => { try { const r = lib[fn](make(n)); if (typeof r === 'string' && /memory exhausted|stack depth/.test(r)) { err = 'returned ' + r.slice(0, 40); return false; } return true; } catch (e) { err = `${e.name}: ${e.message}`.slice(0, 50); return false; } }; | ||
| if (ok(hi)) { rows.push(`${form} ${fn}: >= ${hi}`); continue; } | ||
| ok(hi); | ||
| const top = err; | ||
| while (lo < hi - 1) { const mid = (lo + hi) >> 1; if (ok(mid)) lo = mid; else hi = mid; } | ||
| ok(hi); | ||
| rows.push(`${form} ${fn}: max ${lo} (at ${hi}: ${err}; at 20000: ${top})`); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bug · medium Probe conflates any thrown error with depth failure The 📋 Prompt for AI AgentsIn versions/18/test/depth-probe.test.js line 26, rewrite |
||
| await lib.loadModule(); | ||
| } | ||
| } | ||
| return rows; | ||
| } | ||
|
|
||
| it('probe', async () => { | ||
| const dir = path.join(__dirname, '..', '.probe'); | ||
| fs.mkdirSync(dir, { recursive: true }); | ||
| execSync('npm pack libpg-query@18.1.5 --silent', { cwd: dir }); | ||
| execSync('tar xzf libpg-query-18.1.5.tgz', { cwd: dir }); | ||
| const old = require(path.join(dir, 'package', 'wasm', 'index.cjs')); | ||
| const cur = require('../wasm/index.cjs'); | ||
| const out = [`node ${process.version} ${process.platform} ${process.arch}`]; | ||
| for (const [name, lib] of [['18.1.5', old], ['main', cur]]) { | ||
| for (const row of await measure(lib)) out.push(`PROBE ${name} | ${row}`); | ||
| } | ||
| console.log(out.join('\n')); | ||
| }); | ||
|
Comment on lines
+33
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 bug · medium Probe test needs network and always passes The probe test runs 📋 Prompt for AI AgentsIn versions/18/test/depth-probe.test.js lines 33-45, make the probe robust: skip the test (e.g. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 bug · high
Test script drops all existing test suites
The
testscript in versions/18/package.json:34 now runs onlytest/depth-probe.test.js, replacing the original run of ten test suites (parsing,pg18,fingerprint,normalize,plpgsql,scan,errors,input-encoding,wasm-recovery,load-module). All ten files still exist inversions/18/test/but are no longer executed bynpm test, and no other script runs them. The entire regression suite, including error-handling and WASM-recovery coverage, silently stops running.📋 Prompt for AI Agents
In versions/18/package.json line 34, restore the
testscript to run all existing suites (test/parsing.test.js test/pg18.test.js test/fingerprint.test.js test/normalize.test.js test/plpgsql.test.js test/scan.test.js test/errors.test.js test/input-encoding.test.js test/wasm-recovery.test.js test/load-module.test.js) and add a separate script such as "test:probe": "node --test test/depth-probe.test.js" so the new depth probe runs alongside, not instead of, the regression suite.