test: add TDD bug-capture test for #987 — AutomationProfileRepository session leak #1104

Merged
brent.edwards merged 2 commits from tdd/m5-automation-profile-session-leak into master 2026-03-27 22:22:18 +00:00

2 Commits

Author SHA1 Message Date
brent.edwards 69e2d1f179 test(tdd): add required issue tags for expected-fail session leak test
CI / benchmark-publish (pull_request) Has been skipped
CI / typecheck (pull_request) Successful in 57s
CI / build (pull_request) Successful in 20s
CI / lint (pull_request) Successful in 3m20s
CI / security (pull_request) Successful in 4m11s
CI / quality (pull_request) Successful in 3m40s
CI / integration_tests (pull_request) Successful in 9m36s
CI / unit_tests (pull_request) Successful in 9m52s
CI / docker (pull_request) Successful in 1m9s
CI / coverage (pull_request) Successful in 12m32s
CI / status-check (pull_request) Successful in 1s
CI / e2e_tests (pull_request) Successful in 14m5s
CI / build (push) Successful in 22s
CI / lint (push) Successful in 3m21s
CI / quality (push) Successful in 3m41s
CI / typecheck (push) Successful in 3m57s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m15s
CI / integration_tests (push) Successful in 6m53s
CI / unit_tests (push) Successful in 7m22s
CI / docker (push) Successful in 1m9s
CI / e2e_tests (push) Successful in 11m52s
CI / coverage (push) Successful in 11m22s
CI / status-check (push) Successful in 1s
CI / benchmark-publish (push) Successful in 32m53s
CI / benchmark-regression (pull_request) Successful in 58m33s
Use @tdd_issue and @tdd_issue_987 so the TDD tag validation hook accepts this expected-fail bug-capture feature and unit tests can execute normally.
2026-03-27 22:01:03 +00:00
brent.edwards a5888a08b7 test: add TDD bug-capture test for #987 — AutomationProfileRepository session leak
Add a Behave feature with four scenarios that capture the session leak
bug in AutomationProfileRepository.  The upsert() and delete() methods
commit when auto_commit is True but never call session.close() in a
finally block, leaking database sessions.  SessionRepository correctly
uses finally: if self._auto_commit: db_session.close() in every method
— AutomationProfileRepository does not.

The test uses a _TrackingSession subclass of sqlalchemy.orm.Session that
records whether close() was called, providing direct assertion of the bug.
Four scenarios cover: (1) upsert success path, (2) delete success path,
(3) upsert error path, (4) delete error path.  All scenarios are tagged
@tdd_expected_fail @tdd_bug @tdd_bug_987 so CI passes while the bug
remains unfixed.

Fixes from review:
- M1: Added 4th scenario for delete() error path
- M2: Registered engine.dispose() in _cleanup_handlers for all scenarios
- M3: Registered session.close() in _cleanup_handlers; explicitly close
  setup session in step_given_persisted_profile
- M4: Replaced type: ignore annotations with proper subclass pattern
  (_TrackingSession uses **kwargs: Any; _FailingFlushTrackingSession
  overrides flush() instead of monkey-patching)
- M5: Moved OperationalError import from function body to module level

Robot integration tests are N/A — this is purely a unit-level session
lifecycle bug within a single repository class.

ISSUES CLOSED: #1092
2026-03-27 22:01:03 +00:00