Skip to content

fix(tests): align framework and datastore mocks with current APIs#1665

Merged
MervinPraison merged 2 commits into
mainfrom
fix/tests-stale-mock-targets-framework-and-datastore
May 14, 2026
Merged

fix(tests): align framework and datastore mocks with current APIs#1665
MervinPraison merged 2 commits into
mainfrom
fix/tests-stale-mock-targets-framework-and-datastore

Conversation

@MervinPraison

@MervinPraison MervinPraison commented May 14, 2026

Copy link
Copy Markdown
Owner
  • Patch get_default_registry instead of removed FrameworkAdapterRegistry.get_instance.\n- Patch praisonaiagents.session.get_hierarchical_session_store and reset _impl_cls so the default-store path is exercised correctly.

Made with Cursor

Summary by CodeRabbit

  • Tests
    • Made datastore initialization tests deterministic and ensured failures surface loudly instead of falling back silently.
    • Reworked framework validator tests to mock framework-availability resolution via the registry helper, validating ImportError messages for missing, known, and unknown frameworks and confirming no-exception behavior when available.

Review Change Stack

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI review requested due to automatic review settings May 14, 2026 17:15
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more β†’

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account β†’

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us β†’

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5719f0a2-3fb4-4959-a422-629c0259aa27

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between dd7e4e4 and 62eee03.

πŸ“’ Files selected for processing (1)
  • src/praisonai/tests/unit/test_aiui_datastore.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/praisonai/tests/unit/test_aiui_datastore.py

πŸ“ Walkthrough

Walkthrough

Two unit-test modules change their mocking targets: session datastore tests patch praisonaiagents.session.get_hierarchical_session_store and reset cached implementation state, while framework validator tests mock praisonai.framework_adapters.validators.get_default_registry instead of the registry class.

Changes

Test Mocking Strategy Refactors

Layer / File(s) Summary
Session DataStore initialization test refactoring
src/praisonai/tests/unit/test_aiui_datastore.py
test_init_with_default_store patches praisonaiagents.session.get_hierarchical_session_store, imports praisonai.ui._aiui_datastore as _ds, forces _ds._impl_cls = None before constructing PraisonAISessionDataStore, and removes the prior test_import_fallback no-op (replaced by a comment).
Framework validator availability test refactoring
src/praisonai/tests/unit/test_framework_validators.py
Removes module-level FrameworkAdapterRegistry import and updates tests to mock praisonai.framework_adapters.validators.get_default_registry (instead of FrameworkAdapterRegistry.get_instance) to control is_available() and validate ImportError messages and install hints.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • MervinPraison/PraisonAI#1444: Related to the PraisonAISessionDataStore initialization and aiui.set_datastore(...) wiring that the datastore tests now exercise.

Poem

🐰 Tests hop in neat array,
Patches switched to show the way,
Factories mocked, caches cleared,
Deterministic paths appear,
A tiny rabbit clapsβ€”hooray!

πŸš₯ Pre-merge checks | βœ… 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% 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 accurately describes the main changes: updating test mocks in the framework and datastore modules to align with current API changes (removal of FrameworkAdapterRegistry.get_instance and updates to mock targets).
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tests-stale-mock-targets-framework-and-datastore

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.

@MervinPraison

Copy link
Copy Markdown
Owner Author

@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first β€” incorporate their findings.

Review areas:

  1. Bloat check: Are changes minimal and focused? Any unnecessary code or scope creep?
  2. Security: Any hardcoded secrets, unsafe eval/exec, missing input validation?
  3. Performance: Any module-level heavy imports? Hot-path regressions?
  4. Tests: Are tests included? Do they cover the changes adequately?
  5. Backward compat: Any public API changes without deprecation?
  6. Code quality: DRY violations, naming conventions, error handling?
  7. Address reviewer feedback: If Qodo, Coderabbit, or Gemini flagged valid issues, include them in your review
  8. Suggest specific improvements with code examples where possible

@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 updates unit tests for the AI UI datastore and framework validators. In test_aiui_datastore.py, the patch target for the session store was modified and the implementation class is now reset during the test. In test_framework_validators.py, the tests were refactored to patch get_default_registry directly instead of using FrameworkAdapterRegistry.get_instance. Feedback was provided regarding the risk of modifying global state in tests and a suggestion was made to use patch.object for safer state management, along with a reminder to verify the correct patch target location.

Comment on lines +15 to +18
with patch("praisonaiagents.session.get_hierarchical_session_store") as mock_get_store:
mock_store = Mock()
mock_get_store.return_value = mock_store

_ds._impl_cls = None

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.

medium

Directly setting _ds._impl_cls = None modifies the module's global state, which can lead to test interference and flakiness. It is better to use patch.object to ensure the state is automatically restored after the test block.

Also, verify the patch target "praisonaiagents.session.get_hierarchical_session_store". If the module under test (_ds) uses from praisonaiagents.session import get_hierarchical_session_store, patching the source module will not affect the reference already imported into _ds. In that case, you should patch the usage point: "praisonai.ui._aiui_datastore.get_hierarchical_session_store".

Suggested change
with patch("praisonaiagents.session.get_hierarchical_session_store") as mock_get_store:
mock_store = Mock()
mock_get_store.return_value = mock_store
_ds._impl_cls = None
with patch("praisonaiagents.session.get_hierarchical_session_store") as mock_get_store, \
patch.object(_ds, "_impl_cls", None):
mock_store = Mock()
mock_get_store.return_value = mock_store

Copilot AI 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.

Pull request overview

This PR updates unit tests to match the current registry and session-store APIs after upstream refactors (removal of FrameworkAdapterRegistry.get_instance and changes to how the default hierarchical session store is accessed).

Changes:

  • Update framework validator tests to patch get_default_registry() instead of the removed FrameworkAdapterRegistry.get_instance().
  • Update aiui datastore adapter tests to patch praisonaiagents.session.get_hierarchical_session_store and reset the cached datastore implementation class to exercise the default-store code path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/praisonai/tests/unit/test_framework_validators.py Replaces registry mocking approach to align with get_default_registry() usage in validators.
src/praisonai/tests/unit/test_aiui_datastore.py Adjusts datastore mocking to target the current session-store getter and forces rebuilding the cached impl class for the test.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to 20
import praisonai.ui._aiui_datastore as _ds

with patch("praisonaiagents.session.get_hierarchical_session_store") as mock_get_store, \
patch.object(_ds, "_impl_cls", None):
mock_store = Mock()
mock_get_store.return_value = mock_store

adapter = PraisonAISessionDataStore()
@MervinPraison

Copy link
Copy Markdown
Owner Author

@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding.

Phase 1: Review per AGENTS.md

  1. Protocol-driven: check heavy implementations vs core SDK
  2. Backward compatible: ensure zero feature regressions
  3. Performance: no hot-path regressions

Phase 2: FIX Valid Issues
4. For any VALID bugs or architectural flaws found by Gemini, CodeRabbit, Qodo, Copilot, or any other reviewer: implement the fix
5. Push all code fixes directly to THIS branch (do NOT create a new PR)
6. Comment a summary of exact files modified and what you skipped

Phase 3: Final Verdict
7. If all issues are resolved, approve the PR / close the Issue
8. If blocking issues remain, request changes / leave clear action items

Copilot AI commented May 14, 2026

Copy link
Copy Markdown
Contributor

@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first β€” incorporate their findings.

Review areas:...

Completed the review and applied the only actionable finding from existing bot feedback in commit 62eee03.

  • Qodo: no code findings (review paused notice only).
  • CodeRabbit: still in β€œreview in progress”; no concrete issues posted yet.
  • Gemini: valid concern about leaking global test state; fixed by scoping _impl_cls reset with patch.object(_ds, "_impl_cls", None).

Review results:

  1. Bloat: changes remain minimal (2 test files in PR; this follow-up touches 1 test only).
  2. Security: no secrets/unsafe eval/exec introduced.
  3. Performance: test-only mocking change; no runtime hot-path impact.
  4. Tests: coverage for updated mock paths remains; one test made safer against cross-test interference.
  5. Backward compat: no public API changes.
  6. Code quality: improved isolation/cleanup of module-global state.
  7. Reviewer feedback: incorporated Gemini’s valid issue; no actionable Qodo/CodeRabbit findings available yet.
  8. Suggested improvement already applied:
with patch("praisonaiagents.session.get_hierarchical_session_store") as mock_get_store, \
     patch.object(_ds, "_impl_cls", None):
    ...

I also checked Actions runs for this branch; many push workflows are marked failure with no jobs created, so there were no job logs to analyze for test failures.

@praisonai-triage-agent

praisonai-triage-agent Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

Claude finished @MervinPraison's task β€”β€” View job


Final Architecture Review βœ…

Phase 1: Architecture Review per AGENTS.md

  • Read AGENTS.md architecture guidelines
  • Review changes for protocol-driven design compliance
  • Check backward compatibility
  • Assess performance impact

Phase 2: Fix Valid Issues

  • Analyze previous reviewer feedback (Gemini, CodeRabbit, Qodo, Copilot)
  • Validate Copilot's fix for test state leakage issue
  • No additional fixes needed

Phase 3: Final Verdict

  • Approve PR
  • Provide summary of review findings

Architecture Review Results βœ…

1. Protocol-Driven Design Compliance βœ…

  • Changes are test-only and align with current API contracts
  • Framework validators now use get_default_registry() function instead of deprecated FrameworkAdapterRegistry.get_instance()
  • Datastore tests patch correct session store function: praisonaiagents.session.get_hierarchical_session_store

2. Backward Compatibility βœ…

  • No public API changes - only test mocking adjustments
  • Tests now align with current implementation patterns

3. Performance Impact βœ…

  • Zero performance impact - test-only changes
  • No module-level imports or hot-path regressions

Issue Resolution βœ…

Previous Reviewer Issues Addressed:

  1. Gemini's Valid Issue (FIXED by Copilot):

    • βœ… Problem: Direct global state mutation via _ds._impl_cls = None causing potential test interference
    • βœ… Solution: Replaced with scoped patch.object(_ds, "_impl_cls", None) in commit 62eee03
    • βœ… Impact: Eliminates cross-test state leakage, ensures deterministic test execution
  2. CodeRabbit: Still processing (no actionable findings yet)

  3. Qodo: Reviews paused (no actionable findings)

  4. Other Issues: None identified

Test Changes Validation βœ…

File: test_aiui_datastore.py

  • βœ… Correct patch target: praisonaiagents.session.get_hierarchical_session_store
  • βœ… Proper state isolation using patch.object(_ds, "_impl_cls", None)
  • βœ… Test exercises default store initialization path correctly

File: test_framework_validators.py

  • βœ… Removed deprecated FrameworkAdapterRegistry.get_instance() import
  • βœ… Updated all mocks to use current get_default_registry() function
  • βœ… All test scenarios preserved (error messages, install hints, availability checks)

Final Verdict: APPROVED βœ…

This PR successfully aligns test mocks with current API implementations:

  • Minimal & Focused: Only updates stale test mocks, no scope creep
  • Architecture Compliant: Follows protocol-driven patterns correctly
  • Issue Resolution: Copilot's fix properly addresses the only valid reviewer concern
  • Test Quality: Improves test isolation and determinism

Recommendation: MERGE this PR. All changes are technically sound and improve test reliability.


@greptile-apps

greptile-apps Bot commented May 14, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes two unit test files to align their mocking strategies with the current production API. The old tests patched a removed FrameworkAdapterRegistry.get_instance class method and a non-existent module-level name praisonai.ui._aiui_datastore.get_hierarchical_session_store, causing the tests to mock the wrong targets and pass vacuously.

  • test_framework_validators.py: Replaces eight patch.object(FrameworkAdapterRegistry, \"get_instance\") calls with patch(\"praisonai.framework_adapters.validators.get_default_registry\"), which targets the function actually called in assert_framework_available(). The now-unused FrameworkAdapterRegistry import is also removed.
  • test_aiui_datastore.py: Patches praisonaiagents.session.get_hierarchical_session_store at the source module level and resets _ds._impl_cls to None, so _build_impl_cls() re-runs and the from praisonaiagents.session import get_hierarchical_session_store inside it picks up the mock. This is the correct technique for functions captured in a closure via from X import Y.

Confidence Score: 5/5

Test-only changes that correct previously broken mock targets; no production code is modified.

Both changes are narrowly scoped to unit test files. The new mocking approach correctly patches get_default_registry where the source code calls it, and resets _impl_cls to ensure _build_impl_cls() re-executes and captures the mock via the from X import Y closure β€” which is the right technique for this pattern. No edge cases or regressions are introduced.

No files require special attention.

Important Files Changed

Filename Overview
src/praisonai/tests/unit/test_framework_validators.py Removes the import of the deleted FrameworkAdapterRegistry and replaces all eight patch targets with the correct get_default_registry function used in production; no logic issues found.
src/praisonai/tests/unit/test_aiui_datastore.py Fixes test_init_with_default_store by patching the correct source location for get_hierarchical_session_store and resetting _impl_cls so _build_impl_cls() re-runs within the mock context, correctly exercising the default-store path.

Sequence Diagram

sequenceDiagram
    participant T as Test
    participant DS as _aiui_datastore module
    participant PA as praisonaiagents.session

    Note over T: test_init_with_default_store
    T->>DS: patch.object(_ds, "_impl_cls", None)
    T->>PA: patch("...get_hierarchical_session_store") β†’ mock_store
    T->>DS: PraisonAISessionDataStore()
    DS->>DS: __new__ β†’ _build_impl_cls()
    DS->>DS: _impl_cls is None β†’ proceed
    DS->>PA: from praisonaiagents.session import get_hierarchical_session_store
    PA-->>DS: returns mock (captured in closure)
    DS->>DS: create _PraisonAISessionDataStoreImpl class
    DS->>DS: "_impl_cls = new class"
    DS->>DS: "impl_cls(store=None)"
    DS->>PA: get_hierarchical_session_store() β†’ mock_store
    DS-->>T: "adapter._store == mock_store βœ“"
    Note over T,DS: patch.object restores original _impl_cls on exit

    Note over T: test_framework_validators
    T->>T: patch("...validators.get_default_registry") β†’ mock_registry
    T->>T: assert_framework_available("crewai")
    T->>T: "registry = get_default_registry() β†’ mock_registry"
    T->>T: registry.is_available("crewai") β†’ False
    T->>T: raises ImportError βœ“
Loading

Reviews (1): Last reviewed commit: "test: scope datastore impl cache reset v..." | Re-trigger Greptile

@MervinPraison MervinPraison merged commit 7a601b5 into main May 14, 2026
3 checks passed
@MervinPraison MervinPraison deleted the fix/tests-stale-mock-targets-framework-and-datastore branch May 14, 2026 18:16
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.

3 participants