Forward the lab 5 foundation while preserving lab 6 telemetry

Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files.

Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
This commit is contained in:
Artyom
2026-11-06 12:29:35 +03:00
parent dc9256baf9
commit 12db77133f
161 changed files with 11160 additions and 1467 deletions
+38 -2
View File
@@ -1,8 +1,11 @@
from uuid import uuid4
import time
from uuid import UUID, uuid4
from httpx import AsyncClient
from sqlalchemy import select
from conftest import actor, keyed, make_chat, register
from conftest import actor, keyed, make_chat, register, sql_connection
from messenger.messaging.infrastructure.postgres import ChatRow
async def test_outsider_gets_404_on_chat(client: AsyncClient) -> None:
@@ -82,3 +85,36 @@ async def test_403_is_never_used(client: AsyncClient) -> None:
]
for path in paths:
assert (await client.get(path, headers=actor(eve))).status_code != 403
async def test_request_shape_is_checked_before_access(client: AsyncClient) -> None:
alice = await register(client, "alice")
eve = await register(client, "eve")
chat = await make_chat(client, alice)
for chat_id in (chat["id"], uuid4()):
path = f"/api/v1/chats/{chat_id}/messages"
unkeyed = await client.post(path, json={"text": "чужое"}, headers=actor(eve))
extra = await client.post(path, json={"text": "x", "a": 1}, headers=keyed(eve))
assert unkeyed.status_code == extra.status_code == 400
assert unkeyed.json()["error"]["code"] == extra.json()["error"]["code"] == "invalid_request"
blank = await client.post(
f"/api/v1/chats/{chat['id']}/messages", json={"text": " "}, headers=keyed(eve)
)
assert blank.status_code == 404
async def test_outsider_does_not_wait_for_members_lock(client: AsyncClient) -> None:
alice = await register(client, "alice")
eve = await register(client, "eve")
chat = await make_chat(client, alice)
async with sql_connection() as holder:
await holder.execute(
select(ChatRow.id).where(ChatRow.id == UUID(chat["id"])).with_for_update()
)
started = time.perf_counter()
response = await client.post(
f"/api/v1/chats/{chat['id']}/messages", json={"text": "чужое"}, headers=keyed(eve)
)
elapsed = time.perf_counter() - started
assert response.status_code == 404
assert elapsed < 0.5