Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
64e418c
test(v18): compare WASM depth and recovery in Firefox and WebKit
pyramation Nov 26, 2026
535aeb5
test(v18): isolate depth and preserve PostgreSQL grammar diagnostics
pyramation Nov 26, 2026
a7be2bc
test(v18): recognize 18.1.5 normalization diagnostics returned as str…
pyramation Nov 26, 2026
dcab3dc
fix(v18): preserve PL/pgSQL depth diagnostics as SqlError
pyramation Nov 26, 2026
e358969
test(v18): record the intended PL/pgSQL error type change
pyramation Nov 26, 2026
b92415c
Merge remote-tracking branch 'origin/main' into feat/wasm-browser-depth
pyramation Nov 26, 2026
fd94108
test(v18): exercise the normalizer after a real host overflow
pyramation Nov 26, 2026
26b1777
test(v18): confirm that depth losses survive WASM tiering
pyramation Nov 26, 2026
bf2418d
test(v18): dispose of each browser depth case before the next
pyramation Nov 26, 2026
5992acb
Merge remote-tracking branch 'origin/main' into feat/wasm-browser-depth
pyramation Nov 26, 2026
e08eb43
test(v18): bound the normalization probe by the grammar limit
pyramation Nov 26, 2026
d440c84
test(v18): allow only the verified PL/pgSQL result changes
pyramation Nov 26, 2026
82a713e
test(v18): decouple tiering warmup from browser tab timers
pyramation Nov 26, 2026
7485387
test(v18): budget for published normalization probes on macOS
pyramation Nov 26, 2026
2fd34e6
Merge remote-tracking branch 'origin/main' into feat/wasm-browser-depth
pyramation Nov 26, 2026
9587bf4
test(v18): check every browser depth diagnostic and prove host recovery
pyramation Nov 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,40 @@ jobs:
run: pnpm run test
working-directory: ${{ matrix.package.path }}

browser-depth:
name: Test v18 WASM depth in ${{ matrix.browser }}
needs: build-wasm
strategy:
fail-fast: false
matrix:
include:
- browser: firefox
os: ubuntu-latest
- browser: webkit
os: macos-latest
runs-on: ${{ matrix.os }}
timeout-minutes: 15
env:
WASM_TEST_BROWSER: ${{ matrix.browser }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.x'
- uses: pnpm/action-setup@v2
with:
version: 8.15.1
- run: pnpm install --frozen-lockfile
- uses: actions/download-artifact@v4
with:
name: wasm-artifacts-v18
path: versions/18/wasm/
- if: runner.os == 'Linux'
run: pnpm --dir versions/18 exec playwright install --with-deps "$WASM_TEST_BROWSER"
- if: runner.os == 'macOS'
run: pnpm --dir versions/18 exec playwright install "$WASM_TEST_BROWSER"
- run: pnpm --dir versions/18 test:browser

build-parser:
name: Build Parser Package 📦
needs: build-wasm
Expand Down
47 changes: 46 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ packages:
# Most malicious releases are found and yanked well inside that window.
minimumReleaseAge: 2880

# Exempt from the wait: 6 scope glob(s), 5 first-party package(s).
# Exempt from the wait: 6 scope glob(s), 6 first-party package(s).
# First-party membership comes from what pyramation publishes on npm — waiting on your own release protects nothing.
minimumReleaseAgeExclude:
- "@constructive-db/*"
Expand All @@ -34,6 +34,7 @@ minimumReleaseAgeExclude:
- "@pgpm/*"
- "@pgpmjs/*"
- "@pgsql/*"
- libpg-query
- nested-obj
- pg-proto-parser
- pnpm-policy
Expand Down
19 changes: 11 additions & 8 deletions templates/full/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,15 @@ function outOfMemoryError(): Error {
return error;
}

function plpgsqlError(message: string): Error {
if (message === 'out of memory') return outOfMemoryError();
// The PL/pgSQL C API gives the JS wrapper only the diagnostic text.
if (message === 'stack depth limit exceeded' || message.startsWith('memory exhausted at or near ')) {
return new SqlError(message);
}
return new Error(message);
}

function ensureLoaded() {
if (wasmModule) return;
if (memoryLimitError) throw memoryLimitError;
Expand Down Expand Up @@ -447,10 +456,7 @@ export const parsePlPgSQL = awaitInit(async (query: string): Promise<ParseResult
const resultStr = ptrToString(resultPtr);

// Success is always a JSON object; anything else is an error message
if (!resultStr.startsWith('{')) {
if (resultStr === 'out of memory') throw outOfMemoryError();
throw new Error(resultStr);
}
if (!resultStr.startsWith('{')) throw plpgsqlError(resultStr);

return JSON.parse(resultStr);
} finally {
Expand Down Expand Up @@ -547,10 +553,7 @@ export function parsePlPgSQLSync(query: string): ParseResult {
const resultStr = ptrToString(resultPtr);

// Success is always a JSON object; anything else is an error message
if (!resultStr.startsWith('{')) {
if (resultStr === 'out of memory') throw outOfMemoryError();
throw new Error(resultStr);
}
if (!resultStr.startsWith('{')) throw plpgsqlError(resultStr);

return JSON.parse(resultStr);
} finally {
Expand Down
9 changes: 7 additions & 2 deletions versions/18/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@
"wasm:rebuild": "pnpm wasm:make rebuild",
"wasm:clean": "pnpm wasm:make clean",
"wasm:clean-cache": "pnpm wasm:make clean-cache",
"test": "node --test 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/limits.test.js test/snapshots.test.js test/load-module.test.js"
"test": "node --test 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/limits.test.js test/snapshots.test.js test/load-module.test.js",
"test:browser": "node --test test/wasm-depth.browser.test.js"
},
"author": "Constructive <developers@constructive.io>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/constructive-io/libpg-query-node.git"
},
"devDependencies": {},
"devDependencies": {
"esbuild-wasm": "0.27.7",
"libpg-query-baseline": "npm:libpg-query@18.1.5",
"playwright": "1.61.1"
},
"dependencies": {
"@pgsql/types": "^18.0.0"
},
Expand Down
30 changes: 30 additions & 0 deletions versions/18/release-diff.allow.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
{
"allow": [
{
"id": [
"edge:plpgsql-if-blocks-5000:parsePlPgSQL",
"edge:plpgsql-if-blocks-10000:parsePlPgSQL"
],
"baseline": "18.2.7",
"published": "Error: memory exhausted at or near \"THEN\"",
"candidate": "SqlError: memory exhausted at or near \"THEN\"",
"reason": "The PostgreSQL grammar limit is reported as a SqlError with its existing diagnostic"
},
{
"id": [
"edge:plpgsql-begin-blocks-5000:parsePlPgSQL",
"edge:plpgsql-begin-blocks-10000:parsePlPgSQL"
],
"baseline": "18.2.7",
"published": "Error: memory exhausted at or near \"BEGIN\"",
"candidate": "SqlError: memory exhausted at or near \"BEGIN\"",
"reason": "The PostgreSQL grammar limit is reported as a SqlError with its existing diagnostic"
},
{
"id": [
"edge:plpgsql-loops-5000:parsePlPgSQL",
"edge:plpgsql-loops-10000:parsePlPgSQL"
],
"baseline": "18.2.7",
"published": "Error: memory exhausted at or near \"LOOP\"",
"candidate": "SqlError: memory exhausted at or near \"LOOP\"",
"reason": "The PostgreSQL grammar limit is reported as a SqlError with its existing diagnostic"
},
{
"id": [
"edge:*:parse",
Expand Down
19 changes: 11 additions & 8 deletions versions/18/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,15 @@ function outOfMemoryError(): Error {
return error;
}

function plpgsqlError(message: string): Error {
if (message === 'out of memory') return outOfMemoryError();
// The PL/pgSQL C API gives the JS wrapper only the diagnostic text.
if (message === 'stack depth limit exceeded' || message.startsWith('memory exhausted at or near ')) {
return new SqlError(message);
}
return new Error(message);
}

function ensureLoaded() {
if (wasmModule) return;
if (memoryLimitError) throw memoryLimitError;
Expand Down Expand Up @@ -454,10 +463,7 @@ export const parsePlPgSQL = awaitInit(async (query: string): Promise<ParseResult
const resultStr = ptrToString(resultPtr);

// Success is always a JSON object; anything else is an error message
if (!resultStr.startsWith('{')) {
if (resultStr === 'out of memory') throw outOfMemoryError();
throw new Error(resultStr);
}
if (!resultStr.startsWith('{')) throw plpgsqlError(resultStr);

return JSON.parse(resultStr);
} finally {
Expand Down Expand Up @@ -554,10 +560,7 @@ export function parsePlPgSQLSync(query: string): ParseResult {
const resultStr = ptrToString(resultPtr);

// Success is always a JSON object; anything else is an error message
if (!resultStr.startsWith('{')) {
if (resultStr === 'out of memory') throw outOfMemoryError();
throw new Error(resultStr);
}
if (!resultStr.startsWith('{')) throw plpgsqlError(resultStr);

return JSON.parse(resultStr);
} finally {
Expand Down
8 changes: 8 additions & 0 deletions versions/18/test/plpgsql.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
const query = require("../");
const { describe, it, before, after, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const { blocks } = require('./wasm-depth-cases');

describe("PL/pgSQL Parsing", () => {
before(async () => {
await query.parse("SELECT 1");
});

it("preserves PostgreSQL's grammar limit as a SqlError", async () => {
const sql = blocks.loops(10000);
const expected = { name: "SqlError", message: 'memory exhausted at or near "LOOP"' };
assert.throws(() => query.parsePlPgSQLSync(sql), expected);
await assert.rejects(query.parsePlPgSQL(sql), expected);
});

describe("Sync PL/pgSQL Parsing", () => {
it("should parse a simple PL/pgSQL function", () => {
const funcSql = `
Expand Down
13 changes: 13 additions & 0 deletions versions/18/test/wasm-depth-cases.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const chained = (depth) => 'SELECT 1' + '+1'.repeat(depth);
const subqueries = (depth) => 'SELECT ' + '(SELECT '.repeat(depth) + '1' + ')'.repeat(depth);
const calls = (depth) => 'SELECT ' + 'f('.repeat(depth) + '1' + ')'.repeat(depth);

const blocks = Object.fromEntries(Object.entries({
'IF blocks': ['IF true THEN ', 'NULL;', ' END IF;'],
'BEGIN blocks': ['BEGIN ', 'NULL;', ' END;'],
loops: ['LOOP ', 'EXIT;', ' END LOOP;'],
}).map(([name, [open, body, close]]) => [name, (depth) =>
'CREATE FUNCTION f() RETURNS void LANGUAGE plpgsql AS $$ BEGIN ' +
open.repeat(depth) + body + close.repeat(depth) + ' END $$']));

module.exports = { chained, subqueries, calls, blocks };
Loading
Loading