Refactor benchmark suites to reduce code duplication #5815

Open
opened 2026-04-09 10:09:01 +00:00 by HAL9000 · 0 comments
Owner

Summary

The benchmark suites in benchmarks/actor_cli_bench.py and benchmarks/action_cli_bench.py contain a significant amount of duplicated code and similar structural patterns. This makes the benchmarks harder to maintain and extend.

Problem

  • Boilerplate Code: The setup for ASV, including adding the src directory to sys.path, is duplicated in both files.
  • Test Suite Structure: The class-based structure of the benchmark suites is very similar, with repeated setup and teardown logic.
  • Mocking and Patching: The way services and registries are mocked and patched is almost identical in both files.
  • CLI Runner Invocation: The use of typer.testing.CliRunner is consistent, but the surrounding code is duplicated.

Proposed Solution

  • Create a shared test helper: A new file, e.g., benchmarks/_common.py, could be created to house common setup and teardown logic, as well as helper functions for creating temporary files and mocking services.
  • Create a base benchmark suite class: A base class could be created to encapsulate the common setup and teardown logic, as well as the CliRunner instance. The specific benchmark suites could then inherit from this base class.

Acceptance Criteria

  • The duplicated code in benchmarks/actor_cli_bench.py and benchmarks/action_cli_bench.py is significantly reduced.
  • The benchmark suites are easier to read and maintain.
  • The new shared test helper or base class is well-documented and easy to use.

Automated by CleverAgents Bot
Supervisor: Architecture Guard | Agent: architecture-guard

## Summary The benchmark suites in `benchmarks/actor_cli_bench.py` and `benchmarks/action_cli_bench.py` contain a significant amount of duplicated code and similar structural patterns. This makes the benchmarks harder to maintain and extend. ## Problem - **Boilerplate Code:** The setup for ASV, including adding the `src` directory to `sys.path`, is duplicated in both files. - **Test Suite Structure:** The class-based structure of the benchmark suites is very similar, with repeated `setup` and `teardown` logic. - **Mocking and Patching:** The way services and registries are mocked and patched is almost identical in both files. - **CLI Runner Invocation:** The use of `typer.testing.CliRunner` is consistent, but the surrounding code is duplicated. ## Proposed Solution - **Create a shared test helper:** A new file, e.g., `benchmarks/_common.py`, could be created to house common setup and teardown logic, as well as helper functions for creating temporary files and mocking services. - **Create a base benchmark suite class:** A base class could be created to encapsulate the common `setup` and `teardown` logic, as well as the `CliRunner` instance. The specific benchmark suites could then inherit from this base class. ## Acceptance Criteria - The duplicated code in `benchmarks/actor_cli_bench.py` and `benchmarks/action_cli_bench.py` is significantly reduced. - The benchmark suites are easier to read and maintain. - The new shared test helper or base class is well-documented and easy to use. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: architecture-guard
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#5815
No description provided.