Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ jobs:
run: make $FLAGS
env:
FLAGS: ${{ format('{0} {1} {2}', steps.make_flags.outputs.proto_flags, steps.make_flags.outputs.compiler_flags, steps.make_flags.outputs.debug_flags) }}
build_wasm:
runs-on: ubuntu-24.04
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install Emscripten
run: |
git clone --branch 6.0.3 --depth 1 https://github.com/emscripten-core/emsdk.git "$RUNNER_TEMP/emsdk"
"$RUNNER_TEMP/emsdk/emsdk" install 6.0.3
"$RUNNER_TEMP/emsdk/emsdk" activate 6.0.3
- name: Build and run WASM depth tests
run: |
source "$RUNNER_TEMP/emsdk/emsdk_env.sh"
emmake make -j"$(nproc)" build
emcc -O3 -sENVIRONMENT=node -sSTACK_SIZE=33554432 -sINITIAL_MEMORY=41943040 \
-sALLOW_MEMORY_GROWTH=1 -I. test/wasm_depth.c libpg_query.a -o test/wasm_depth.js
node test/wasm_depth.js
Comment on lines +97 to +99

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 bug · high

Add -sEXIT_RUNTIME=1 so WASM test exit status propagates

The emcc link command for the WASM depth test omits -sEXIT_RUNTIME=1 (.github/workflows/ci.yml:97). With Emscripten's default EXIT_RUNTIME=0, the runtime does not call exit() after main() returns, so the EXIT_FAILURE returned by test/wasm_depth.c is discarded and the Node process exits with code 0. The new CI job therefore always reports success, even when every depth case fails — the check can never catch a regression.

📋 Prompt for AI Agents

In .github/workflows/ci.yml in the build_wasm job's emcc command (lines 97-99), add -sEXIT_RUNTIME=1 to the flag list. Without it, Emscripten's default EXIT_RUNTIME=0 discards the return value of main() and the Node process exits 0 even when test/wasm_depth.c returns EXIT_FAILURE, so the CI check can never fail.

build_macos:
runs-on: macos-latest
steps:
Expand Down
64 changes: 64 additions & 0 deletions test/wasm_depth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <pg_query.h>

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static bool check_depth(const char *name, const char *open, int depth,
bool nested, bool expect_error)
{
const char prefix[] = "SELECT ";
size_t open_len = strlen(open);
char *query = malloc(sizeof(prefix) + depth * (open_len + nested) + 1);
if (query == NULL)
{
fprintf(stderr, "FAIL %s: could not allocate query\n", name);
return false;
}

char *p = query;
memcpy(p, prefix, sizeof(prefix) - 1);
p += sizeof(prefix) - 1;
for (int i = 0; i < depth; i++)
{
memcpy(p, open, open_len);
p += open_len;
}
*p++ = '1';
if (nested)
{
memset(p, ')', depth);
p += depth;
}
*p = '\0';

PgQueryParseResult result = pg_query_parse(query);
const char *error = result.error ? result.error->message : NULL;
bool ok = expect_error ? error && strcmp(error, "stack depth limit exceeded") == 0
: result.error == NULL && result.parse_tree != NULL;
if (ok)
printf("PASS %s: %s\n", name, expect_error ? error : "parsed successfully");
else
fprintf(stderr, "FAIL %s: expected %s, got %s\n", name,
expect_error ? "stack depth limit exceeded" : "a parse tree",
error ? error : result.parse_tree ? "a parse tree" : "no parse tree");

pg_query_free_parse_result(result);
free(query);
return ok;
}

int main(void)
{
int status = EXIT_SUCCESS;
if (!check_depth("2000 chained terms", "1+", 1999, false, false))
status = EXIT_FAILURE;
if (!check_depth("1000 nested subqueries", "(SELECT ", 1000, true, false))
status = EXIT_FAILURE;
if (!check_depth("2000 nested function calls", "f(", 2000, true, false))
status = EXIT_FAILURE;
if (!check_depth("100000 chained terms", "1+", 99999, false, true))
status = EXIT_FAILURE;
return status;
}
Loading