TEST-INFRA: [missing-test-levels] Add Behave coverage for if __name__ == "__main__" guard in src/cleveragents/__main__.py #1619

Open
opened 2026-04-02 23:15:23 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: test/main-entrypoint-guard-coverage
  • Commit Message: test(__main__): cover if __name__ == "__main__" guard via subprocess execution
  • Milestone: v3.8.0
  • Parent Epic: #933

Description

src/cleveragents/__main__.py contains the following guard on its final line:

if __name__ == "__main__":
    sys.exit(run())

This guard is the canonical entry point invoked when a user runs python -m cleveragents. It is not covered by the current Behave test suite because all existing scenarios exercise the run() function or the CLI app in-process via CliRunner or mock patches — none of them cause coverage.py to record the if __name__ == "__main__" branch itself as executed.

The correct way to cover this line is to invoke the module as a subprocess (e.g. via runpy.run_module("cleveragents", run_name="__main__") with appropriate patching, or via a real subprocess call) so that the guard evaluates to True and sys.exit(run()) is actually reached.

This gap risks the overall project coverage falling below the mandatory 97% threshold defined in CONTRIBUTING.md.

Subtasks

  • Identify the exact uncovered line(s) in src/cleveragents/__main__.py by running nox -e coverage_report and inspecting the HTML report
  • Write a new Behave scenario (or extend an existing feature file) that exercises the if __name__ == "__main__" branch by invoking the module via runpy.run_module or a patched subprocess call
  • Place any required test doubles (mocks/fakes) exclusively in features/mocks/
  • Verify nox -e unit_tests passes with the new scenario
  • Verify nox -e coverage_report shows src/cleveragents/__main__.py at 100% and overall coverage >= 97%
  • Verify nox -e typecheck passes (all step definitions must be fully typed)
  • Verify nox -e lint passes

Definition of Done

  • All subtasks above are checked off
  • The new Behave scenario is written in Gherkin syntax under features/
  • No pytest-style or xUnit-style tests introduced
  • All mocks placed exclusively in features/mocks/
  • All step definition code is statically typed and passes nox -e typecheck
  • src/cleveragents/__main__.py reports 100% line and branch coverage
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: Unknown | Agent: ca-new-issue-creator

## Metadata - **Branch**: `test/main-entrypoint-guard-coverage` - **Commit Message**: `test(__main__): cover if __name__ == "__main__" guard via subprocess execution` - **Milestone**: v3.8.0 - **Parent Epic**: #933 ## Description `src/cleveragents/__main__.py` contains the following guard on its final line: ```python if __name__ == "__main__": sys.exit(run()) ``` This guard is the canonical entry point invoked when a user runs `python -m cleveragents`. It is **not covered** by the current Behave test suite because all existing scenarios exercise the `run()` function or the CLI app in-process via `CliRunner` or mock patches — none of them cause `coverage.py` to record the `if __name__ == "__main__"` branch itself as executed. The correct way to cover this line is to invoke the module as a subprocess (e.g. via `runpy.run_module("cleveragents", run_name="__main__")` with appropriate patching, or via a real `subprocess` call) so that the guard evaluates to `True` and `sys.exit(run())` is actually reached. This gap risks the overall project coverage falling below the mandatory 97% threshold defined in CONTRIBUTING.md. ## Subtasks - [ ] Identify the exact uncovered line(s) in `src/cleveragents/__main__.py` by running `nox -e coverage_report` and inspecting the HTML report - [ ] Write a new Behave scenario (or extend an existing feature file) that exercises the `if __name__ == "__main__"` branch by invoking the module via `runpy.run_module` or a patched subprocess call - [ ] Place any required test doubles (mocks/fakes) exclusively in `features/mocks/` - [ ] Verify `nox -e unit_tests` passes with the new scenario - [ ] Verify `nox -e coverage_report` shows `src/cleveragents/__main__.py` at 100% and overall coverage >= 97% - [ ] Verify `nox -e typecheck` passes (all step definitions must be fully typed) - [ ] Verify `nox -e lint` passes ## Definition of Done - [ ] All subtasks above are checked off - [ ] The new Behave scenario is written in Gherkin syntax under `features/` - [ ] No pytest-style or xUnit-style tests introduced - [ ] All mocks placed exclusively in `features/mocks/` - [ ] All step definition code is statically typed and passes `nox -e typecheck` - [ ] `src/cleveragents/__main__.py` reports 100% line and branch coverage - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Unknown | Agent: ca-new-issue-creator
freemo added this to the v3.8.0 milestone 2026-04-02 23:15:34 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Priority/Medium
  • MoSCoW: MoSCoW/Could Have — adding Behave coverage for main blocks is a test coverage improvement. Could Have.

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Priority/Medium - **MoSCoW**: MoSCoW/Could Have — adding Behave coverage for __main__ blocks is a test coverage improvement. Could Have. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
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.

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