Skip to content

🧪 [Add tests for load_persisted_stats]#167

Merged
sheepdestroyer merged 8 commits into
masterfrom
chore/test-load-persisted-stats-8225724147617958369
Jul 1, 2026
Merged

🧪 [Add tests for load_persisted_stats]#167
sheepdestroyer merged 8 commits into
masterfrom
chore/test-load-persisted-stats-8225724147617958369

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jun 30, 2026

Copy link
Copy Markdown
Owner

🎯 What: The testing gap for load_persisted_stats was addressed by adding a new test file to test the function's logic thoroughly.
📊 Coverage: Covered happy path (JSON load and dictionary merging), missing file path, and corrupted file handling (Exceptions during load).
Result: Improved test coverage and reliability of startup stats loading logic.


PR created automatically by Jules for task 8225724147617958369 started by @sheepdestroyer

Summary by Sourcery

Tests:

  • Add unit tests covering load_persisted_stats when the stats file is missing, successfully loaded, and when loading raises an exception.

Summary by CodeRabbit

  • Tests
    • Added coverage for loading saved statistics, including cases where the saved file is missing, successfully read, or fails during loading.
    • Verified that existing statistics remain intact when no saved file is found or an error occurs.
    • Confirmed that saved values are merged correctly when available, with new data added and existing values updated as expected.

Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@sourcery-ai

sourcery-ai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Adds a new test module that thoroughly exercises load_persisted_stats behavior across success, missing file, and exception scenarios, validating stats merging semantics and logging interactions.

File-Level Changes

Change Details Files
Add focused unit tests that validate load_persisted_stats behavior for missing files, successful JSON load and merge, and exceptions during file read.
  • Introduce a pytest fixture that seeds router.main.stats with a clean baseline and uses patch.dict to isolate test state.
  • Add a test that mocks os.path.exists to simulate a missing stats file and verifies stats remain unchanged and path check is performed.
  • Add a test that mocks os.path.exists, builtins.open, and router.main.logger.info to simulate successful JSON load, dictionary merging (including nested dict behavior), and success logging.
  • Add a test that mocks os.path.exists, builtins.open raising an Exception, and router.main.logger.error to ensure stats remain unchanged and error logging occurs.
router/tests/test_load_persisted_stats.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@sheepdestroyer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20ab4f5c-5902-4743-a71c-f9332e48f708

📥 Commits

Reviewing files that changed from the base of the PR and between 4cdde50 and 253d23f.

📒 Files selected for processing (1)
  • router/tests/test_load_persisted_stats.py
📝 Walkthrough

Walkthrough

A new test module was added covering router.main.load_persisted_stats. It tests behavior when the stats file is missing, when it loads and merges JSON successfully, and when reading raises an exception, verifying state changes and logging in each case.

Changes

load_persisted_stats Test Coverage

Layer / File(s) Summary
Test fixture and missing-file case
router/tests/test_load_persisted_stats.py
Adds a mock_stats fixture resetting router.main.stats, and a test confirming stats is unchanged when os.path.exists returns False.
Success and exception path tests
router/tests/test_load_persisted_stats.py
Adds tests verifying correct merging of total_requests/nested_dict/new keys on successful load with success logging, and unchanged stats plus error logging when reading raises an exception.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Poem

A rabbit hops through JSON fields so neat,
Checking stats with paws and tiny feet 🐾
If the file's not there, nothing breaks,
If it errors out, a log message wakes,
Merged dicts and counts, all verified complete!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: adding tests for load_persisted_stats.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/test-load-persisted-stats-8225724147617958369

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

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The mock_stats fixture patches the global router.main.stats dict directly, which could lead to subtle cross-test coupling if other tests rely on it; consider using a more localized setup or resetting state explicitly after each test.
  • The tests patch os.path.exists via the global name rather than targeting the module under test (e.g., router.main.os.path.exists), which can make them more brittle if imports change; patch the symbol as used in router.main instead.
  • The assertion on the exact logger.info message string in test_load_persisted_stats_success is quite strict and may cause unnecessary failures on minor wording changes; consider asserting on key parts of the message or the fact that logging occurred instead of the full literal.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `mock_stats` fixture patches the global `router.main.stats` dict directly, which could lead to subtle cross-test coupling if other tests rely on it; consider using a more localized setup or resetting state explicitly after each test.
- The tests patch `os.path.exists` via the global name rather than targeting the module under test (e.g., `router.main.os.path.exists`), which can make them more brittle if imports change; patch the symbol as used in `router.main` instead.
- The assertion on the exact `logger.info` message string in `test_load_persisted_stats_success` is quite strict and may cause unnecessary failures on minor wording changes; consider asserting on key parts of the message or the fact that logging occurred instead of the full literal.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@jules
This branch has conflicts that must be resolved. Merge master changes & Resolve conflicts before continuing.
pr_description.txt (this one must never be commited)

There are unaddressed Reviews & Comments on this PR#
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.
Make sure you did not miss any reviews or comments.

@sheepdestroyer

Copy link
Copy Markdown
Owner Author

waiting to trigger gemini review

Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@jules
This branch has conflicts that must be resolved. Merge master changes & Resolve conflicts before continuing.

Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@jules

  • This branch has conflicts that must be resolved. Merge master changes & Resolve conflicts before continuing.

google-labs-jules Bot and others added 2 commits July 1, 2026 09:27
Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@users.noreply.github.com>
@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@gemini review
@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@sheepdestroyer, I'll review the changes now.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new test suite in router/tests/test_load_persisted_stats.py to verify the behavior of load_persisted_stats under different conditions, including file absence, successful loading, and error handling. The review feedback suggests scoping mock patches (like os.path.exists and open) to the target module's namespace (router.main) instead of patching them globally, which helps avoid unintended side effects on pytest internals or other modules.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread router/tests/test_load_persisted_stats.py Outdated
Comment thread router/tests/test_load_persisted_stats.py Outdated
Comment thread router/tests/test_load_persisted_stats.py Outdated
sheepdestroyer and others added 3 commits July 1, 2026 11:57
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant