Files
T
ArtyomandClaude Opus 5.5 9db7a24362 Propose load-balanced replicas and idempotent messages as an openspec change
Plan the grade 3 cycle of lab 3 on top of the carried-over lab 2
solution: run the API as several replicas of one compose service
behind HAProxy as the only published entry point, stamp every API
response with X-Instance-Id taken from the container hostname, require
Idempotency-Key on message posts and keep the key and the message in
one PostgreSQL transaction, and add explicit stop-one, restart and
restore hooks.

The design fixes the balancer settings and retry policy, the
idempotency table, the lookup order under the chat row lock, the
request fingerprint and the shutdown budget. Delta specs add the
lab3-load-balancing and lab3-idempotent-messages capabilities and
modify message posting, request identification, shutdown, container
delivery, migrations, restart and the reproducible stand.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-28 11:31:41 +03:00

44 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## MODIFIED Requirements
### Requirement: Отправка сообщения
Сервис SHALL принимать `POST /api/v1/chats/{chat_id}/messages` от участника чата с телом `{"text":...}` и обязательным заголовком `Idempotency-Key` и возвращать `201` с объектом `Message`. Отправитель SHALL выводиться из предъявленной идентификации; поле `sender_id` в теле запроса SHALL NOT приниматься. `text` SHALL содержать от 1 до 4000 Unicode code points и SHALL NOT состоять только из пробельных символов. `id` и `created_at` SHALL назначаться сервером. Правила ключа описаны в `lab3-idempotent-messages`.
#### Scenario: Сообщение отправлено
- **WHEN** участник отправляет `{"text":"Привет, мир 👋"}` в свой чат с новым `Idempotency-Key`
- **THEN** ответ `201`, тело соответствует схеме `Message`
- **AND** `sender_id` равен идентификатору вызывающего, `chat_id` равен чату из пути, `text` побайтово совпадает с отправленным
#### Scenario: Ключ не передан
- **WHEN** участник отправляет корректное тело без заголовка `Idempotency-Key`
- **THEN** ответ `400` с кодом `invalid_request`
#### Scenario: Отправитель не берётся из тела запроса
- **WHEN** тело запроса содержит поле `sender_id`
- **THEN** ответ `400` с кодом `invalid_request`
#### Scenario: Пустой или пробельный текст
- **WHEN** тело содержит `{"text":""}` или `{"text":" "}`
- **THEN** ответ `400` с кодом `invalid_request`
#### Scenario: Текст длиннее предела
- **WHEN** `text` содержит более 4000 Unicode code points
- **THEN** ответ `400` с кодом `invalid_request`
- **AND** длина считается в code points, а не в байтах UTF-8
#### Scenario: Посторонний пишет в чужой чат
- **WHEN** пользователь, не входящий в состав чата, отправляет корректное сообщение с ключом
- **THEN** ответ `404` с кодом `not_found`
- **AND** сообщение не сохраняется
#### Scenario: Доступ проверяется раньше содержимого
- **WHEN** посторонний отправляет в чужой чат с ключом тело с пустым `text`
- **THEN** ответ `404`, а не `400`