X Tutup
Skip to content

test: add unit tests for planners module#4766

Open
cchinchilla-dev wants to merge 2 commits intogoogle:mainfrom
cchinchilla-dev:test/add-planners-unit-tests
Open

test: add unit tests for planners module#4766
cchinchilla-dev wants to merge 2 commits intogoogle:mainfrom
cchinchilla-dev:test/add-planners-unit-tests

Conversation

@cchinchilla-dev
Copy link
Contributor

Link to Issue or Description of Change

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added 41 tests across three new files:

  • test_base_planner.py (4 tests): Abstract interface enforcement, concrete subclass instantiation, method contracts.
  • test_built_in_planner.py (7 tests): apply_thinking_config() (set, preserve, overwrite with log), return values of build_planning_instruction and process_planning_response.
  • test_plan_re_act_planner.py (30 tests): _split_by_last_pattern(), _mark_as_thought(), _handle_non_function_call_parts() (parametrized for all tags + final answer), process_planning_response() (empty/None parts, function call filtering, text-after-FC dropping), build_planning_instruction().
$ pytest tests/unittests/planners/ -v
41 passed

$ pytest tests/unittests/planners/ --cov=src/google/adk/planners --cov-report=term-missing
base_planner.py 88% (2 uncovered pass in abstract methods)
built_in_planner.py 100%
plan_re_act_planner.py 100%
TOTAL 98%

Manual End-to-End (E2E) Tests:
Not applicable — pure unit tests with no runtime side effects.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Happy to adjust the tests based on maintainer feedback.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the robustness of the planners module by introducing a comprehensive suite of unit tests. These tests validate the expected behavior of the BasePlanner, BuiltInPlanner, and PlanReActPlanner classes, ensuring that the core planning functionalities operate correctly and are resilient to future modifications. This effort contributes to a more stable and maintainable codebase.

Highlights

  • New Unit Tests for Planners Module: Added 41 new unit tests across three files to enhance the test coverage and reliability of the planners module.
  • BasePlanner Testing: Introduced tests for the BasePlanner to ensure proper abstract interface enforcement and method contract adherence.
  • BuiltInPlanner Testing: Added tests for the BuiltInPlanner, specifically covering the apply_thinking_config method's behavior and the return values of build_planning_instruction and process_planning_response.
  • PlanReActPlanner Comprehensive Testing: Implemented extensive tests for the PlanReActPlanner, including its internal utility methods like _split_by_last_pattern, _mark_as_thought, _handle_non_function_call_parts, and its core planning logic in process_planning_response and build_planning_instruction.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • tests/unittests/planners/init.py
    • Added an __init__.py file to establish the planners directory as a Python package.
  • tests/unittests/planners/test_base_planner.py
    • Added tests to verify that the BasePlanner cannot be directly instantiated.
    • Added tests to confirm that a concrete subclass of BasePlanner can be instantiated.
    • Added tests for the build_planning_instruction interface to ensure it returns the expected instruction.
    • Added tests for the process_planning_response interface to ensure it returns the provided response parts.
  • tests/unittests/planners/test_built_in_planner.py
    • Added tests to confirm that BuiltInPlanner correctly stores its thinking_config upon initialization.
    • Added tests for apply_thinking_config to ensure it sets the thinking_config on an LlmRequest.
    • Added tests to verify apply_thinking_config preserves default configurations.
    • Added tests to confirm apply_thinking_config overwrites existing thinking_config values and logs the action.
    • Added tests to ensure apply_thinking_config preserves other GenerateContentConfig parameters.
    • Added tests to confirm build_planning_instruction returns None for BuiltInPlanner.
    • Added tests to confirm process_planning_response returns None for BuiltInPlanner.
  • tests/unittests/planners/test_plan_re_act_planner.py
    • Added tests for _split_by_last_pattern covering various scenarios including pattern presence, absence, and multiple occurrences.
    • Added tests for _mark_as_thought to ensure text parts are correctly marked as thoughts.
    • Added parametrized tests for _handle_non_function_call_parts to verify handling of different planning tags and final answers.
    • Added tests for process_planning_response covering empty/None responses, single text/function call parts, filtering of invalid function calls, and handling of text before/after function calls.
    • Added tests for build_planning_instruction to ensure it returns a non-empty string containing all expected planning tags.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Mar 8, 2026
Copy link
Contributor

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

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 comprehensive suite of unit tests for the planners module, significantly improving code coverage and ensuring the correctness of the abstract BasePlanner and its concrete implementations, BuiltInPlanner and PlanReActPlanner. The tests are well-structured, covering various scenarios including interface contracts, configuration handling, and complex response processing logic. My review found the tests to be of high quality. I have one suggestion to enhance the assertions in one of the tests for PlanReActPlanner to make it even more robust.

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

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit tests for planners module

2 participants

X Tutup