test(04-01): add comprehensive tests for UserContextManager
- Add TestUserContext: tests for UserContext dataclass (creation, to_dict, from_dict) - Add TestUserContextManager: tests for manager initialization and load - Add TestAtomicWrites: tests for atomic save with backup rotation - Add TestMultiUser: tests for multi-user isolation and convenience methods - Add tmp_users_root and user_context_manager fixtures to conftest.py - Export UserContext and UserContextManager from __init__.py Note: Implementation was already done in commit 9bd29a2 as part of 04-02 plan. This commit adds the tests that should have been part of 04-01 TDD workflow. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -90,3 +90,32 @@ def sample_state() -> SessionState:
|
||||
last_output_snapshot="Test output snapshot",
|
||||
display_name="Test Project Display Name"
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tmp_users_root(tmp_path: Path) -> Path:
|
||||
"""Temporary root for user context testing.
|
||||
|
||||
This ensures tests don't pollute the real ~/gsd-workspaces/.users directory.
|
||||
|
||||
Args:
|
||||
tmp_path: Pytest's built-in temporary directory fixture.
|
||||
|
||||
Returns:
|
||||
Path to a temporary .users directory.
|
||||
"""
|
||||
return tmp_path / "gsd-workspaces" / ".users"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def user_context_manager(tmp_users_root: Path) -> "UserContextManager":
|
||||
"""UserContextManager with temporary root for isolation.
|
||||
|
||||
Args:
|
||||
tmp_users_root: Fixture providing temporary user context root.
|
||||
|
||||
Returns:
|
||||
UserContextManager instance configured for testing.
|
||||
"""
|
||||
from gsd_openclaw.user_context import UserContextManager
|
||||
return UserContextManager("test-user", tmp_users_root)
|
||||
|
||||
Reference in New Issue
Block a user