Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

use console.print_json#571

Merged
mangelajo merged 2 commits intojumpstarter-dev:mainfrom
bennyz:add-raw-json
Jul 22, 2025
Merged

use console.print_json#571
mangelajo merged 2 commits intojumpstarter-dev:mainfrom
bennyz:add-raw-json

Conversation

@bennyz
Copy link
Copy Markdown
Member

@bennyz bennyz commented Jul 20, 2025

Summary by CodeRabbit

  • Improvements
    • Enhanced the display of JSON output for models, providing clearer and more readable formatting in the console.
  • Tests
    • Improved JSON output validation in tests with a new utility for more reliable comparisons.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 20, 2025

Walkthrough

The changes add minor formatting improvements to an exception handling decorator, enhance JSON output printing by using a dedicated JSON print method, introduce a new JSON comparison utility function, and update multiple test assertions to use this utility for robust JSON equality checks. No logic or control flow is changed.

Changes

File(s) Change Summary
packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py Added blank lines for improved readability within the exception handling decorator.
packages/jumpstarter-cli-common/jumpstarter_cli_common/print.py Changed JSON output from console.print() to console.print_json() with indentation handled in the print call.
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/test_utils.py Added new utility function json_equal to compare JSON strings robustly, including handling nested JSON.
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py Updated JSON output assertions to use json_equal instead of direct string equality checks.
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py Updated JSON output assertions to use json_equal instead of direct string equality checks.

Estimated code review effort

2 (~15 minutes)

Possibly related PRs

Poem

🐇 Hopping through code with formatting neat,
A decorator pause, a JSON treat.
Comparing JSON with care so fine,
Tests now sparkle, outputs align.
Console prints with colors bright,
A rabbit’s joy in code tonight! ✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@netlify
Copy link
Copy Markdown

netlify Bot commented Jul 20, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 99f9852
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/687f8a52deadc30008513e89
😎 Deploy Preview https://deploy-preview-571--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@bennyz bennyz force-pushed the add-raw-json branch 2 times, most recently from dcb9efe to e04f6bb Compare July 20, 2025 17:12
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py (1)

28-30: Good addition of JSON comparison utility.

This helper function improves test robustness by comparing parsed JSON objects rather than raw strings, making tests less sensitive to formatting differences.

Consider moving this utility function to a shared test module since it's duplicated in both get_test.py and create_test.py:

# In a new file like test_utils.py
import json

def json_equal(a: str, b: str) -> bool:
    return json.loads(a) == json.loads(b)

Then import it in both test files to avoid duplication.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dcb9efe and e04f6bb.

📒 Files selected for processing (5)
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py (4 hunks)
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py (11 hunks)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py (2 hunks)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/print.py (1 hunks)
  • packages/jumpstarter-cli/jumpstarter_cli/login.py (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/print.py
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py
  • packages/jumpstarter-cli/jumpstarter_cli/login.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py (1)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py (1)
  • json_equal (375-376)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: e2e
🔇 Additional comments (9)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py (9)

1-1: LGTM! Import addition is correct.

The json import is necessary for the new json_equal helper function and is properly placed.


103-103: LGTM! Improved JSON assertion.

Using json_equal makes the test more robust against formatting differences while ensuring semantic correctness.


255-255: LGTM! Consistent JSON assertion improvement.

The change to json_equal follows the same improvement pattern for testing JSON list output.


283-283: LGTM! Consistent improvement for empty list testing.

The json_equal usage is properly applied to empty list scenarios as well.


360-360: LGTM! Consistent JSON testing improvement for exporters.

The pattern is consistently applied across all resource types.


475-475: LGTM! Consistent application to exporter devices testing.

The improvement pattern is properly extended to exporter devices functionality.


620-620: LGTM! Consistent improvement for exporters list.

The pattern continues to be applied consistently across all list operations.


788-788: LGTM! Consistent improvement for exporters devices list.

The pattern is properly applied to complex list scenarios with nested device data.


979-979: LGTM! Complete coverage of lease testing improvements.

The json_equal pattern has been consistently applied to both individual lease and lease list testing, completing the comprehensive improvement across all resource types.

Also applies to: 1181-1181

@bennyz bennyz changed the title print raw json use console.print_json Jul 21, 2025
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/test_utils.py (2)

8-9: Consider using json.JSONDecodeError for more specific exception handling.

Using the more specific json.JSONDecodeError instead of the broad ValueError would be more precise, as json.loads() raises JSONDecodeError (a subclass of ValueError) for invalid JSON.

-        except ValueError:
+        except json.JSONDecodeError:

13-14: Consider using json.JSONDecodeError for consistency.

For consistency with the outer exception handling, consider using json.JSONDecodeError here as well.

-            except ValueError:
+            except json.JSONDecodeError:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84e39f9 and c17688b.

📒 Files selected for processing (5)
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py (3 hunks)
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py (10 hunks)
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/test_utils.py (1 hunks)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py (2 hunks)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/print.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/exceptions.py
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/print.py
🧰 Additional context used
🧠 Learnings (1)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py (1)

Learnt from: NickCao
PR: jumpstarter-dev/jumpstarter#463
File: packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py:270-270
Timestamp: 2025-05-28T15:09:35.768Z
Learning: The jumpstarter CLI is designed to match kubectl's behavior, including returning exit code 0 (success) when no resources are found, rather than exit code 1 (failure).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: e2e
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
🔇 Additional comments (4)
packages/jumpstarter-cli-admin/jumpstarter_cli_admin/test_utils.py (1)

4-17: Well-designed JSON comparison utility with robust error handling.

The json_equal function elegantly handles edge cases like double-encoded JSON and malformed input by using a sentinel object for failed parsing attempts. This provides more reliable JSON comparison than direct string equality.

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py (3)

16-16: Good addition of the json_equal import.

The import is correctly placed and enables more robust JSON comparison in the test assertions.


188-188: Improved JSON comparison robustness.

Replacing direct string equality with json_equal makes the test more resilient to formatting differences while maintaining the same semantic validation.


353-353: Consistent application of robust JSON comparison.

Good consistency in applying the json_equal utility for exporter JSON validation as well.

@bennyz bennyz requested review from NickCao and mangelajo July 22, 2025 12:50
@mangelajo mangelajo enabled auto-merge July 22, 2025 12:55
@mangelajo mangelajo merged commit 2b2f264 into jumpstarter-dev:main Jul 22, 2025
18 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants