Repository navigation
MOD-16366 json add flow tests to check llapi c api - #1614
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1614 +/- ##
==========================================
+ Coverage 76.29% 85.99% +9.69%
==========================================
Files 15 15
Lines 5177 5177
==========================================
+ Hits 3950 4452 +502
+ Misses 1227 725 -502 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
gabsow
left a comment
There was a problem hiding this comment.
Automated code review (recall-biased, high effort). Test-only PR — no production JSON behavior changes. Findings below are latent/robustness/quality issues in the new test harness and consumer module; none break the current RedisJSON test run, but several affect reliability and the module's stated cross-module reuse goal. Refuted candidates (e.g. num_array typed-packing assertion, allocJson NULL check, Linux -shared symbol resolution) are not reported.
| *) LLAPI_TEST_LDFLAGS="-shared" ;; | ||
| esac | ||
| if "${LLAPI_TEST_CC:-cc}" -fPIC $LLAPI_TEST_LDFLAGS -O2 -Wall \ | ||
| -I"$ROOT/deps/RedisModulesSDK" -I"$ROOT/redis_json/src/include" \ |
There was a problem hiding this comment.
Submodule not initialized here, and redismodule.h is not vendored in the repo. This -I"$ROOT/deps/RedisModulesSDK" is the only source of redismodule.h (the repo only ships redis_json/src/include/rejson_api.h), and deps/RedisModulesSDK is a brand-new submodule. tests.sh never runs git submodule update --init. CI is fine because the workflows check out with submodules: recursive, but on any non-recursive checkout (fresh clone, local dev, an alternate CI lane) the include dir is empty, the build fails, and you fall through to the soft warning below — surfacing as an opaque RuntimeError in every test rather than "submodule missing". Consider git submodule update --init deps/RedisModulesSDK here (or a clear precondition check).
| -o "$LLAPI_TEST_DIR/llapi_test.so" "$LLAPI_TEST_DIR/module.c"; then | ||
| export LLAPI_TEST_MODULE="$LLAPI_TEST_DIR/llapi_test.so" | ||
| else | ||
| echo "warning: failed to build LLAPI test module; test_llapi.py will fail" |
There was a problem hiding this comment.
Build failure is swallowed. On a compile error you echo a warning and continue without exporting LLAPI_TEST_MODULE. Two failure modes: (1) if test_llapi.py is collected, every test fails with a confusing RuntimeError far from the real cause (the compile error scrolled past); (2) if a given run filters test_llapi.py out, a broken module.c goes completely undetected — there is no build-success invariant. Recommend failing the build step loudly on compile error so the cause is reported where it happens.
| } | ||
| RedisModule_Log(ctx, "notice", "llapi_test: bound RedisJSON shared API V%d", japi_ver); | ||
|
|
||
| REGISTER("LLAPI.VERSION", VersionCmd); |
There was a problem hiding this comment.
V4/V6/V7 commands are registered (and called) unconditionally, regardless of the bound API version. fetch_japi() binds the highest available RedisJSON_V<n> down to V1, and testLLAPIVersion explicitly accepts ver >= 1, matching the file header's stated goal of running against any module exporting this shared API (e.g. JsonHDT, MOD-14113). But GETKEYVALUES (V4), GETAT/allocJson/freeJson (V6) and GETARRAY (V7) are always registered and dereference those struct fields. Against RedisJSON this is safe (it exports the same full struct under every version name — see c_api.rs:858-864), but against a genuinely lower-version provider those fields lie past the provider's struct → garbage/NULL function pointer → crash. If cross-module reuse is a real goal, gate the REGISTER(...) calls (or the command bodies) on japi_ver.
| def _new_env(): | ||
| """A fresh Env loading the JSON module under test plus the LLAPI consumer.""" | ||
| if not LLAPI_MODULE or not os.path.exists(LLAPI_MODULE): | ||
| raise RuntimeError( |
There was a problem hiding this comment.
Running pytest outside tests.sh errors the whole file instead of skipping. _new_env raises RuntimeError when LLAPI_TEST_MODULE is unset/missing, so a direct pytest/IDE run (the common debug loop) fails all ~17 tests rather than skipping them. If skip-on-missing is intended, use unittest.SkipTest / pytest.skip; if fail-loud is intended (so a missing module can't hide), that's defensible but worth a comment stating it.
| size_t len = 0; | ||
| JSONArrayType atype = JSONArrayType_Heterogeneous; | ||
| const void *arr = japi->getArray(node, &len, &atype); | ||
| if (!arr && len == 0 && japi->getType(node) != JSONType_Array) { |
There was a problem hiding this comment.
Fragile not-an-array detection. if (!arr && len == 0 && japi->getType(node) != JSONType_Array) reconstructs "not an array" from three coupled signals because getArray returns (NULL, 0) for non-arrays and potentially for empty arrays. It works today only because an empty array reports getType == Array. The TYPE/KEYVALUES/SCALAR handlers already gate cleanly on getType(node) up front — doing the same here (if (getType(node) != JSONType_Array) error; before calling getArray) is unambiguous and not coupled to undocumented NULL-vs-empty pointer semantics.
| if (!it) return REDISMODULE_OK; | ||
|
|
||
| RedisModuleString *s = NULL; | ||
| if (japi->getJSONFromIter(it, ctx, &s) == REDISMODULE_OK) { |
There was a problem hiding this comment.
LLAPI.ITER_JSON returns an error for a valid path that matches zero nodes. getJSONFromIter returns REDISMODULE_ERR when the result set is empty (c_api.rs:205, pos >= len), so LLAPI.ITER_JSON doc $.does_not_exist replies ERR getJSONFromIter failed, while LLAPI.ITER_LEN returns 0 and LLAPI.OPEN_GET returns [] for the same input. Not covered by a test today, but the inconsistent error surface is surprising — consider replying an empty result for the zero-match case to match the other iterators.
| static int OpenFromStrCmd(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | ||
| if (argc != 3) return RedisModule_WrongArity(ctx); | ||
| const char *keyname = RedisModule_StringPtrLen(argv[1], NULL); | ||
| RedisJSON json = japi->openKeyFromStr(ctx, keyname); |
There was a problem hiding this comment.
(cleanup) OpenFromStrCmd and OpenFlagsCmd re-implement the open-key + get(path) + error-reply body of open_and_get (lines 122-135), differing only in the open call (openKeyFromStr / openKeyWithFlags). Three near-identical sequences with duplicated error strings; a helper parameterized by the opened RedisJSON would collapse them and keep the error wording in one place.
| static int IsJsonCmd(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { | ||
| if (argc != 2) return RedisModule_WrongArity(ctx); | ||
| RedisModuleKey *key = RedisModule_OpenKey(ctx, argv[1], REDISMODULE_READ); | ||
| int res = japi->isJSON(key); |
There was a problem hiding this comment.
(minor) IsJsonCmd calls japi->isJSON(key) before the if (key) null check on the next line. RedisModule_OpenKey(..., REDISMODULE_READ) can return NULL, and the trailing if (key) RedisModule_CloseKey(key) shows NULL is anticipated — but isJSON already received the (possibly NULL) handle. Reorder to null-check before the isJSON call (untested today since only existing keys are exercised).
| RedisModule_FreeString(ctx, s); | ||
| } else { | ||
| RedisModule_ReplyWithError(ctx, "ERR getJSONFromIter failed"); | ||
| } |
There was a problem hiding this comment.
ITER_JSON errors on zero matches
Medium Severity
For a valid path that matches no nodes, LLAPI.ITER_JSON replies with ERR getJSONFromIter failed because IterJsonCmd always calls getJSONFromIter, which the JSON provider rejects when the iterator is empty. LLAPI.ITER_LEN and LLAPI.OPEN_GET return 0 and [] for the same case, so the new wrapper is inconsistent.
Reviewed by Cursor Bugbot for commit e77fe31. Configure here.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 17ba1c2. Configure here.
| } | ||
| n++; | ||
| } | ||
| RedisModule_ReplySetArrayLength(ctx, n); |
There was a problem hiding this comment.
Error replies inside array builders
Medium Severity
In LLAPI.OPEN_GET and LLAPI.KEYVALUES, a failed getJSON calls RedisModule_ReplyWithError while a multi-bulk array reply is already open via REDISMODULE_POSTPONED_LEN, producing an invalid nested error inside an array.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 17ba1c2. Configure here.
gabsow
left a comment
There was a problem hiding this comment.
Re-reviewed after your CR commits — thanks, most of my comments are addressed (submodule init before the LLAPI build, hard build-failure now exit 1, latest-only shared-API bind so no out-of-bounds struct read, not-an-array detection, OpenFromStr/OpenFlags dedup, IsJson null-check order). Two items are still open (both also flagged by cursor) — re-flagged inline. Holding approval until those are addressed or consciously waived.
| if (!it) return REDISMODULE_OK; | ||
|
|
||
| RedisModuleString *s = NULL; | ||
| if (japi->getJSONFromIter(it, ctx, &s) == REDISMODULE_OK) { |
There was a problem hiding this comment.
Still open after the CR commits (cursor flagged this too): for a valid path that matches zero nodes, getJSONFromIter returns non-OK, so LLAPI.ITER_JSON replies with an error — whereas LLAPI.ITER_LEN returns 0 and LLAPI.OPEN_GET returns an empty array for the same input. That inconsistency bites anyone using ITER_JSON as the "serialize the whole result set" entry point. Consider treating an empty iterator as an empty ([] / null) result rather than an error, to mirror ITER_LEN/OPEN_GET.
There was a problem hiding this comment.
Looked into this — the inconsistency mirrors the real C API contract, so I'd keep ITER_JSON as-is. In c_api.rs, getJSONFromIter returns Status::Err (and writes no string) when the iterator is empty:
▎
▎ if iter.pos >= iter.results.len() {
▎ Status::Err as c_int
▎ } else {
▎ // serialize_object(...) -> JSON array
▎ }
▎
There was a problem hiding this comment.
Confirmed against redis_json/src/c_api.rs — json_api_get_json_from_iter returns Status::Err when iter.pos >= iter.results.len(), so ITER_JSON erroring on an empty result set faithfully mirrors the real LLAPI contract. Agreed it should stay as-is; thanks for adding the explicit assertion in testLLAPIOpenGetAndIter documenting the intentional difference. 👍
gabsow
left a comment
There was a problem hiding this comment.
Re-reviewed the latest CR (322cde0) — both of my remaining items are addressed:
test_llapi.pynow raisesunittest.SkipTestinstead ofRuntimeError, so a directpytest/IDE run (withLLAPI_TEST_MODULEunset) skips cleanly instead of erroring the whole file.LLAPI.ITER_JSONon a valid zero-match path: confirmed againstredis_json/src/c_api.rsthatgetJSONFromIterreturnsStatus::Erron an empty iterator, so the test faithfully mirrors the real C API contract — keeping it as-is is correct, and the new assertion documents the intent.
Everything from my earlier review (submodule init before the LLAPI build, hard build-failure, latest-only shared-API bind, dedup, null-check order) is in. LGTM — approving. Thanks for the thorough follow-ups!
* MOD-13014: redact user data from JSONPath trace logs (#1605) MOD-13014 removed user data from errors but left the JSONPath engine's trace logs, which still emitted document values, query literals and paths at Redis `debug` log level (trace! maps to RedisLogLevel::Debug). Gate those traces behind a cached mirror of Redis core's `hide-user-data-from-log` server config: a new `trace_user_data!` macro suppresses the message when the flag is on. The module reads the config at load and refreshes it on CONFIG SET via a config-changed event handler. Structural traces (grammar rules, "missing operand" diagnostics) stay on plain trace! and are unaffected. Co-authored-by: Claude Opus 4.8 <[email protected]> * remove `#[cfg(not(feature = "as-library"))]` from `sync_hide_user_dat… (#1613) * MOD-16366 json add flow tests to check llapi c api (#1614) * MOD-16366 LLAPI flow tests * remove `#[cfg(not(feature = "as-library"))]` from `sync_hide_user_data_from_log` * remove `#[cfg(not(feature = "as-library"))]` from `sync_hide_user_data_from_log` * fail if module not available * fixes * CR * . * CR * MOD-16514 - fix bootstrap & build for al os (#1612) * alma8 +rhel8+rhel9+bionic +focal passes * fix for alpine * fix for bionic * fix * fix mariner * fix bionic bootstrap * fix bionic * fix bionic * fi bionic * fix bionic * install aws cli for json * bionic fix * fix bionic * fix for focal * fix for focak * fix for bionic & focal &mariner&alpine * apply fixes * fix remarks * fix for alpine * try another methood * ci: source $HOME/.cargo/env in flow-clippy so cargo is on PATH Match flow-linter.yml; getrust.sh now installs Rust user-scoped, so later Actions steps don't see cargo without sourcing the env. * CI was failing because getrust.sh ran twice. install_script.sh already invokes it from the repo root (works), but the workflow then called ./getrust.sh sudo again from working-directory: .install — where rust-toolchain.toml doesn't exist, so its `sed rust-toolchain.toml` errored with "No such file or directory" (exit 2). Removed the redundant ./getrust.sh line from flow-linter.yml and flow-clippy.yml; install_script.sh handles Rust install on its own. * ci(macos): add rust-toolchain.toml to sparse checkout The macOS "Deps checkout" fetches only .install and test requirements, then runs install_script.sh -> getrust.sh, which reads rust-toolchain.toml from the repo root to resolve the pinned toolchain. That file wasn't in the sparse list, so getrust failed with "sed: rust-toolchain.toml: No such file or directory". Add it to the sparse-checkout. * bump version 8.9.81 to Cargo.lock & Cargo.toml --------- Co-authored-by: Tom Gabsow <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Aviv David <[email protected]>
* MOD-13014: redact user data from JSONPath trace logs (#1605) MOD-13014 removed user data from errors but left the JSONPath engine's trace logs, which still emitted document values, query literals and paths at Redis `debug` log level (trace! maps to RedisLogLevel::Debug). Gate those traces behind a cached mirror of Redis core's `hide-user-data-from-log` server config: a new `trace_user_data!` macro suppresses the message when the flag is on. The module reads the config at load and refreshes it on CONFIG SET via a config-changed event handler. Structural traces (grammar rules, "missing operand" diagnostics) stay on plain trace! and are unaffected. Co-authored-by: Claude Opus 4.8 <[email protected]> * remove `#[cfg(not(feature = "as-library"))]` from `sync_hide_user_dat… (#1613) * MOD-16366 json add flow tests to check llapi c api (#1614) * MOD-16366 LLAPI flow tests * remove `#[cfg(not(feature = "as-library"))]` from `sync_hide_user_data_from_log` * remove `#[cfg(not(feature = "as-library"))]` from `sync_hide_user_data_from_log` * fail if module not available * fixes * CR * . * CR * MOD-16514 - fix bootstrap & build for al os (#1612) * alma8 +rhel8+rhel9+bionic +focal passes * fix for alpine * fix for bionic * fix * fix mariner * fix bionic bootstrap * fix bionic * fix bionic * fi bionic * fix bionic * install aws cli for json * bionic fix * fix bionic * fix for focal * fix for focak * fix for bionic & focal &mariner&alpine * apply fixes * fix remarks * fix for alpine * try another methood * ci: source $HOME/.cargo/env in flow-clippy so cargo is on PATH Match flow-linter.yml; getrust.sh now installs Rust user-scoped, so later Actions steps don't see cargo without sourcing the env. * CI was failing because getrust.sh ran twice. install_script.sh already invokes it from the repo root (works), but the workflow then called ./getrust.sh sudo again from working-directory: .install — where rust-toolchain.toml doesn't exist, so its `sed rust-toolchain.toml` errored with "No such file or directory" (exit 2). Removed the redundant ./getrust.sh line from flow-linter.yml and flow-clippy.yml; install_script.sh handles Rust install on its own. * ci(macos): add rust-toolchain.toml to sparse checkout The macOS "Deps checkout" fetches only .install and test requirements, then runs install_script.sh -> getrust.sh, which reads rust-toolchain.toml from the repo root to resolve the pinned toolchain. That file wasn't in the sparse list, so getrust failed with "sed: rust-toolchain.toml: No such file or directory". Add it to the sparse-checkout. * MOD-16300 perf(json_path): materialize filter literals once per query (#1615) * MOD-16300 perf(json_path): materialize filter literals once per query * simplify * CR + Reuse cache in whole query * MOD-16608 Bump ijson(reduce object memory) (#1617) * MOD-16608 Bump ijson(reduce object memory) * clippy * fix memory test * MOD-16274 | MOD-16275 add size/sizeof and empty operators on object (#1618) * MOD-16685 Add RedisJSON API to open from RedisModuleKey (#1619) * MOD-16685 Add RedisJSON API to open from RedisModuleKey Add a RedisJSON shared API V8 entry that opens a JSON root from an already-open RedisModuleKey handle. This lets consumers such as RediSearch reuse an existing key handle instead of manually checking isJSON and calling RedisModule_ModuleTypeGetValue. Update the RediSearch RedisJSON API header copy and add LLAPI coverage for the new openKeyFromHandle path. * use Imanager to get value for json * fix clippy * rename functions * fix compilation * MOD-16872 make `apply_updates` return the current status of updates (#1621) * add docker image managment to json (#1622) * Add `AGENTS.md` and `CLAUDE.md` * ignore AGENS.MD in spellcheck * ignore CLAUDE.MD in spellcheck * [MOD-17021] Add getWithPath LLAPI to evaluate a pre-compiled JSONPath (#1623) * MOD-16899: add getWithPath LLAPI to evaluate a pre-compiled JSONPath Adds a V9 RedisJSON C API entry getWithPath(json, JSONPath) that evaluates an already-compiled path (from pathParse) instead of a path string, skipping the per-call pest compilation. Callers that resolve the same path across many documents (e.g. RediSearch FT.AGGREGATE LOAD) can compile once and reuse the handle. - c_api.rs: json_api_get_with_path + exported JSONAPI_getWithPath, struct/initializer entry, REDIS_JSONAPI_LATEST_API_VER 8->9; parity unit test (getWithPath == get). - include/rejson_api.h: getWithPath declaration + LATEST_API_VER bump. lib.rs: register the entrypoint. Co-Authored-By: Claude Opus 4.8 <[email protected]> * MOD-16899: add LLAPI flow test for getWithPath Extend the llapi_test_module consumer with LLAPI.OPEN_GET_WITH_PATH (pathParse + getWithPath, via an open_and_get_with_path helper mirroring open_and_get, sharing reply_nodes_as_json with OPEN_GET) and assert in test_llapi.py that it matches LLAPI.OPEN_GET, plus missing-key / bad-path / projection error cases. Co-Authored-By: Claude Opus 4.8 <[email protected]> * getWithPath: reject projections at runtime like json_api_get Replace the debug_assert with 'if query.is_projection() { return null(); }' so a projection path is handled identically to the string-based json_api_get in all builds (not just debug), and defensively at the FFI boundary. Add a unit test passing a compiled projection Query directly. Co-Authored-By: Claude Opus 4.8 <[email protected]> * getWithPath: trim projection comments Drop the self-explanatory test doc comment and shorten the guard comment to a one-liner referencing json_api_get. Co-Authored-By: Claude Opus 4.8 <[email protected]> * getWithPath: drop json_api_get reference from projection guard comment Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]> * MOD-16952 - enhance bootstrap (add list and dry-run arg) (#1624) * enhance bootstrap - add check-deps * write list to afile * add optional deps * add another optional deps * add another optional deps * add versioning managment * rename command to list * renme to list * add dry run * fix colors * fix missing uv * remove min cmake version * fix remarks * add the retry mechanizm to json as well * fix remarks * fix remarks * add _sh so we can have the full bootstrap output * always return to the workspace dir * make single copy paste install all * fix alma8 * fix bad dry-run print * gaurd tool-set version 11 * fix curl minimal * remove centos-release-scl for amazonlinux2 * fix macos env * fix(bootstrap): make sudo a no-op on root containers without a sudo binary The install scripts run privileged steps via literal `sudo` inside `_sh` command strings (e.g. `sudo ln -sf ...`, `| sudo tee`, `&& sudo make install`). On a slim Docker image that runs install_script.sh directly as root with no `sudo` package installed (e.g. RedisTimeSeries' amazonlinux2 CI), those steps fail with `sudo: command not found` (exit 127), aborting the whole bootstrap. Add a root-only pass-through in pm.sh/deps_lib.sh: when running as root and no real `sudo` binary exists, define `sudo()` to run its arguments directly. When not root, a missing sudo stays a genuine error and is left unmasked. * version update * Revert "[MOD-17021] Add getWithPath LLAPI to evaluate a pre-compiled JSONPath (#1623)" This reverts commit 628013e. --------- Co-authored-by: Tom Gabsow <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Aviv David <[email protected]> Co-authored-by: avivdavid23 <[email protected]> Co-authored-by: Itzikvaknin <[email protected]>


Adds a pytest flow tests which are testing the LLAPI the json module registers at
redis_json/src/c_api.rs.Note
Low Risk
Test-only infrastructure and fixtures; no changes to the JSON module’s production LLAPI registration or runtime behavior.
Overview
Adds end-to-end flow coverage for the RedisJSON LLAPI (
RedisModule_GetSharedAPI/RedisJSON_V<n>), which client commands cannot reach directly.A small C consumer module (
llapi_test_module) binds the latest shared API and exposes thinLLAPI.*commands that mirrorRedisJSONAPI(open/get, iterators, scalars, arrays, key-values, path parse,isJSON, etc.).test_llapi.pyloads RedisJSON plus that module, seeds a fixture document, and asserts happy paths and error behavior (missing keys, type mismatches, bad paths).tests.shnow auto-buildsllapi_test.so(initializingdeps/RedisModulesSDKwhen needed), setsLLAPI_TEST_MODULE, and fails the run if the build breaks; direct pytest runs skip when the.sois absent..gitignoreignores built artifacts;llapi_doc.jsonis the shared test payload.Reviewed by Cursor Bugbot for commit 322cde0. Bugbot is set up for automated code reviews on this repo. Configure here.