test(BA-4974): add component tests for session lifecycle management#9891
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new component test module to expand coverage of session lifecycle behavior through the SDK v2 client and manager REST handlers.
Changes:
- Introduces
tests/component/session/test_session_lifecycle.pywith additional session lifecycle tests (restart, status transit, rename, permissions, status history, destroy). - Adds a DB-seeded “regular user owned” session fixture to validate role/ownership constraints.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| class TestSessionRestart: | ||
| """Test session restart lifecycle.""" | ||
|
|
||
| async def test_restart_running_session( | ||
| self, | ||
| admin_registry: BackendAIClientRegistry, | ||
| session_seed: SessionSeedData, | ||
| ) -> None: | ||
| await admin_registry.session.restart( | ||
| session_seed.session_name, | ||
| RestartSessionRequest(), | ||
| ) | ||
| # After restart, session should still be accessible | ||
| result = await admin_registry.session.get_info(session_seed.session_name) | ||
| assert isinstance(result, GetSessionInfoResponse) | ||
|
|
||
| async def test_restart_terminated_session_fails( | ||
| self, | ||
| admin_registry: BackendAIClientRegistry, | ||
| terminated_session_seed: SessionSeedData, | ||
| ) -> None: | ||
| # Terminated sessions are stale and cannot be found for restart | ||
| with pytest.raises((NotFoundError, BackendAPIError)): | ||
| await admin_registry.session.restart( | ||
| terminated_session_seed.session_name, | ||
| RestartSessionRequest(), | ||
| ) | ||
|
|
||
| async def test_restart_nonexistent_session_returns_not_found( | ||
| self, | ||
| admin_registry: BackendAIClientRegistry, | ||
| ) -> None: | ||
| with pytest.raises(NotFoundError): | ||
| await admin_registry.session.restart( | ||
| "nonexistent-session-xyz-99999", | ||
| RestartSessionRequest(), | ||
| ) | ||
|
|
||
|
|
||
| class TestSessionStatusTransition: |
There was a problem hiding this comment.
PR description/test count appears out of sync with the file contents: this module defines 21 test_* functions (2 marked xfail), but the PR metadata says 17 tests (and the per-class table totals don’t match). Please update the PR description/test table (or adjust the tests) so reviewers and CI expectations stay aligned.
| """Destroying an already-terminated session succeeds (forced destroy is idempotent).""" | ||
| result = await admin_registry.session.destroy( | ||
| terminated_session_seed.session_name, | ||
| DestroySessionRequest(forced=True), | ||
| ) | ||
| assert result is not None |
There was a problem hiding this comment.
The assertions in this test are too weak to validate the intended behavior (idempotent forced destroy). Other session component tests assert the concrete response type/shape for destroy(). Consider asserting the returned value is a DestroySessionResponse (and/or checking expected fields) so regressions don’t slip through while still returning a non-None object.
| # Verify the session status changed | ||
| assert result is not None |
There was a problem hiding this comment.
The inline comment says “Verify the session status changed”, but the test only asserts the destroy call returned a non-None response. Either add an assertion that confirms the session is no longer accessible / has TERMINATED status (e.g., get_info raises NotFound or status_history behavior), or remove/adjust the comment to match what’s actually verified.
| # Verify the session status changed | |
| assert result is not None | |
| # Verify the session status changed and is no longer accessible | |
| assert result is not None | |
| with pytest.raises(NotFoundError): | |
| await user_registry.session.get_info( | |
| user_session_seed.session_name, | |
| ) |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e5e0229 to
f18c299
Compare
Add tests for session restart, status transitions, rename lifecycle, role-based permissions, status history, and destroy edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolves #9832 (BA-4974)
Summary
test_session_lifecycle.py(20 tests)test_session.py(10 tests added to existing file)user_session_seedandscheduling_controller_mockfixtures toconftest.pyTest Distribution
test_session_lifecycle.py— Lifecycle & Status Transitions (20 tests)TestSessionRestartTestSessionStatusTransitionTestSessionStatusHistorytest_session.py— CRUD & Permissions (10 tests added)TestSessionRenameTestSessionDestroyTestSessionPermissionsTest plan
pants lint tests/component/session/passespants check tests/component/session/passespants test tests/component/session/passes (all 5 test files)🤖 Generated with Claude Code