fix(app) backported some things agent broke in lab2 and bugfixed other autocheck issues manually
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -150,7 +150,6 @@ docker compose --env-file .env down -v # осознанно удалить
|
|||||||
|
|
||||||
- Один экземпляр API и один Redis, единые точки отказа хранилищ
|
- Один экземпляр API и один Redis, единые точки отказа хранилищ
|
||||||
- AOF с `appendfsync everysec`: при аварийном убийстве процесса возможна потеря до ~1 секунды последних операций с сессиями. Graceful-перезапуск, который использует `scripts/restart.sh`, проходит без потерь.
|
- AOF с `appendfsync everysec`: при аварийном убийстве процесса возможна потеря до ~1 секунды последних операций с сессиями. Graceful-перезапуск, который использует `scripts/restart.sh`, проходит без потерь.
|
||||||
- Время сообщения хранится с точностью до секунды, поэтому сообщения одной секунды упорядочиваются по UUID. Это согласовано с контрактом: курсор — `(created_at, id)`, а при конкурентных вставках возможна перестановка внутри секунды; полной snapshot-изоляции между HTTP-запросами контракт не требует.
|
|
||||||
- Список `member_ids` в ответе чата упорядочен по UUID, а не по порядку запроса; состав участников от этого не меняется. Порядок чатов и сообщений, который важен контракту, соблюдается.
|
- Список `member_ids` в ответе чата упорядочен по UUID, а не по порядку запроса; состав участников от этого не меняется. Порядок чатов и сообщений, который важен контракту, соблюдается.
|
||||||
- Нагрузочный отчёт ограничен closed-loop клиентом и не является надёжным измерением ёмкости.
|
- Нагрузочный отчёт ограничен closed-loop клиентом и не является надёжным измерением ёмкости.
|
||||||
- В отчёте не раскрываются токены, пароли и содержимое `.env`; в `evidence/` сохранены только агрегаты и коды ответов.
|
- В отчёте не раскрываются токены, пароли и содержимое `.env`; в `evidence/` сохранены только агрегаты и коды ответов.
|
||||||
|
|||||||
@@ -13,5 +13,5 @@ func (t RFCFormTime) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NowUTC() RFCFormTime {
|
func NowUTC() RFCFormTime {
|
||||||
return RFCFormTime(time.Now().UTC().Truncate(time.Second))
|
return RFCFormTime(time.Now().UTC())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,10 +74,11 @@ func ValidateCreateUser(username, displayName string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidatePassword enforces the contract range in Unicode code points. The
|
|
||||||
// upper bound matters: bcrypt would silently truncate, which is why this
|
|
||||||
// project uses Argon2id instead.
|
|
||||||
func ValidatePassword(password string) string {
|
func ValidatePassword(password string) string {
|
||||||
|
if blank(password) {
|
||||||
|
return "password must not be empty or only whitespace"
|
||||||
|
}
|
||||||
|
|
||||||
if !strLenBetween(password, 12, 128) {
|
if !strLenBetween(password, 12, 128) {
|
||||||
return "password must be between 12 and 128 Unicode code points"
|
return "password must be between 12 and 128 Unicode code points"
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-17
@@ -8,40 +8,40 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id" validate:"required"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username" validate:"required"`
|
||||||
DisplayName string `json:"display_name"`
|
DisplayName string `json:"display_name" validate:"required"`
|
||||||
PasswordHash string `json:"-"`
|
PasswordHash string `json:"-"`
|
||||||
CreatedAt common.RFCFormTime `json:"created_at"`
|
CreatedAt common.RFCFormTime `json:"created_at" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) GetID() uuid.UUID { return u.ID }
|
func (u User) GetID() uuid.UUID { return u.ID }
|
||||||
func (u User) GetCreatedAt() time.Time { return time.Time(u.CreatedAt) }
|
func (u User) GetCreatedAt() time.Time { return time.Time(u.CreatedAt) }
|
||||||
|
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id" validate:"required"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title" validate:"required"`
|
||||||
MemberIDs []uuid.UUID `json:"member_ids"`
|
MemberIDs []uuid.UUID `json:"member_ids" validate:"required"`
|
||||||
CreatedAt common.RFCFormTime `json:"created_at"`
|
CreatedAt common.RFCFormTime `json:"created_at" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chat) GetID() uuid.UUID { return c.ID }
|
func (c Chat) GetID() uuid.UUID { return c.ID }
|
||||||
func (c Chat) GetCreatedAt() time.Time { return time.Time(c.CreatedAt) }
|
func (c Chat) GetCreatedAt() time.Time { return time.Time(c.CreatedAt) }
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id" validate:"required"`
|
||||||
ChatID uuid.UUID `json:"chat_id"`
|
ChatID uuid.UUID `json:"chat_id" validate:"required"`
|
||||||
SenderID uuid.UUID `json:"sender_id"`
|
SenderID uuid.UUID `json:"sender_id" validate:"required"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text" validate:"required"`
|
||||||
CreatedAt common.RFCFormTime `json:"created_at"`
|
CreatedAt common.RFCFormTime `json:"created_at" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Message) GetID() uuid.UUID { return m.ID }
|
func (m Message) GetID() uuid.UUID { return m.ID }
|
||||||
func (m Message) GetCreatedAt() time.Time { return time.Time(m.CreatedAt) }
|
func (m Message) GetCreatedAt() time.Time { return time.Time(m.CreatedAt) }
|
||||||
|
|
||||||
type Session struct {
|
type Session struct {
|
||||||
Token string `json:"token"`
|
Token string `json:"token" validate:"required"`
|
||||||
TokenType string `json:"token_type"`
|
TokenType string `json:"token_type" validate:"required"`
|
||||||
ExpiresAt common.RFCFormTime `json:"expires_at"`
|
ExpiresAt common.RFCFormTime `json:"expires_at" validate:"required"`
|
||||||
User User `json:"user"`
|
User User `json:"user" validate:"required"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (s *Store) Create(ctx context.Context, userID uuid.UUID) (string, time.Time
|
|||||||
return "", time.Time{}, fmt.Errorf("generate token: %w", err)
|
return "", time.Time{}, fmt.Errorf("generate token: %w", err)
|
||||||
}
|
}
|
||||||
token := base64.RawURLEncoding.EncodeToString(raw)
|
token := base64.RawURLEncoding.EncodeToString(raw)
|
||||||
expiresAt := time.Now().UTC().Truncate(time.Second).Add(s.ttl)
|
expiresAt := time.Now().UTC().Add(s.ttl)
|
||||||
|
|
||||||
opCtx, cancel := context.WithTimeout(ctx, s.timeout)
|
opCtx, cancel := context.WithTimeout(ctx, s.timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package store
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/common"
|
"gitflic.ru/project/bulla-max/mtusi2026lab2/internal/common"
|
||||||
@@ -346,7 +347,8 @@ func dbError(err error) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.Is(err, context.DeadlineExceeded) ||
|
var netErr net.Error
|
||||||
|
if errors.As(err, &netErr) || errors.Is(err, context.DeadlineExceeded) ||
|
||||||
errors.Is(err, context.Canceled) ||
|
errors.Is(err, context.Canceled) ||
|
||||||
pgconn.SafeToRetry(err) ||
|
pgconn.SafeToRetry(err) ||
|
||||||
errors.Is(err, pgx.ErrTxClosed) {
|
errors.Is(err, pgx.ErrTxClosed) {
|
||||||
|
|||||||
Reference in New Issue
Block a user