Skip to content

Add JSON output for RedisVL CLI read commands - #593

Merged
vishal-bala merged 24 commits into
mainfrom
feat/RAAE-1557/cli-json
Apr 30, 2026
Merged

Add JSON output for RedisVL CLI read commands#593
vishal-bala merged 24 commits into
mainfrom
feat/RAAE-1557/cli-json

Conversation

@limjoobin

@limjoobin limjoobin commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Changes

This PR adds JSON output for RedisVL CLI read commands to make it more machine-readable.

Features added:

  • added the --json flag to rvl version, rvl index listall, rvl index info, and rvl stats.
  • Add shared JSON CLI helpers (add_json_output_flag, cli_print_json) in redisvl/cli/utils.py for consistent one-object stdout behavior.
  • Add/update unit tests for all new JSON paths and error contracts.

Note

Low Risk
Adds optional output formatting for CLI read commands without changing index/data operations. Main risk is minor: downstream scripts may depend on exact stdout text when --json is used, but default behavior is preserved.

Overview
Adds a shared CLI JSON output mode via --json, including new helpers add_json_output_flag and cli_print_json (with safe bytes encoding) to ensure one JSON object on stdout on success.

Extends rvl index info, rvl index listall, and rvl stats to support JSON output: index info now normalizes FT.INFO-style structures into a stable {index_information, index_fields} payload, listall emits {indices: [...]}, and stats emits a full STATS_KEYS-shaped object with missing keys as null, while keeping existing human-readable output when --json is not used.

Adds unit tests covering JSON vs table behavior, key ordering/normalization, bytes decoding, and ensuring no partial JSON is printed on error paths.

Reviewed by Cursor Bugbot for commit e1d2bcf. Bugbot is set up for automated code reviews on this repo. Configure here.

- add_json_output_flag for --json on argparse parsers
- cli_print_json for single-object stdout; bytes-safe default

Made-with: Cursor
Print {"version": <package>} to stdout; --json overrides --short

Made-with: Cursor
- tests for add_json_output_flag, cli_print_json, Version

Made-with: Cursor
@limjoobin limjoobin self-assigned this Apr 27, 2026
@jit-ci

jit-ci Bot commented Apr 27, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@jit-ci

jit-ci Bot commented Apr 27, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@limjoobin
limjoobin marked this pull request as ready for review April 27, 2026 07:11
@limjoobin limjoobin changed the title (RAAE-1557) Add JSON output for RedisVL CLI read commands Add JSON output for RedisVL CLI read commands Apr 27, 2026
Comment thread redisvl/cli/index.py
Comment thread redisvl/cli/stats.py Outdated

@vishal-bala vishal-bala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good! Just a couple of minor things

Comment thread redisvl/cli/index.py Outdated
Comment thread redisvl/cli/utils.py Outdated
Comment thread redisvl/cli/version.py Outdated
limjoobin and others added 4 commits April 29, 2026 21:08
Co-authored-by: Vishal Bala <vishal-bala@users.noreply.github.com>
Co-authored-by: Vishal Bala <vishal-bala@users.noreply.github.com>

@vishal-bala vishal-bala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM!

Comment thread tests/unit/test_cli_utils.py
@vishal-bala vishal-bala added the auto:patch Increment the patch version when merged label Apr 29, 2026
Comment thread redisvl/cli/index.py Outdated
Comment thread tests/unit/test_cli_index.py Outdated
Comment thread tests/unit/test_cli_stats.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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 9e8790b. Configure here.

Comment thread redisvl/cli/utils.py Outdated
with pytest.raises(SystemExit) as excinfo: # exit(0) in Index.__init__ is not a plain return
Index()
assert excinfo.value.code == 0 # "log and exit(0)" CLI contract
# assert excinfo.value.code == 0 # "log and exit(0)" CLI contract

@vishal-bala vishal-bala Apr 30, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why do we have these assertions commented out?

Suggested change
# assert excinfo.value.code == 0 # "log and exit(0)" CLI contract

)
with pytest.raises(SystemExit) as excinfo:
Index()
# assert excinfo.value.code == 0 # try/except in Index.__init__ + exit(0)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
# assert excinfo.value.code == 0 # try/except in Index.__init__ + exit(0)

@vishal-bala
vishal-bala merged commit 270b48f into main Apr 30, 2026
57 checks passed
@vishal-bala
vishal-bala deleted the feat/RAAE-1557/cli-json branch April 30, 2026 15:55
@applied-ai-release-bot

Copy link
Copy Markdown

🚀 PR was released in v0.18.1 🚀

@applied-ai-release-bot applied-ai-release-bot Bot added the released This issue/pull request has been released. label Apr 30, 2026
vishal-bala added a commit that referenced this pull request Jun 23, 2026
)

### Changes
In this PR, we reinforce our test coverage of redisVL CLI foundation
contracts.
For CLI foundation contracts, the following were verified for
correctness:

- sydout/stderr output
- system exit codes
- usage errors
- runtime failures
- human-readable success paths
- JSON success paths

Note: This PR merges commits from:
- fix/cli-exit-codes-and-streams (#592)
- feat/RAAE-1557/cli-json (#593)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Changes are limited to unit tests; they document and guard existing
CLI behavior without modifying runtime code in this diff.
> 
> **Overview**
> This PR **expands CLI regression tests only** (no production
`redisvl/cli` changes in the diff). It replaces shallow fake-Redis tests
with **contract-focused coverage** for `rvl`, `rvl index`, and `rvl
stats`.
> 
> **Top-level CLI** (`test_cli_main.py`): new tests assert help lists
`index`, `mcp`, `version`, and `stats` (in-process and via `python -m
redisvl.cli.runner`), and that unknown commands exit **2** with errors
on stderr and empty stdout.
> 
> **Index CLI** (`test_cli_index.py`): adds help/subprocess help checks,
a real Redis index fixture for `listall`/`info`, success assertions for
`create` (exact success banner; `--json` does not add JSON), JSON shape
checks for `listall` and `info`, human-output smoke tests, and
parametrized **usage errors (exit 2)** vs **runtime/Redis failures (exit
1, no stdout JSON)**.
> 
> **Stats CLI** (`test_cli_stats.py`): mirrors the same patterns—help,
runner subprocess, real-index JSON/table success, `_stats_rows`
ordering, usage **exit 2**, and runtime **`RedisSearchError`/generic
errors exit 1** with empty stdout on `--json` failure paths.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c7d67fa. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: ht <121932573+hillarytoh@users.noreply.github.com>
Co-authored-by: Vishal Bala <vishal-bala@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto:patch Increment the patch version when merged released This issue/pull request has been released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants