Skip to content

🧪 Add missing tests for get_goose_sessions#165

Merged
sheepdestroyer merged 8 commits into
masterfrom
chore/test-get-goose-sessions-16558526271462662412
Jul 1, 2026
Merged

🧪 Add missing tests for get_goose_sessions#165
sheepdestroyer merged 8 commits into
masterfrom
chore/test-get-goose-sessions-16558526271462662412

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jun 30, 2026

Copy link
Copy Markdown
Owner

🎯 What: The get_goose_sessions function in router/main.py lacked unit test coverage, leaving its logic around querying a local SQLite DB untested. This change adds a dedicated test file to verify its behavior.
📊 Coverage: The added tests cover the main scenarios: when the SQLite DB file is missing, the happy path (verifying database connection, cursor execution, fetching, and closing), and when an exception occurs during the database connection phase. Appropriate mocking using patch.dict ensures sqlite3 is safely intercepted for localized testing.
Result: Test coverage and reliability of router/main.py are improved without impacting global state or adding side-effects. The test suite reliably verifies this utility function's interaction with the underlying database query.


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

Summary by Sourcery

Tests:

  • Introduce a dedicated test module for get_goose_sessions covering missing DB file, successful query execution, and database connection exceptions.

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

This PR adds unit tests for the get_goose_sessions function in router/main.py, verifying its behavior against different filesystem and sqlite3 interaction scenarios via mocking.

File-Level Changes

Change Details Files
Add unit tests covering get_goose_sessions behavior for missing DB file, successful DB query, and connection exceptions.
  • Set CONFIG_PATH and modify sys.path in the test module to import main.get_goose_sessions.
  • Add test for behavior when the SQLite DB file does not exist, expecting an empty list.
  • Add test for successful DB interaction using MagicMock for sqlite3, connection, and cursor, asserting fetch results and interaction with connect/execute/close.
  • Add test for exception during sqlite3.connect that verifies the function returns an empty list and handles errors gracefully.
router/tests/test_get_goose_sessions.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

Warning

Review limit reached

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

Next review available in: 10 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: b1f27357-f668-4003-bbd6-526291b4f5b2

📥 Commits

Reviewing files that changed from the base of the PR and between b3334f5 and 5d067bb.

📒 Files selected for processing (3)
  • pod.yaml
  • router/tests/test_get_goose_sessions.py
  • start-stack.sh
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/test-get-goose-sessions-16558526271462662412

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 found 2 issues, and left some high level feedback:

  • The tests manipulate sys.path and CONFIG_PATH at import time, which can introduce hidden coupling and side effects; consider using pytest fixtures or project-relative imports instead of modifying global state in the test module.
  • Patching sqlite3 via patch.dict(sys.modules, {'sqlite3': mock_sqlite3}) is quite invasive; patch the sqlite3 symbol where it is imported in main (e.g., patch('main.sqlite3.connect', ...)) to keep the mocking scoped and less brittle.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The tests manipulate `sys.path` and `CONFIG_PATH` at import time, which can introduce hidden coupling and side effects; consider using pytest fixtures or project-relative imports instead of modifying global state in the test module.
- Patching `sqlite3` via `patch.dict(sys.modules, {'sqlite3': mock_sqlite3})` is quite invasive; patch the `sqlite3` symbol where it is imported in `main` (e.g., `patch('main.sqlite3.connect', ...)`) to keep the mocking scoped and less brittle.

## Individual Comments

### Comment 1
<location path="router/tests/test_get_goose_sessions.py" line_range="12-14" />
<code_context>
+
+from main import get_goose_sessions
+
+def test_get_goose_sessions_no_db():
+    with patch('os.path.exists', return_value=False):
+        assert get_goose_sessions() == []
+
+def test_get_goose_sessions_success():
</code_context>
<issue_to_address>
**suggestion (testing):** Also assert that no DB connection is attempted when the file does not exist

The existing test correctly checks that an empty list is returned when the DB file is missing. To more fully verify the behavior, also assert that `sqlite3.connect` is not called in this case (e.g., by mocking `sqlite3` and using `mock_sqlite3.connect.assert_not_called()`). This confirms the code short-circuits before any DB interaction.

```suggestion
def test_get_goose_sessions_no_db():
    with patch('os.path.exists', return_value=False), patch('main.sqlite3') as mock_sqlite3:
        assert get_goose_sessions() == []
        mock_sqlite3.connect.assert_not_called()
```
</issue_to_address>

### Comment 2
<location path="router/tests/test_get_goose_sessions.py" line_range="7-8" />
<code_context>
+from pathlib import Path
+from unittest.mock import patch, MagicMock
+
+os.environ["CONFIG_PATH"] = str(Path(__file__).resolve().parent.parent / "config.yaml")
+sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
+
+from main import get_goose_sessions
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid module-level mutation of environment and sys.path in tests to reduce cross-test side effects

These assignments to `os.environ["CONFIG_PATH"]` and `sys.path` at module import time can create hidden dependencies between tests and make ordering matter. Instead, move this setup into fixtures or individual tests (e.g., use `pytest`’s `monkeypatch` for both env vars and `sys.path`) so configuration is scoped per test and doesn’t leak across the suite.

Suggested implementation:

```python
import pytest
import sys
import os
from pathlib import Path
from unittest.mock import patch, MagicMock
import importlib

```

```python
@pytest.fixture
def goose_sessions(monkeypatch):
    project_root = Path(__file__).resolve().parent.parent
    config_path = project_root / "config.yaml"

    monkeypatch.setenv("CONFIG_PATH", str(config_path))
    monkeypatch.syspath_prepend(str(project_root))

    # Import or reload main after environment and path are configured
    import main
    importlib.reload(main)

    return main.get_goose_sessions


def test_get_goose_sessions_no_db(goose_sessions):
    with patch('os.path.exists', return_value=False):
        assert goose_sessions() == []

```

```python
def test_get_goose_sessions_success(goose_sessions):
    mock_sqlite3 = MagicMock()
    mock_conn = MagicMock()
    mock_cursor = MagicMock()

```

If other tests in this file (not shown in the snippet) reference `get_goose_sessions` directly or rely on the previous module-level configuration, they should be updated to:
1. Accept the `goose_sessions` fixture as a parameter.
2. Call `goose_sessions()` instead of `get_goose_sessions()`.
This ensures all tests use scoped configuration via `monkeypatch` and avoid cross-test side effects.
</issue_to_address>

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.

Comment on lines +12 to +14
def test_get_goose_sessions_no_db():
with patch('os.path.exists', return_value=False):
assert get_goose_sessions() == []

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.

suggestion (testing): Also assert that no DB connection is attempted when the file does not exist

The existing test correctly checks that an empty list is returned when the DB file is missing. To more fully verify the behavior, also assert that sqlite3.connect is not called in this case (e.g., by mocking sqlite3 and using mock_sqlite3.connect.assert_not_called()). This confirms the code short-circuits before any DB interaction.

Suggested change
def test_get_goose_sessions_no_db():
with patch('os.path.exists', return_value=False):
assert get_goose_sessions() == []
def test_get_goose_sessions_no_db():
with patch('os.path.exists', return_value=False), patch('main.sqlite3') as mock_sqlite3:
assert get_goose_sessions() == []
mock_sqlite3.connect.assert_not_called()

Comment on lines +7 to +8
os.environ["CONFIG_PATH"] = str(Path(__file__).resolve().parent.parent / "config.yaml")
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

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.

suggestion (testing): Avoid module-level mutation of environment and sys.path in tests to reduce cross-test side effects

These assignments to os.environ["CONFIG_PATH"] and sys.path at module import time can create hidden dependencies between tests and make ordering matter. Instead, move this setup into fixtures or individual tests (e.g., use pytest’s monkeypatch for both env vars and sys.path) so configuration is scoped per test and doesn’t leak across the suite.

Suggested implementation:

import pytest
import sys
import os
from pathlib import Path
from unittest.mock import patch, MagicMock
import importlib
@pytest.fixture
def goose_sessions(monkeypatch):
    project_root = Path(__file__).resolve().parent.parent
    config_path = project_root / "config.yaml"

    monkeypatch.setenv("CONFIG_PATH", str(config_path))
    monkeypatch.syspath_prepend(str(project_root))

    # Import or reload main after environment and path are configured
    import main
    importlib.reload(main)

    return main.get_goose_sessions


def test_get_goose_sessions_no_db(goose_sessions):
    with patch('os.path.exists', return_value=False):
        assert goose_sessions() == []
def test_get_goose_sessions_success(goose_sessions):
    mock_sqlite3 = MagicMock()
    mock_conn = MagicMock()
    mock_cursor = MagicMock()

If other tests in this file (not shown in the snippet) reference get_goose_sessions directly or rely on the previous module-level configuration, they should be updated to:

  1. Accept the goose_sessions fixture as a parameter.
  2. Call goose_sessions() instead of get_goose_sessions().
    This ensures all tests use scoped configuration via monkeypatch and avoid cross-test side effects.

@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@jules
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.

README.md
get_pr_status.py
host_agy_daemon.py
pod.yaml
router/tests/test_dashboard_data.py
start-stack.sh
test_host_agy_daemon.py
test_pie_chart_gradient.py
test_record_tool_usage.py

google-labs-jules Bot and others added 2 commits July 1, 2026 09:43
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: Got it, kicking off a fresh review 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 unit tests for the get_goose_sessions function in router/tests/test_get_goose_sessions.py. However, the start-stack.sh script contains multiple unresolved merge conflict markers and a syntax issue with missing commas in a Python list that must be resolved before merging.

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 start-stack.sh Outdated
Comment on lines +144 to +145
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
=======

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.

critical

Unresolved merge conflict markers are present in the script. Please remove the conflict markers and keep the master branch changes to ensure the script runs correctly.

Comment thread start-stack.sh Outdated
echo "✓ Generated new CLICKHOUSE_PASSWORD and saved to $ENV_FILE"
fi

>>>>>>> master

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.

critical

Unresolved merge conflict marker >>>>>>> master is present here. Please remove it.

Comment thread start-stack.sh Outdated
Comment on lines +388 to +392
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
export WORKDIR HOME LITELLM_MASTER_KEY POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD
=======
export WORKDIR HOME LITELLM_MASTER_KEY POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD REDIS_AUTH CLICKHOUSE_PASSWORD
>>>>>>> master

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.

critical

Unresolved merge conflict markers in render_pod_yaml. Please resolve this by keeping the master branch version which includes REDIS_AUTH and CLICKHOUSE_PASSWORD.

Suggested change
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
export WORKDIR HOME LITELLM_MASTER_KEY POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD
=======
export WORKDIR HOME LITELLM_MASTER_KEY POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD REDIS_AUTH CLICKHOUSE_PASSWORD
>>>>>>> master
export WORKDIR HOME LITELLM_MASTER_KEY POSTGRES_PASSWORD NEXTAUTH_SECRET SALT ENCRYPTION_KEY LANGFUSE_INIT_USER_PASSWORD MINIO_ROOT_USER MINIO_ROOT_PASSWORD REDIS_AUTH CLICKHOUSE_PASSWORD

Comment thread start-stack.sh Outdated
Comment on lines +409 to +417
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
"MINIO_PASSWORD_PLACEHOLDER"
"LANGFUSE_INIT_USER_PASSWORD_PLACEHOLDER"
=======
"MINIO_PASSWORD_PLACEHOLDER",
"LANGFUSE_INIT_USER_PASSWORD_PLACEHOLDER",
"REDIS_AUTH_PLACEHOLDER",
"CLICKHOUSE_PASSWORD_PLACEHOLDER"
>>>>>>> master

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.

critical

Unresolved merge conflict markers in the python placeholders list. Note that the branch version also lacks commas between string literals, which would cause implicit string concatenation and break the placeholder checks. Please resolve this by keeping the master branch version.

Suggested change
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
"MINIO_PASSWORD_PLACEHOLDER"
"LANGFUSE_INIT_USER_PASSWORD_PLACEHOLDER"
=======
"MINIO_PASSWORD_PLACEHOLDER",
"LANGFUSE_INIT_USER_PASSWORD_PLACEHOLDER",
"REDIS_AUTH_PLACEHOLDER",
"CLICKHOUSE_PASSWORD_PLACEHOLDER"
>>>>>>> master
"MINIO_PASSWORD_PLACEHOLDER",
"LANGFUSE_INIT_USER_PASSWORD_PLACEHOLDER",
"REDIS_AUTH_PLACEHOLDER",
"CLICKHOUSE_PASSWORD_PLACEHOLDER"

Comment thread start-stack.sh Outdated
Comment on lines +437 to +441
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
=======
text = text.replace("REDIS_AUTH_PLACEHOLDER", os.environ["REDIS_AUTH"])
text = text.replace("CLICKHOUSE_PASSWORD_PLACEHOLDER", os.environ["CLICKHOUSE_PASSWORD"])
>>>>>>> master

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.

critical

Unresolved merge conflict markers in the python string replacement block. Please resolve this by keeping the master branch version.

Suggested change
<<<<<<< chore/test-get-goose-sessions-16558526271462662412
=======
text = text.replace("REDIS_AUTH_PLACEHOLDER", os.environ["REDIS_AUTH"])
text = text.replace("CLICKHOUSE_PASSWORD_PLACEHOLDER", os.environ["CLICKHOUSE_PASSWORD"])
>>>>>>> master
text = text.replace("REDIS_AUTH_PLACEHOLDER", os.environ["REDIS_AUTH"])
text = text.replace("CLICKHOUSE_PASSWORD_PLACEHOLDER", os.environ["CLICKHOUSE_PASSWORD"])

@sheepdestroyer

Copy link
Copy Markdown
Owner Author

@jules

  • 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.

google-labs-jules Bot and others added 2 commits July 1, 2026 09:57
Co-authored-by: sheepdestroyer <1377479+sheepdestroyer@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