Skip to content

refactor(checks): make Scenario mutable and remove scenario() factory#2296

Merged
mattbit merged 5 commits intomainfrom
2287-scenario-builder-encourages-variable-shadowing
Mar 11, 2026
Merged

refactor(checks): make Scenario mutable and remove scenario() factory#2296
mattbit merged 5 commits intomainfrom
2287-scenario-builder-encourages-variable-shadowing

Conversation

@kevinmessiaen
Copy link
Copy Markdown
Member

Description

  • Remove ScenarioBuilder and scenario() to eliminate variable shadowing
  • Add fluent methods (interact, check, etc.) directly to Scenario
  • Update Suite to accept only Scenario
  • Use scenario/scenario1/scenario2 as variable names in examples

BREAKING CHANGE: scenario() and ScenarioBuilder are removed. Use Scenario("name").interact(...).check(...) instead.

Type of Change

  • 💥 Breaking change (fix or feature that would cause existing functionality to change)

- Remove ScenarioBuilder and scenario() to eliminate variable shadowing
- Add fluent methods (interact, check, etc.) directly to Scenario
- Update Suite to accept only Scenario
- Use scenario/scenario1/scenario2 as variable names in examples

BREAKING CHANGE: scenario() and ScenarioBuilder are removed. Use
Scenario("name").interact(...).check(...) instead.

Closes #2287

Made-with: Cursor
@kevinmessiaen kevinmessiaen linked an issue Mar 9, 2026 that may be closed by this pull request
@kevinmessiaen kevinmessiaen requested a review from mattbit March 9, 2026 03:36
@kevinmessiaen kevinmessiaen self-assigned this Mar 9, 2026
@gemini-code-assist
Copy link
Copy Markdown
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 refactors the scenario creation and management API to simplify its usage and improve consistency. By making the Scenario class mutable and embedding fluent methods directly within it, the need for a separate ScenarioBuilder and scenario() factory function is eliminated. This change reduces boilerplate, prevents potential variable shadowing issues, and makes the API more intuitive for users, while also updating the Suite class to align with the new Scenario object-centric approach.

Highlights

  • API Simplification: The ScenarioBuilder class and the scenario() factory function have been removed, streamlining the API for creating scenarios.
  • Mutable Scenario Class: The Scenario class is now mutable and directly incorporates fluent methods such as interact(), check(), append(), and extend(), allowing scenarios to be built directly on Scenario instances.
  • Improved Type Consistency: The Suite class now exclusively accepts Scenario objects, removing support for ScenarioBuilder instances and enhancing type consistency.
  • Variable Naming Convention: Examples and documentation have been updated to use scenario, scenario1, and scenario2 as variable names for Scenario instances, avoiding shadowing with the Scenario class name.

🧠 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
  • libs/giskard-checks/CODEMAP.md
    • Updated scenario examples to use scenario1 instead of s1 for clarity.
    • Removed ScenarioBuilder and scenario from the imported modules list.
  • libs/giskard-checks/README.md
    • Updated the description of the fluent scenario builder and runner to refer only to Scenario.
    • Modified quickstart examples to instantiate Scenario directly instead of using the scenario() factory function.
    • Adjusted variable names in examples from test_scenario to scenario and s1/s2 to scenario1/scenario2 to avoid shadowing.
    • Updated the 'Fluent API' concept description to reflect direct Scenario(...) usage.
  • libs/giskard-checks/src/giskard/checks/init.py
    • Removed imports for ScenarioBuilder and scenario from the module's public API.
  • libs/giskard-checks/src/giskard/checks/core/scenario.py
    • Removed frozen=True from the Scenario class definition, making it mutable.
    • Updated the Scenario class docstring to reflect the new fluent API usage.
    • Changed the sequence attribute type from Sequence to list.
    • Set default values for name and sequence attributes.
    • Added an __init__ method to allow positional name argument for Scenario instantiation.
    • Implemented fluent methods (interact, check, checks, add_interaction, add_interactions, append, extend, with_annotations, with_target) directly within the Scenario class.
  • libs/giskard-checks/src/giskard/checks/core/testcase.py
    • Updated the docstring example to use Scenario(...).interact().check() instead of scenario().interact().check().
  • libs/giskard-checks/src/giskard/checks/scenarios/init.py
    • Removed ScenarioBuilder and scenario from the __all__ export list.
  • libs/giskard-checks/src/giskard/checks/scenarios/builder.py
    • Removed the builder.py file, which contained the ScenarioBuilder class and scenario() factory function.
  • libs/giskard-checks/src/giskard/checks/scenarios/suite.py
    • Removed the import of ScenarioBuilder.
    • Updated the append method to accept only Scenario objects, removing support for ScenarioBuilder.
    • Modified docstring examples to instantiate Scenario directly.
  • libs/giskard-checks/tests/core/test_scenario.py
    • Removed the import of scenario.
    • Updated all test cases to instantiate Scenario directly using Scenario(...) instead of the scenario() factory function.
  • libs/giskard-checks/tests/core/test_suite.py
    • Removed the import of scenario.
    • Updated all test cases to instantiate Scenario directly using Scenario(...) instead of the scenario() factory function.
  • libs/giskard-checks/tests/integration/test_stateful.py
    • Removed the import of scenario and added Scenario to the import list.
    • Updated test cases to instantiate Scenario directly.
  • libs/giskard-checks/tests/integration/test_stateless.py
    • Removed the import of scenario.
    • Updated test cases to instantiate Scenario directly.
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.

Copy link
Copy Markdown
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 is a significant refactoring that simplifies the API for creating scenarios. It makes the Scenario class mutable and adds fluent methods directly to it, removing the need for ScenarioBuilder and the scenario() factory function. The changes are well-implemented and consistently applied across the codebase, including code, tests, and documentation.

My review found a couple of minor inconsistencies in the code examples within the README.md file, where the old scenario factory is still being imported. I've left specific suggestions to correct these.

Copy link
Copy Markdown
Member

@mattbit mattbit left a comment

Choose a reason for hiding this comment

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

Looks good, I will do some QA

@mattbit mattbit merged commit 7463496 into main Mar 11, 2026
23 checks passed
@mattbit mattbit deleted the 2287-scenario-builder-encourages-variable-shadowing branch March 11, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Scenario builder encourages variable shadowing

2 participants