chore: carry lab 3 over

- carry the lab 3 solution over from mtusi2026lab3-safronov
  (solution/bvt2301-safronov, ce89eba): src, migrations, student-tests,
  bench, openspec, .claude, infra/haproxy and infra/valkey, own scripts,
  Dockerfile, compose, pyproject and uv lock
- merge Makefile, .gitignore and .dockerignore (the lab 3 versions only
  add lines to the skeleton, which is the same in lab 4) and
  .env.example (lab 4 skeleton names listed in the header)
- rename the compose project to mtusi-lab4 and the image to :lab4 so
  the stand does not reuse the lab 3 containers and volumes
- update AGENTS.md for lab 4: current lab, origin commit, contract and
  test files of the new skeleton

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 17:32:33 +03:00
co-authored by Claude Opus 5.5
parent ec540a1a72
commit 5d5d8f9d2a
365 changed files with 64878 additions and 19 deletions
+78
View File
@@ -0,0 +1,78 @@
"""Спек `chat-cache`: что видно по HTTP при кэше карточки чата.
Попадание в кэш, срок записи и отказ Valkey по HTTP не различить: это
исключения в `spec_coverage.py` с evidence.
"""
from typing import Any
import pytest
from api_client import API, Actor, Api
from contract import assert_error, assert_ok
@pytest.mark.spec("chat-cache", "Повторное чтение чата")
def test_repeated_reads_match_creation(
api: Api,
alice: Actor,
bob: Actor,
eve: Actor,
) -> None:
# порядок участников не совпадает ни с сортировкой, ни с порядком
# регистрации: кэш обязан сохранить его как есть
created = api.create_chat(bob, eve, alice, title="Кэш «карточки»")
path = f"{API}/chats/{created['id']}"
first = assert_ok(api.request("GET", path, actor=alice), 200, "Chat")
second = assert_ok(api.request("GET", path, actor=eve), 200, "Chat")
assert first == second == created
assert first["member_ids"] == [bob.id, eve.id, alice.id]
@pytest.mark.spec("chat-cache", "Проверка членства по карточке")
def test_membership_from_new_chat(
api: Api,
alice: Actor,
bob: Actor,
eve: Actor,
) -> None:
chat = api.create_chat(alice, bob)
api.send_message(bob, chat["id"], "сразу после создания")
path = f"{API}/chats/{chat['id']}"
assert_error(api.request("GET", path, actor=eve), 404)
assert_error(
api.post_message(eve, chat["id"], json={"text": "посторонний"}),
404,
)
@pytest.mark.spec("chat-cache", "Сообщение видно сразу")
def test_message_visible_at_once(
api: Api,
alice: Actor,
bob: Actor,
chat: dict[str, Any],
) -> None:
# история уже прочитана: если бы она кэшировалась, второе чтение
# отдало бы старую страницу
assert api.all_messages(bob, chat["id"]) == []
message = api.send_message(alice, chat["id"], "видно сразу")
assert api.all_messages(bob, chat["id"]) == [message]
@pytest.mark.spec("chat-cache", "Новый чат в списке")
def test_new_chat_listed_at_once(
api: Api,
alice: Actor,
bob: Actor,
chat: dict[str, Any],
) -> None:
listed = [
item["id"] for page in api.chat_pages(bob) for item in page["items"]
]
assert listed == [chat["id"]]
second = api.create_chat(alice, bob, title="Второй")
listed = [
item["id"] for page in api.chat_pages(bob) for item in page["items"]
]
assert listed == [chat["id"], second["id"]]