Fix prototype state user isolation

This commit is contained in:
Mikhail Putilovskij 2026-04-08 01:30:37 +03:00
parent 19c85db89a
commit fabedb105b
2 changed files with 7 additions and 2 deletions

View file

@ -44,7 +44,7 @@ class PrototypeStateStore:
if existing is not None: if existing is not None:
stored = existing.model_copy(update={"is_new": False}) stored = existing.model_copy(update={"is_new": False})
self._users[key] = stored self._users[key] = stored
return stored return stored.model_copy()
user = User( user = User(
user_id=f"usr-{platform}-{external_id}", user_id=f"usr-{platform}-{external_id}",
@ -55,7 +55,7 @@ class PrototypeStateStore:
is_new=True, is_new=True,
) )
self._users[key] = user self._users[key] = user
return user return user.model_copy()
async def get_settings(self, user_id: str) -> UserSettings: async def get_settings(self, user_id: str) -> UserSettings:
stored = self._settings.get(user_id, {}) stored = self._settings.get(user_id, {})

View file

@ -21,9 +21,14 @@ async def test_get_or_create_user_is_stable_per_surface_identity():
assert first.user_id == "usr-matrix-@alice:example.org" assert first.user_id == "usr-matrix-@alice:example.org"
assert first.is_new is True assert first.is_new is True
first.display_name = "Mallory"
first.is_new = False
assert second.user_id == first.user_id assert second.user_id == first.user_id
assert second.is_new is False assert second.is_new is False
assert second.display_name == "Alice" assert second.display_name == "Alice"
assert store._users["matrix:@alice:example.org"].display_name == "Alice"
assert store._users["matrix:@alice:example.org"].is_new is False assert store._users["matrix:@alice:example.org"].is_new is False