feat: add evidence, report.md

This commit is contained in:
2026-10-21 11:48:36 +03:00
parent 1d5c1e0cc6
commit a4b03c2a92
11 changed files with 694 additions and 30 deletions
+94
View File
@@ -0,0 +1,94 @@
#!/bin/sh
set -u
cd "$(dirname "$0")/.."
mkdir -p evidence
COMMIT="$(git rev-parse --short HEAD)$(git diff --quiet HEAD -- src prisma test compose.yaml Dockerfile || echo ' (dirty)')"
header() {
printf '# %s\n# date: %s\n# commit: %s\n\n' "$1" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$COMMIT"
}
run() {
echo "\$ $*"
"$@" 2>&1 || echo "EXIT CODE $?"
echo
}
started() {
docker inspect -f '{{.Name}} {{.State.Status}} started={{.State.StartedAt}}' $(docker compose ps -q postgres redis api)
}
echo 'container.txt'
{
header 'Стенд: сервисы, образы, volumes'
run docker compose ps -a --format 'table {{.Service}}\t{{.Image}}\t{{.Status}}'
run docker compose images
run docker volume ls --filter name=messenger-lab2
run docker compose exec -T postgres postgres --version
run docker compose exec -T redis redis-server --version
run docker compose exec -T redis sh -c 'redis-cli --no-auth-warning -a "$(cat /run/secrets/redis_password)" config get appendonly'
echo '## Повторный запуск миграций и сверка схемы Prisma с БД'
run docker compose run --rm migrate
run docker compose run --rm --no-deps migrate sh -c 'export DATABASE_URL="$(cat "$DATABASE_URL_FILE")"; npx prisma migrate diff --from-url "$DATABASE_URL" --to-schema-datamodel prisma/schema.prisma --exit-code'
run docker compose exec -T postgres psql -U messenger -d messenger -c 'SELECT migration_name, finished_at FROM _prisma_migrations ORDER BY started_at'
} > evidence/container.txt
echo 'tests.txt'
{
header 'Собственные e2e-тесты (PostgreSQL + Redis из compose.test.yaml)'
docker compose -f compose.test.yaml build -q tests
run docker compose -f compose.test.yaml run --rm tests npx jest --config ./test/jest-e2e.json --verbose
docker compose -f compose.test.yaml down >/dev/null 2>&1
} > evidence/tests.txt
echo 'smoke.txt'
{
header 'Публичные проверки'
run make check
run make test
} > evidence/smoke.txt
echo 'persistence.txt'
{
header 'make test-persistence: restart.sh перезапускает postgres, redis, api с сохранением volumes'
echo '## до'
started
echo
run make test-persistence ACTION_SCRIPT=scripts/restart.sh
echo '## после (started изменился у всех трёх контейнеров)'
started
} > evidence/persistence.txt
echo 'failures.txt'
{
header 'Отказы зависимостей и expiry на стенде'
echo '## 1. Redis остановлен: полный публичный smoke проходит через PostgreSQL'
run docker compose stop redis
run make test
run docker compose start redis
echo '## 2. PostgreSQL остановлен: ограниченный 503 без внутренних деталей'
run docker compose stop postgres
run python3 scripts/probe.py status GET /health/ready
run python3 scripts/probe.py status GET /api/v1/chats
run python3 scripts/probe.py status GET /api/v1/chats 'Bearer unknown-token'
run docker compose start postgres
run python3 scripts/probe.py ready
echo '## 3. Redis после рестарта пуст (без persistence), сессии берутся из PostgreSQL'
run docker compose restart redis
run make test
echo '## 4. Expiry: API пересоздан с SESSION_TTL_SECONDS=2'
SESSION_TTL_SECONDS=2 docker compose up -d --wait api >/dev/null 2>&1
run docker compose exec -T api printenv SESSION_TTL_SECONDS
run python3 scripts/probe.py expiry 2
docker compose up -d --wait api >/dev/null 2>&1
run python3 scripts/probe.py ready
} > evidence/failures.txt
echo 'explain.txt'
{
header 'EXPLAIN (ANALYZE, BUFFERS) истории: 10 000 сообщений в чате, 50 000 всего (транзакция с ROLLBACK)'
docker compose exec -T postgres psql -U messenger -d messenger < scripts/explain.sql 2>&1
} > evidence/explain.txt
echo 'done'
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/env python3
import base64
import json
import os
import sys
import time
import urllib.error
import urllib.request
import uuid
BASE = os.environ.get('BASE_URL', 'http://localhost:8080')
def call(method, path, body=None, headers=None):
data = json.dumps(body).encode() if body is not None else None
content_type = {'Content-Type': 'application/json'} if data else {}
request = urllib.request.Request(BASE + path, data=data, method=method, headers={**content_type, **(headers or {})})
try:
with urllib.request.urlopen(request, timeout=5) as response:
return response.status, json.loads(response.read() or b'null')
except urllib.error.HTTPError as error:
return error.code, json.loads(error.read() or b'null')
except OSError as error:
return 0, str(error)
def ready(timeout=90):
deadline = time.monotonic() + timeout
while time.monotonic() < deadline:
if call('GET', '/health/ready')[0] == 200:
print('ready')
return
time.sleep(0.5)
sys.exit('not ready within %ds' % timeout)
def status(method, path, authorization=None):
code, body = call(method, path, headers={'Authorization': authorization} if authorization else None)
print(method, path, '(%s)' % (authorization or 'anonymous'), '->', code, json.dumps(body, ensure_ascii=False))
def expiry(ttl):
username = 'expiry_' + uuid.uuid4().hex[:8]
password = 'Expiry-check-' + uuid.uuid4().hex
print('register ->', call('POST', '/api/v1/users', {'username': username, 'display_name': 'Expiry', 'password': password})[0])
credential = base64.b64encode((username + ':' + password).encode()).decode()
code, session = call('POST', '/api/v1/auth/sessions', headers={'Authorization': 'Basic ' + credential})
if code != 201:
sys.exit('login failed: %s %s' % (code, session))
print('login ->', code, 'expires_at:', session['expires_at'])
auth = {'Authorization': 'Bearer ' + session['token']}
print('GET /api/v1/users/me (fresh) ->', call('GET', '/api/v1/users/me', headers=auth)[0])
time.sleep(ttl + 1)
print('GET /api/v1/users/me (after %ds) ->' % (ttl + 1), call('GET', '/api/v1/users/me', headers=auth)[0])
if __name__ == '__main__':
command = sys.argv[1]
if command == 'ready':
ready()
elif command == 'status':
status(*sys.argv[2:5])
elif command == 'expiry':
expiry(int(sys.argv[2]))