Skip to content

Conversation

@omertuc
Copy link
Contributor

@omertuc omertuc commented Oct 8, 2025

Description

  .../assisted-chat/lightspeed-stack/src/authorization/middleware.py:91: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
    if not access_resolver.check_access(action, user_roles):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

mock_access_resolver is created as an AsyncMock, which makes all its
methods async by default, but AccessResolver check_access is sync

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #
  • Closes #

LCORE-602

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • Tests
    • Updated authorization test helpers to align synchronous/asynchronous behavior, improving reliability and reducing flakiness.
    • Refined mock configurations to better reflect expected roles, actions, and access outcomes in tests.
    • Minor improvements to test readability and maintainability.
    • No changes to application functionality or user experience.

```
  .../assisted-chat/lightspeed-stack/src/authorization/middleware.py:91: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
    if not access_resolver.check_access(action, user_roles):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
```

`mock_access_resolver` is created as an `AsyncMock`, which makes all its
methods async by default, but `AccessResolver` `check_access` is sync
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

Walkthrough

A test utility was updated: in mock_authorization_resolvers, mock_access_resolver is now a synchronous Mock instead of AsyncMock. Other mocked behaviors remain unchanged (roles resolve to empty set, access checks return True, actions getter returns a set of Action).

Changes

Cohort / File(s) Summary of Changes
Test auth helpers
tests/unit/utils/auth_helpers.py
Changed mock_access_resolver from AsyncMock to Mock; preserved return behaviors for resolve_roles (empty set), check_access (True), and get_actions (set of Action).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my nose at mocks anew,
Async no more—now sync will do.
Roles are empty, access true,
Actions gathered like morning dew.
I thump approval, hop on through—
Tests aligned, and swiftly too. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly references the issue number and states the core objective of fixing a unit‐test warning, concisely conveying the main purpose of the changes without unnecessary detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 690a6bc and a69b96e.

📒 Files selected for processing (1)
  • tests/unit/utils/auth_helpers.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.py: All modules start with descriptive module-level docstrings explaining purpose
Use logger = logging.getLogger(name) for module logging after import logging
Define type aliases at module level for clarity
All functions require docstrings with brief descriptions
Provide complete type annotations for all function parameters and return types
Use typing_extensions.Self in model validators where appropriate
Use modern union syntax (str | int) and Optional[T] or T | None consistently
Function names use snake_case with descriptive, action-oriented prefixes (get_, validate_, check_)
Avoid in-place parameter modification; return new data structures instead of mutating arguments
Use appropriate logging levels: debug, info, warning, error with clear messages
All classes require descriptive docstrings explaining purpose
Class names use PascalCase with conventional suffixes (Configuration, Error/Exception, Resolver, Interface)
Abstract base classes should use abc.ABC and @AbstractMethod for interfaces
Provide complete type annotations for all class attributes
Follow Google Python docstring style for modules, classes, and functions, including Args, Returns, Raises, Attributes sections as needed

Files:

  • tests/unit/utils/auth_helpers.py
tests/{unit,integration}/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/{unit,integration}/**/*.py: Use pytest for all unit and integration tests
Do not use unittest in tests; pytest is the standard

Files:

  • tests/unit/utils/auth_helpers.py
tests/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

tests/**/*.py: Use pytest-mock to create AsyncMock objects for async interactions in tests
Use the shared auth mock constant: MOCK_AUTH = ("mock_user_id", "mock_username", False, "mock_token") in tests

Files:

  • tests/unit/utils/auth_helpers.py
⏰ 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). (2)
  • GitHub Check: e2e_tests (ci)
  • GitHub Check: build-pr
🔇 Additional comments (1)
tests/unit/utils/auth_helpers.py (1)

22-22: Approve RuntimeWarning fix
Changing mock_access_resolver from AsyncMock to Mock eliminates the unawaited coroutine warning. Verified that AccessResolver.check_access and get_actions are synchronous methods.


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 and usage tips.

Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

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

LGTM

@tisnik tisnik merged commit 44435d2 into lightspeed-core:main Oct 8, 2025
18 of 19 checks passed
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.

2 participants