Files
cleveragents-core/features
brent.edwards 3d961fa0aa test: add TDD bug-capture test for #988 — ReactiveEventBus.emit swallows exceptions (#1106)
## Summary

Add a TDD bug-capture Behave scenario that proves bug #988 exists: `ReactiveEventBus.emit()` exception handler logs only `type(exc).__name__` (e.g., "ValueError") without the exception message (`str(exc)`) or traceback (`exc_info=True`). When a subscriber fails, the log contains zero diagnostic detail, making production debugging impossible.

## What was done

- **Feature file**: `features/tdd_event_bus_exception_swallow.feature` — tagged `@tdd_expected_fail @tdd_bug @tdd_bug_988`
- **Step definitions**: `features/steps/tdd_event_bus_exception_swallow_steps.py` — subscribes a handler that raises `ValueError("detailed error message for debugging")`, emits an event, captures the structlog warning via `structlog.testing.capture_logs()`, and asserts:
  1. The exception message text appears in the log entry (scenario 1)
  2. The `exc_info` key is present and truthy, confirming traceback logging (scenario 2)
- **Changelog**: Updated `CHANGELOG.md` with the new entry

## How the test works

1. A `ReactiveEventBus` is created with a subscriber that raises `ValueError` with a distinctive message
2. An event is emitted, triggering the failing handler
3. The `emit()` exception handler catches the error and logs a warning via structlog
4. **Scenario 1** asserts the exception **message** (not just the type name) appears in the log entry
5. **Scenario 2** asserts the log entry includes **`exc_info`** (traceback), per bug #988's acceptance criteria requiring `exc_info=True`
6. Both assertions **FAIL** because the current code only logs `type(exc).__name__` — confirming the bug
7. The `@tdd_expected_fail` tag inverts these failures to CI passes

## Test verification

- `nox -s unit_tests`  passes (462 features, 12,232 scenarios passed, 0 failed)
- Both underlying assertions correctly fail, proving the bug exists
- Tag validation rules pass: `@tdd_bug_988` has corresponding `@tdd_bug`, and `@tdd_expected_fail` has both
- `nox -s lint`  passes
- `nox -s typecheck`  passes (0 errors on changed files)

## Review fixes applied

- **C1 (Critical)**: Rebased onto latest `master` (`5f5ef891`) to eliminate unrelated `docs/timeline.md` regression that was overwriting Day 42 data with stale Day 39 content
- **m1**: Added docstrings to all four step functions
- **m2**: Renamed parameter `ctx` → `context` across all step functions to match project convention (97%+ of codebase uses `context`)
- **m3**: Added second scenario "Bug #988 — emit() logs traceback via exc_info when handler raises" with new `step_then_log_contains_traceback` step that verifies the `exc_info=True` requirement from bug #988 acceptance criteria
- **n1 (Informational)**: Feature-level tags are valid Gherkin; no change needed
- **n2 (Informational)**: `# type: ignore[import-untyped]` on behave imports is the established project convention (106+ files); no change needed

## Robot test

N/A — this is a purely unit-level concern (testing a single class's internal error handling, no external services or IPC involved).

Closes #1093

Reviewed-on: cleveragents/cleveragents-core#1106
Reviewed-by: Jeffrey Phillips Freeman <jeffrey.freeman@cleverthis.com>
Co-authored-by: Brent Edwards <brent.edwards@cleverthis.com>
Co-committed-by: Brent Edwards <brent.edwards@cleverthis.com>
2026-03-26 01:02:10 +00:00
..