chore: carry over lab 1 solution into lab 2 skeleton

Copy the committed lab 1 sources as-is: src/, student-tests/, bench/,
Dockerfile, docker-compose.yml, pyproject.toml, uv.lock,
.python-version, config_example.toml, AGENTS.md, CLAUDE.md, .claude/,
openspec/, .graphifyignore and KNOWN_ISSUES.md. Lab 1 evidence stays
in the lab 1 repository.

Merge the new skeleton files with own sections: Makefile (lab 2
targets plus own run, docker, bench and common targets), .gitignore,
.dockerignore and .env.example. Rename the image to
mtusi-messenger:lab2 and point AGENTS.md at lab 2.

The application is still the in-memory lab 1 implementation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 22:11:46 +03:00
co-authored by Claude Opus 5.5
parent 65003b6119
commit 7b775a29a9
174 changed files with 19023 additions and 11 deletions
View File
+50
View File
@@ -0,0 +1,50 @@
import bisect
from uuid import UUID
from src.infra.memory import MemoryStore
from src.schemas import dataclasses
from src.utils.cursor import CursorKey
def _chat_key(chat: dataclasses.ChatFullDTO) -> CursorKey:
return (chat.created_at, chat.id)
async def insert_chat(
store: MemoryStore,
*,
chat: dataclasses.ChatFullDTO,
) -> dataclasses.ChatFullDTO:
"""Чат, его место в списках всех участников и пустая история — разом."""
store.chats[chat.id] = chat
for member_id in chat.member_ids:
bisect.insort(
store.chats_by_user.setdefault(member_id, []),
chat,
key=_chat_key,
)
store.messages_by_chat[chat.id] = []
return chat
async def get_chat(
store: MemoryStore,
*,
chat_id: UUID,
) -> dataclasses.ChatFullDTO | None:
return store.chats.get(chat_id)
async def get_user_chats_page(
store: MemoryStore,
*,
user_id: UUID,
after: CursorKey | None,
limit: int,
) -> list[dataclasses.ChatFullDTO]:
"""До `limit + 1` чатов пользователя строго после ключа `after`."""
chats = store.chats_by_user.get(user_id, [])
start = 0
if after is not None:
start = bisect.bisect_right(chats, after, key=_chat_key)
return chats[start : start + limit + 1]
+38
View File
@@ -0,0 +1,38 @@
import bisect
from uuid import UUID
from src.infra.memory import MemoryStore
from src.schemas import dataclasses
from src.utils.cursor import CursorKey
def _message_key(message: dataclasses.MessageFullDTO) -> CursorKey:
return (message.created_at, message.id)
async def insert_message(
store: MemoryStore,
*,
message: dataclasses.MessageFullDTO,
) -> dataclasses.MessageFullDTO:
bisect.insort(
store.messages_by_chat[message.chat_id],
message,
key=_message_key,
)
return message
async def get_chat_messages_page(
store: MemoryStore,
*,
chat_id: UUID,
after: CursorKey | None,
limit: int,
) -> list[dataclasses.MessageFullDTO]:
"""До `limit + 1` сообщений чата строго после ключа `after`."""
messages = store.messages_by_chat.get(chat_id, [])
start = 0
if after is not None:
start = bisect.bisect_right(messages, after, key=_message_key)
return messages[start : start + limit + 1]
+36
View File
@@ -0,0 +1,36 @@
from collections.abc import Iterable
from uuid import UUID
from src.infra.memory import MemoryStore
from src.schemas import dataclasses
async def insert_user(
store: MemoryStore,
*,
user: dataclasses.UserFullDTO,
) -> dataclasses.UserFullDTO | None:
"""Вставка с проверкой уникальности username; конфликт — None."""
if user.username in store.user_id_by_username:
return None
store.users[user.id] = user
store.user_id_by_username[user.username] = user.id
store.chats_by_user[user.id] = []
return user
async def get_user(
store: MemoryStore,
*,
user_id: UUID,
) -> dataclasses.UserFullDTO | None:
return store.users.get(user_id)
async def get_existing_user_ids(
store: MemoryStore,
*,
user_ids: Iterable[UUID],
) -> set[UUID]:
"""Те из переданных id, для которых пользователь существует."""
return {user_id for user_id in user_ids if user_id in store.users}