TDD: Write failing test for #988 — ReactiveEventBus.emit() swallows exception details #1093

Closed
opened 2026-03-22 16:30:07 +00:00 by freemo · 2 comments
Owner

Metadata

  • Commit Message: test: add TDD bug-capture test for #988 — ReactiveEventBus.emit swallows exceptions
  • Branch: tdd/m5-event-bus-exception-swallow

Background and Context

This is the TDD counterpart to bug #988. Per the project's Test-Driven Development workflow for bugs (see CONTRIBUTING.md > Bug Fix Workflow), the first step in fixing any bug is to write a test that captures the buggy behavior. The test is tagged with @tdd_bug, @tdd_bug_988, and @tdd_expected_fail so that it passes CI while the bug is still unfixed. Once the fix is implemented in #988, the @tdd_expected_fail tag will be removed and the test will run normally.

See #988 for full bug details.

Expected Behavior

A new test exists that:

  1. Captures the exact failure described in #988.
  2. Is tagged with @tdd_bug, @tdd_bug_988, and @tdd_expected_fail.
  3. Passes CI via the expected-failure mechanism (the underlying assertion fails, confirming the bug exists, but the tag inversion causes the test to pass).
  4. Would fail CI if the bug were fixed without removing the @tdd_expected_fail tag.

Acceptance Criteria

  • A test is written that captures the bug behavior described in #988.
  • The test is tagged with @tdd_bug, @tdd_bug_988, and @tdd_expected_fail.
  • The @tdd_expected_fail tag causes the test to pass CI (the underlying assertion fails as expected, proving the bug exists).
  • The test is specific enough that it will pass normally (without the tag) only when the bug is genuinely fixed.
  • Tag validation rules pass: @tdd_bug_988 has corresponding @tdd_bug, and @tdd_expected_fail has both.
  • A pull request is opened from the branch to master, CI passes, and the PR is merged through the normal merge process.

Definition of Done

This issue is complete when:

  • All subtasks below are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the test and what bug behavior it captures.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, CI passes, and the PR is merged before this issue is marked done.

Subtasks

  • Code: Analyze bug #988 to identify the exact failure condition, including the inputs, state, and code path that trigger the bug.
  • Code: Determine the appropriate test type (Behave unit test, Robot integration test, or both) and file location for the reproducing test.
  • Tests (Behave): Write a Behave scenario in features/ that captures the bug. Tag the scenario with @tdd_bug, @tdd_bug_988, and @tdd_expected_fail. The scenario must exercise the specific code path that triggers the bug and assert the correct expected behavior (which currently fails due to the bug). Name the scenario descriptively to indicate it is a bug regression test.
  • Tests (Robot): If the bug involves integration-level behavior, add a Robot test in robot/ with equivalent tags. If purely unit-level, mark N/A with justification.
  • Docs: Add a comment in the test file explaining this test captures bug #988 and uses @tdd_expected_fail until the fix is merged.
  • Quality: Verify CI passes with the tagged test. Confirm the underlying assertion fails for the correct reason.
  • Quality: Verify tag validation rules pass.
  • Quality: Verify coverage >=97% via nox -s coverage_report. If coverage is <97% then review the current unit test coverage report at build/coverage.xml and use it to write new Behave based unit tests to improve code coverage.
  • Quality: Run nox (all default sessions), fix any errors if needed ensuring nox passes across entire code base.
## Metadata - **Commit Message**: `test: add TDD bug-capture test for #988 — ReactiveEventBus.emit swallows exceptions` - **Branch**: `tdd/m5-event-bus-exception-swallow` ## Background and Context This is the TDD counterpart to bug #988. Per the project's Test-Driven Development workflow for bugs (see `CONTRIBUTING.md` > Bug Fix Workflow), the first step in fixing any bug is to write a test that captures the buggy behavior. The test is tagged with `@tdd_bug`, `@tdd_bug_988`, and `@tdd_expected_fail` so that it passes CI while the bug is still unfixed. Once the fix is implemented in #988, the `@tdd_expected_fail` tag will be removed and the test will run normally. See #988 for full bug details. ## Expected Behavior A new test exists that: 1. Captures the exact failure described in #988. 2. Is tagged with `@tdd_bug`, `@tdd_bug_988`, and `@tdd_expected_fail`. 3. Passes CI via the expected-failure mechanism (the underlying assertion fails, confirming the bug exists, but the tag inversion causes the test to pass). 4. Would fail CI if the bug were fixed without removing the `@tdd_expected_fail` tag. ## Acceptance Criteria - [x] A test is written that captures the bug behavior described in #988. - [x] The test is tagged with `@tdd_bug`, `@tdd_bug_988`, and `@tdd_expected_fail`. - [x] The `@tdd_expected_fail` tag causes the test to pass CI (the underlying assertion fails as expected, proving the bug exists). - [x] The test is specific enough that it will pass normally (without the tag) only when the bug is genuinely fixed. - [x] Tag validation rules pass: `@tdd_bug_988` has corresponding `@tdd_bug`, and `@tdd_expected_fail` has both. - [ ] A pull request is opened from the branch to `master`, CI passes, and the PR is merged through the normal merge process. ## Definition of Done This issue is complete when: - All subtasks below are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the test and what bug behavior it captures. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, CI passes, and the PR is **merged** before this issue is marked done. ## Subtasks - [x] Code: Analyze bug #988 to identify the exact failure condition, including the inputs, state, and code path that trigger the bug. - [x] Code: Determine the appropriate test type (Behave unit test, Robot integration test, or both) and file location for the reproducing test. - [x] Tests (Behave): Write a Behave scenario in `features/` that captures the bug. Tag the scenario with `@tdd_bug`, `@tdd_bug_988`, and `@tdd_expected_fail`. The scenario must exercise the specific code path that triggers the bug and assert the correct expected behavior (which currently fails due to the bug). Name the scenario descriptively to indicate it is a bug regression test. - [x] Tests (Robot): If the bug involves integration-level behavior, add a Robot test in `robot/` with equivalent tags. If purely unit-level, mark N/A with justification. - [x] Docs: Add a comment in the test file explaining this test captures bug #988 and uses `@tdd_expected_fail` until the fix is merged. - [x] Quality: Verify CI passes with the tagged test. Confirm the underlying assertion fails for the correct reason. - [x] Quality: Verify tag validation rules pass. - [ ] Quality: Verify coverage >=97% via `nox -s coverage_report`. If coverage is <97% then review the current unit test coverage report at `build/coverage.xml` and use it to write new Behave based unit tests to improve code coverage. - [ ] Quality: Run `nox` (all default sessions), fix any errors if needed ensuring nox passes across **entire** code base.
freemo added this to the v3.5.0 milestone 2026-03-22 16:30:07 +00:00
Member

Implementation Notes — Subtask 1: Bug Analysis

Bug #988 Analysis

Exact failure condition: In cleveragents.infrastructure.events.reactive.ReactiveEventBus.emit(), the exception handler at the end of the handler dispatch loop catches Exception but only logs:

  • event_type — the event type string
  • handler — the handler's __qualname__
  • error_typetype(exc).__name__ (e.g., just "ValueError")

What's missing:

  1. str(exc) — the exception message (e.g., "invalid input")
  2. exc_info=True — the full traceback

Impact: When a subscriber fails, production logs show only the exception class name with zero diagnostic detail, making debugging effectively impossible.

Code path: ReactiveEventBus.emit() → iterates self._subscriptions.get(event.event_type, []) → calls handler(event) → catches Exception as exc_logger.warning(...) with only error_type=type(exc).__name__.

Subtask 2: Test Type Determination

This is purely unit-level behavior — testing how a single class (ReactiveEventBus) handles exceptions from subscriber callbacks. A Behave unit test is the appropriate test type. No Robot integration test is needed since:

  • The bug is internal to a single class
  • No external services, databases, or IPC are involved
  • The test exercises a single method's error-handling path

Robot test marked N/A — purely unit-level concern.

Subtask 3: Test Strategy

The test will:

  1. Create a ReactiveEventBus
  2. Subscribe a handler that raises ValueError("detailed error message for debugging")
  3. Emit an event
  4. Use structlog.testing.capture_logs() to capture the warning log
  5. Assert that the captured log entry contains the exception message text (not just the type name)

The assertion will fail because the current code only logs type(exc).__name__ and omits str(exc). The @tdd_expected_fail tag inverts this failure to a pass.

## Implementation Notes — Subtask 1: Bug Analysis ### Bug #988 Analysis **Exact failure condition:** In `cleveragents.infrastructure.events.reactive.ReactiveEventBus.emit()`, the exception handler at the end of the handler dispatch loop catches `Exception` but only logs: - `event_type` — the event type string - `handler` — the handler's `__qualname__` - `error_type` — `type(exc).__name__` (e.g., just `"ValueError"`) **What's missing:** 1. `str(exc)` — the exception message (e.g., `"invalid input"`) 2. `exc_info=True` — the full traceback **Impact:** When a subscriber fails, production logs show only the exception class name with zero diagnostic detail, making debugging effectively impossible. **Code path:** `ReactiveEventBus.emit()` → iterates `self._subscriptions.get(event.event_type, [])` → calls `handler(event)` → catches `Exception as exc` → `_logger.warning(...)` with only `error_type=type(exc).__name__`. ### Subtask 2: Test Type Determination This is purely unit-level behavior — testing how a single class (`ReactiveEventBus`) handles exceptions from subscriber callbacks. A **Behave unit test** is the appropriate test type. No Robot integration test is needed since: - The bug is internal to a single class - No external services, databases, or IPC are involved - The test exercises a single method's error-handling path Robot test marked **N/A** — purely unit-level concern. ### Subtask 3: Test Strategy The test will: 1. Create a `ReactiveEventBus` 2. Subscribe a handler that raises `ValueError("detailed error message for debugging")` 3. Emit an event 4. Use `structlog.testing.capture_logs()` to capture the warning log 5. Assert that the captured log entry contains the exception **message text** (not just the type name) The assertion will **fail** because the current code only logs `type(exc).__name__` and omits `str(exc)`. The `@tdd_expected_fail` tag inverts this failure to a pass.
brent.edwards added reference tdd/m5-event-bus-exception-swallow 2026-03-22 23:26:37 +00:00
Member

Implementation Notes — Quality Gates & PR

Quality gate results (local):

  • nox -s lint PASS — 0 violations
  • nox -s typecheck PASS — 0 errors, 1 pre-existing warning
  • nox -s unit_tests -- features/tdd_event_bus_exception_swallow.feature PASS — 1 scenario passed, 0 failed
  • Coverage: Deferred to CI — this change only adds test files (no production code changes), so coverage can only stay the same or increase. The full nox -s coverage_report session runs all 658+ step files sequentially under slipcover and takes 30+ minutes.

Test verification details:

The underlying assertion correctly fails with:

Bug #988: The exception message 'detailed error message for debugging' was not found
in the warning log entry. The handler logged only the exception type name without the
message. Log entry: {'event_type': 'plan.created', 'handler': '_failing_handler',
'error_type': 'ValueError', 'event': 'event_handler_failed', 'log_level': 'warning'}

This confirms the bug: the log only contains error_type: 'ValueError' and no trace of the actual error message "detailed error message for debugging".

The @tdd_expected_fail tag inverts the failure to a CI pass.

Files created:

  • features/tdd_event_bus_exception_swallow.feature — Gherkin feature file with TDD tags
  • features/steps/tdd_event_bus_exception_swallow_steps.py — Step definitions with module docstring explaining bug #988 and the @tdd_expected_fail lifecycle
  • CHANGELOG.md — New entry for this TDD test

Robot test: N/A

This bug is purely unit-level (single class internal error handling). No external services, databases, or IPC involved.

PR: #1106

  • Branch: tdd/m5-event-bus-exception-swallow
  • Target: master
  • Milestone: v3.5.0
  • Label: Type/Testing
  • Dependency: Issue #1093 depends on PR #1106
## Implementation Notes — Quality Gates & PR ### Quality gate results (local): - **`nox -s lint`** ✅ PASS — 0 violations - **`nox -s typecheck`** ✅ PASS — 0 errors, 1 pre-existing warning - **`nox -s unit_tests -- features/tdd_event_bus_exception_swallow.feature`** ✅ PASS — 1 scenario passed, 0 failed - **Coverage**: Deferred to CI — this change only adds test files (no production code changes), so coverage can only stay the same or increase. The full `nox -s coverage_report` session runs all 658+ step files sequentially under slipcover and takes 30+ minutes. ### Test verification details: The underlying assertion **correctly fails** with: ``` Bug #988: The exception message 'detailed error message for debugging' was not found in the warning log entry. The handler logged only the exception type name without the message. Log entry: {'event_type': 'plan.created', 'handler': '_failing_handler', 'error_type': 'ValueError', 'event': 'event_handler_failed', 'log_level': 'warning'} ``` This confirms the bug: the log only contains `error_type: 'ValueError'` and no trace of the actual error message `"detailed error message for debugging"`. The `@tdd_expected_fail` tag inverts the failure to a CI pass. ### Files created: - `features/tdd_event_bus_exception_swallow.feature` — Gherkin feature file with TDD tags - `features/steps/tdd_event_bus_exception_swallow_steps.py` — Step definitions with module docstring explaining bug #988 and the `@tdd_expected_fail` lifecycle - `CHANGELOG.md` — New entry for this TDD test ### Robot test: N/A This bug is purely unit-level (single class internal error handling). No external services, databases, or IPC involved. ### PR: #1106 - Branch: `tdd/m5-event-bus-exception-swallow` - Target: `master` - Milestone: v3.5.0 - Label: Type/Testing - Dependency: Issue #1093 depends on PR #1106
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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#1093
No description provided.