docs: complete lab 4 report and add the application CI job
- fill the skeleton sections of REPORT.md: author and target grade,
launch from a clean clone, architecture and variable mapping, open
questions to the teacher, limitations, sources and AI use
- add evidence/tests/clean-clone-final.md: clean clone of de98d77
- add .github/workflows/application.yml (CONTRIBUTING.md, CI) and the
.github/ci/ override for the Gitea runner: configs instead of bind
mounts, no host ports; evidence/tests/ci-application.md
- remove PLAN.md now that all changes are archived; point AGENTS.md
and the rules at REPORT.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
# CI job `application`: сборка, стенд и проверки в раннере Gitea
|
||||
|
||||
Свой job по `CONTRIBUTING.md`, «CI»: `.github/workflows/application.yml`
|
||||
(workflow skeleton `contracts.yml` не менялся), override стенда
|
||||
`.github/ci/compose.yml` и окружение шагов `.github/ci/stand-env.sh`.
|
||||
Устройство — `REPORT.md`, раздел «CI» в «Запуск из чистого clone».
|
||||
|
||||
## Раннер
|
||||
|
||||
Раннеры Gitea fork — `runner-1` и `runner-2`, `act_runner` v0.2.13,
|
||||
метки `ubuntu-latest`, `ubuntu-22.04`, `ubuntu-24.04` (настройки fork →
|
||||
Actions → Раннеры, 2026-10-29). По журналу публичного прогона на этом же
|
||||
Gitea: job — контейнер образа `gitea/runner-images:ubuntu-latest`
|
||||
(linux/amd64) в своей сети, сокет Docker хоста раннера ему доступен,
|
||||
стенд compose поднимается соседними контейнерами. Отсюда два ограничения,
|
||||
которые снимает override:
|
||||
|
||||
- bind mount файла рабочего каталога (`./config.toml`,
|
||||
`./infra/haproxy/haproxy.cfg` и др.) Docker ищет на хосте раннера, а
|
||||
файлы есть только в контейнере job: `bind source path does not exist`;
|
||||
- порт стенда на `127.0.0.1` хоста раннера из контейнера job не виден и
|
||||
на общем хосте может быть занят.
|
||||
|
||||
Инструменты образа раннера (`docker run --rm
|
||||
gitea/runner-images:ubuntu-latest …`, index
|
||||
`sha256:2992a8a0448aba1c093255787390b2a090fefbfd76cc25db107f527e9bd65d3a`):
|
||||
|
||||
```text
|
||||
PRETTY_NAME="Ubuntu 24.04.5 LTS"
|
||||
Docker version 29.9.2, build a82e528
|
||||
Docker Compose version v5.6.1
|
||||
Python 3.12.3
|
||||
GNU Make 4.3
|
||||
curl 8.5.0
|
||||
OpenSSL 3.0.13 30 Jan 2024
|
||||
git version 2.56.0
|
||||
```
|
||||
|
||||
## Почему конфиги копируются с переводом строки в конце
|
||||
|
||||
`$(cat файл)` срезает последний перевод строки; `stand-env.sh` его
|
||||
возвращает. Без него HAProxy закреплённого образа конфиг не принимает:
|
||||
|
||||
```text
|
||||
$ haproxy -c -f /c.cfg # infra/haproxy/haproxy.cfg без последнего \n
|
||||
[ALERT] (1) : config : parsing [/c.cfg:163]: Missing LF on last line, file might have been truncated at position 23.
|
||||
[ALERT] (1) : config : Error(s) found in configuration file : /c.cfg
|
||||
[ALERT] (1) : config : Fatal errors found in configuration.
|
||||
```
|
||||
|
||||
С исходным файлом та же команда проходит без вывода.
|
||||
|
||||
## Локальный прогон шагов workflow в схеме раннера
|
||||
|
||||
2026-10-29, 18:06–18:09 MSK. Хост: Docker Desktop 29.9.2 (ВМ
|
||||
linux/arm64, 12 CPU, 7,7 GiB), macOS, Apple M3 Pro. Код — рабочее
|
||||
дерево поверх `de98d77`: файлы будущего commit с job (`git ls-files -co
|
||||
--exclude-standard`; `.env` и `config.toml` в них не входят).
|
||||
|
||||
Схема та же, что у раннера: контейнер `gitea/runner-images:ubuntu-latest`
|
||||
в своей сети, сокет Docker хоста смонтирован, файлы репозитория
|
||||
скопированы внутрь архивом (не смонтированы). Шаги — блоки `run`
|
||||
`application.yml` как есть, `bash --noprofile --norc -e -o pipefail`, в
|
||||
порядке файла, с `if: failure()` и `if: always()`. `${{ github.run_id
|
||||
}}` — `sim1`. Шаг Checkout пропущен: файлы уже скопированы, а commit на
|
||||
Gitea ещё не опубликован. Сам checkout проверен отдельно в том же образе
|
||||
на `main` fork: `git fetch --depth=1 origin
|
||||
ec540a1a725862a8619fcb758daec4ad197f0dd5` по https без токена, `git
|
||||
checkout --detach FETCH_HEAD`, исполняемые биты `scripts/*.sh`
|
||||
сохранились.
|
||||
|
||||
| Шаг | Код | с | Итог |
|
||||
|---|---|---|---|
|
||||
| Runner | 0 | 0 | `docker 29.9.2, linux/aarch64, 12 CPU`, Compose v5.6.1, Python 3.12.3 |
|
||||
| Remove stands of interrupted runs | 0 | 0 | хвостов нет |
|
||||
| Build and start the stand | 0 | 14 | `new .env with random …` (только имена); образ `mtusi-messenger:safronov-ci-sim1`; проект `mtusi-lab4-safronov-ci-sim1`; `LB ready: 0d9ec34300c1 dd41a7e8f7f9` |
|
||||
| make check and make test | 0 | 1 | оба `PASS` |
|
||||
| Bucket is closed to anonymous requests | 0 | 0 | три анонимных GET — 403 |
|
||||
| Install uv | 0 | 6 | uv 0.12.17 в venv `$RUNNER_TEMP/uv` |
|
||||
| make student_test | 0 | 62 | `198 passed, 56 deselected in 52.62s` |
|
||||
| make test-persistence | 0 | 32 | `PASS`, затем обе реплики в LB |
|
||||
| make test-failover, stop and kill | 0 | 39 | 2 × `PASS`, `failed_attempts` 0 |
|
||||
| Stand logs | — | — | пропущен (`failure()`) |
|
||||
| Remove the stand | 0 | 16 | контейнеры, сеть, volumes `…_postgres_data` и `…_s3_data` удалены |
|
||||
|
||||
Сборка шла из кэша BuildKit хоста; на раннере первая сборка дольше
|
||||
(зависимости по `uv.lock` скачиваются заново).
|
||||
|
||||
Стенд после старта (`docker compose ps -a`): сервисы рабочего стенда,
|
||||
конфиги HAProxy, Valkey, bootstrap S3 и `config.toml` — из `configs`, не
|
||||
из bind mount.
|
||||
|
||||
```text
|
||||
SERVICE STATUS
|
||||
api Up 3 seconds (healthy)
|
||||
api Up 3 seconds (healthy)
|
||||
cleaner Up 3 seconds
|
||||
haproxy Up 3 seconds (healthy)
|
||||
migrate Exited (0) 6 seconds ago
|
||||
postgres Up 11 seconds (healthy)
|
||||
s3 Up 11 seconds (healthy)
|
||||
s3-bootstrap Exited (0) 3 seconds ago
|
||||
valkey Up 11 seconds (healthy)
|
||||
```
|
||||
|
||||
`make check`, `make test` (через `http://haproxy:8080` в сети стенда):
|
||||
|
||||
```text
|
||||
python3 scripts/check_contract.py
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
python3 tests/smoke.py --base-url "http://haproxy:8080"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
```
|
||||
|
||||
Аноним без подписи:
|
||||
|
||||
```text
|
||||
anonymous GET http://s3:8333/ -> 403
|
||||
anonymous GET http://s3:8333/messenger -> 403
|
||||
anonymous GET http://s3:8333/messenger?list-type=2 -> 403
|
||||
```
|
||||
|
||||
`make student_test` (`BASE_URL=http://haproxy:8080 EXPECT_REPLICAS=2 uv
|
||||
run pytest`, CPython 3.12.3 образа, 102 пакета по `uv.lock`): тесты реплик
|
||||
выполнены, а не пропущены — `test_download_through_other_replica`,
|
||||
`test_replay_on_other_replica`, `test_one_session_on_several_replicas`,
|
||||
`test_write_visible_through_other_replica`,
|
||||
`test_same_key_through_replicas` — `PASSED`.
|
||||
|
||||
```text
|
||||
coverage: 252 scenarios in 13 specs, 235 tested (70 by make failure_checks), 17 excluded
|
||||
===================== 198 passed, 56 deselected in 52.62s ======================
|
||||
```
|
||||
|
||||
`make test-persistence ACTION_SCRIPT=scripts/restart.sh` — hook
|
||||
перезапускает LB, реплики, PostgreSQL, Valkey и S3 этого проекта
|
||||
(`COMPOSE_PROJECT_NAME`, `COMPOSE_FILE` из окружения job):
|
||||
|
||||
```text
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
LB ready: 0d9ec34300c1 dd41a7e8f7f9
|
||||
```
|
||||
|
||||
`make test-failover ACTION_SCRIPT=scripts/stop-one.sh`, затем `make
|
||||
replicas`, затем то же со `STOP_MODE=kill`:
|
||||
|
||||
```text
|
||||
{"observed_instances_before": 2, "successful_writes": 121, "failed_attempts": 0, "first_recovery_seconds": 1.804}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
{"observed_instances_before": 2, "successful_writes": 125, "failed_attempts": 0, "first_recovery_seconds": 0.858}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
2026-10-29T15:08:18Z TARGET_INSTANCE_ID=dd41a7e8f7f9 container=dd41a7e8f7f9957ba930c4a5d5d1a28eef38f90cdc63e1ff682443d4633c95d7 mode=stop
|
||||
2026-10-29T15:08:37Z TARGET_INSTANCE_ID=dd41a7e8f7f9 container=dd41a7e8f7f9957ba930c4a5d5d1a28eef38f90cdc63e1ff682443d4633c95d7 mode=kill
|
||||
```
|
||||
|
||||
Тест останавливает реплику, ответившую на его первую отправку: оба раза
|
||||
это `dd41a7e8f7f9`, в режимах `stop` и `kill`. Отказ каждой реплики по
|
||||
очереди — `evidence/failover/test-failover.md` и
|
||||
`evidence/tests/clean-clone-final.md`.
|
||||
|
||||
После прогона на хосте нет ни контейнеров, ни volumes, ни сетей, ни
|
||||
образа прогона (`docker ps -a`, `docker volume ls`, `docker network ls`,
|
||||
`docker image ls` по `safronov-ci` — пусто).
|
||||
|
||||
## Шаг уборки хвостов трогает только свои проекты
|
||||
|
||||
Контейнер, volume и сеть с меткой проекта
|
||||
`mtusi-lab4-safronov-ci-zz9` и контейнер проекта `mtusi-lab4-other`;
|
||||
блок `run` шага «Remove stands of interrupted runs» в контейнере образа
|
||||
раннера с сокетом Docker:
|
||||
|
||||
```text
|
||||
remove leftover stand mtusi-lab4-safronov-ci-zz9
|
||||
step exit=0
|
||||
```
|
||||
|
||||
После него остался только контейнер `mtusi-lab4-other`; контейнер,
|
||||
volume и сеть проекта `…-ci-zz9` удалены.
|
||||
@@ -0,0 +1,336 @@
|
||||
# Итоговая проверка из чистого clone: стенд с LB, S3 и уборщиком
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Что проверялось | раздел `REPORT.md` «Запуск из чистого clone»: шаг за шагом, как у проверяющего |
|
||||
| Дата | 2026-10-29 12:46–13:04 UTC |
|
||||
| Commit | `de98d77` — `git clone --branch solution/bvt2301-safronov` локального репозитория во временный каталог. Рабочее дерево клона чистое, `.env`, `config.toml` и `.venv` нет. Это итоговый код всех changes лабы 4: последний commit кода — `ca0c4b2` (правки по verify `track2-reconcile-cost`), после него — только документы |
|
||||
| Стенд | временный проект compose `mtusi-lab4-cleancheck`, LB на `127.0.0.1:8090`, остальные порты по умолчанию: PostgreSQL 5433, Valkey 6380, S3 8334, `make test_isolated` 18088. Клон стартовал на пустых volumes PostgreSQL и S3 со своими секретами, как у проверяющего. Рабочий стенд `mtusi-lab4` остановлен и не тронут. После проверки стенд клона удалён (`docker compose down -v`), volumes `mtusi-lab4_postgres_data` и `mtusi-lab4_s3_data` на месте |
|
||||
| Хост | Docker Desktop 29.9.2, Compose 5.6.1, macOS 26.7.1, Apple M3 Pro, 18 ГиБ; ВМ Docker — 12 CPU, 7,7 GiB, ядро 7.0.14-linuxkit, aarch64; `python3` на `PATH` — 3.11.9, uv 0.12.17 (виртуальное окружение — CPython 3.12.12). Порт 8080 хоста занят посторонним контейнером. Это проверка, а не замер |
|
||||
|
||||
**Отличие от последовательности проверяющего — две строки `.env`.**
|
||||
Порт 8080 на хосте занят посторонним контейнером, а рабочий стенд с
|
||||
тем же именем проекта трогать нельзя. Поэтому до `make env_setup` в клон
|
||||
записан `.env` из двух строк: `COMPOSE_PROJECT_NAME=mtusi-lab4-cleancheck`
|
||||
и `APP_OUT_PORT=8090`. Это штатный способ из раздела «Нужно на машине».
|
||||
Остальные переменные, в том числе все секреты, дописал `make env_setup`
|
||||
из `.env.example`: этот путь проходит проверяющий со старым `.env`.
|
||||
Цели `Makefile`, `scripts/restart.sh`, `scripts/stop-one.sh`,
|
||||
`run_failures.py`, `run_isolated.py` и драйвер берут проект и порт у
|
||||
`docker compose` и из `.env`, поэтому шаги те же. Отличие одно:
|
||||
`BASE_URL=http://localhost:8090` у `make test`, `make test-persistence`,
|
||||
`make test-failover` и `make student_test`, а у драйвера — `--port
|
||||
8090`.
|
||||
|
||||
Значения секретов не выводились. Поиск всех десяти значений из `.env`
|
||||
клона по полному журналу проверки — 0 совпадений.
|
||||
|
||||
Все шаги ниже завершились с кодом 0. Длительности — из журнала, `exit` —
|
||||
код команды.
|
||||
|
||||
## Подготовка и запуск
|
||||
|
||||
```text
|
||||
$ git clone --branch solution/bvt2301-safronov <репозиторий> clean-clone && cd clean-clone
|
||||
$ git log --oneline -1; git status --short | wc -l; ls .env config.toml .venv
|
||||
de98d77 docs: archive track2-reconcile-cost and sync its specs
|
||||
0
|
||||
ls: .env: No such file or directory
|
||||
ls: .venv: No such file or directory
|
||||
ls: config.toml: No such file or directory
|
||||
|
||||
$ grep -v '^#' .env # записан до env_setup: комментарий и две строки, см. выше
|
||||
COMPOSE_PROJECT_NAME=mtusi-lab4-cleancheck
|
||||
APP_OUT_PORT=8090
|
||||
$ make env_setup
|
||||
added to existing .env: APP__PORT API_REPLICAS POSTGRES_USER POSTGRES_PASSWORD POSTGRES_DB POSTGRES_HOST POSTGRES_PORT POSTGRES_OUT_PORT DATABASE__HOST DATABASE__PORT DATABASE__USER DATABASE__PASSWORD DATABASE__NAME VALKEY_PASSWORD VALKEY_HOST VALKEY_PORT VALKEY_OUT_PORT CACHE__HOST CACHE__PORT CACHE__PASSWORD S3__BUCKET S3_ROOT_ACCESS_KEY S3_ROOT_SECRET_KEY S3_JWT_SIGNING_KEY S3_API_ACCESS_KEY S3_API_SECRET_KEY S3_CLEANER_ACCESS_KEY S3_CLEANER_SECRET_KEY S3_HOST S3_PORT S3_OUT_PORT S3__HOST S3__PORT S3__ACCESS_KEY_ID S3__SECRET_ACCESS_KEY TEST_APP_PORT
|
||||
env ready: .env, config.toml
|
||||
$ grep -c -E '^(POSTGRES|VALKEY)_PASSWORD=.{32}$' .env # случайные пароли
|
||||
2
|
||||
$ docker compose config | sed -n 's/^name: //p'
|
||||
mtusi-lab4-cleancheck
|
||||
|
||||
$ make run_docker # exit 0, 11 с (слои — из кэша BuildKit)
|
||||
Image mtusi-messenger:lab4 Built
|
||||
Volume mtusi-lab4-cleancheck_postgres_data Created
|
||||
Volume mtusi-lab4-cleancheck_s3_data Created
|
||||
Container mtusi-lab4-cleancheck-migrate-1 Exited
|
||||
Container mtusi-lab4-cleancheck-s3-bootstrap-1 Exited
|
||||
$ make replicas # exit 0, 3 с: ожидание healthy
|
||||
$ docker compose ps -a --format 'table {{.Name}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}'
|
||||
NAME IMAGE STATUS PORTS
|
||||
mtusi-lab4-cleancheck-api-1 mtusi-messenger:lab4 Up 2 seconds (healthy) 8080/tcp
|
||||
mtusi-lab4-cleancheck-api-2 mtusi-messenger:lab4 Up 3 seconds (healthy) 8080/tcp
|
||||
mtusi-lab4-cleancheck-cleaner-1 mtusi-messenger:lab4 Up 2 seconds 8080/tcp
|
||||
mtusi-lab4-cleancheck-haproxy-1 haproxy:3.4.6-trixie@sha256:e273… Up 2 seconds (health: starting) 127.0.0.1:8090->8080/tcp
|
||||
mtusi-lab4-cleancheck-migrate-1 mtusi-messenger:lab4 Exited (0) 7 seconds ago
|
||||
mtusi-lab4-cleancheck-postgres-1 postgres:18.6-trixie@sha256:5a5a… Up 10 seconds (healthy) 127.0.0.1:5433->5432/tcp
|
||||
mtusi-lab4-cleancheck-s3-1 chrislusf/seaweedfs:4.48@sha256:4e61… Up 11 seconds (healthy) 127.0.0.1:8334->8333/tcp
|
||||
mtusi-lab4-cleancheck-s3-bootstrap-1 chrislusf/seaweedfs:4.48@sha256:4e61… Exited (0) 3 seconds ago
|
||||
mtusi-lab4-cleancheck-valkey-1 valkey/valkey:9.1.2-trixie@sha256:4186… Up 10 seconds (healthy) 127.0.0.1:6380->6379/tcp
|
||||
```
|
||||
|
||||
Digest в выводе сокращён, полностью он в `docker-compose.yml`. `8080/tcp`
|
||||
у реплик и уборщика — `EXPOSE` образа: опубликованного порта у них нет,
|
||||
API на хосте — только через HAProxy. Уборщик HTTP не слушает.
|
||||
|
||||
```text
|
||||
$ docker compose logs migrate --no-log-prefix | <поле event>
|
||||
Running upgrade -> 16c279725564, added messenger tables
|
||||
Running upgrade 16c279725564 -> 42bc3b9be38f, added sessions and password hashes
|
||||
Running upgrade 42bc3b9be38f -> 7652184b7016, added idempotency keys
|
||||
Running upgrade 7652184b7016 -> e656d6bbe1a4, added message instance id
|
||||
Running upgrade e656d6bbe1a4 -> ef25d50b01a8, added attachments tables
|
||||
Running upgrade ef25d50b01a8 -> 739b8f04d5fb, added pending attachments index
|
||||
Running upgrade 739b8f04d5fb -> 5c3e1f0a9b7d, added attachments lost_at
|
||||
Finished alembic
|
||||
|
||||
$ docker compose logs s3-bootstrap --no-log-prefix
|
||||
s3-bootstrap: bucket messenger created
|
||||
s3-bootstrap: user api created
|
||||
s3-bootstrap: user cleaner created
|
||||
s3-bootstrap: checks passed (api key put/get; cleaner key get/delete and list messenger/attachments/; api key list and bucket create, cleaner key put and list of the bucket, anonymous get and list denied)
|
||||
|
||||
$ curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8090/health/ready
|
||||
200
|
||||
```
|
||||
|
||||
## Публичные проверки skeleton
|
||||
|
||||
```text
|
||||
$ make check
|
||||
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
|
||||
|
||||
$ uv sync && make validate PYTHON=.venv/bin/python # exit 0
|
||||
Installed 102 packages in 169ms
|
||||
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
|
||||
|
||||
$ make test BASE_URL=http://localhost:8090
|
||||
python3 tests/smoke.py --base-url "http://localhost:8090"
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
|
||||
$ make instances
|
||||
user lb_cdce70f9: one login, 12 requests with one token
|
||||
91fbe934191d: 6
|
||||
94a968393dd6: 6
|
||||
instances: 2
|
||||
|
||||
$ make test-persistence ACTION_SCRIPT=scripts/restart.sh BASE_URL=http://localhost:8090 # 29 с
|
||||
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
|
||||
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
$ docker compose ps -a --format '{{.Name}} {{.Status}}' # сразу после hook
|
||||
mtusi-lab4-cleancheck-api-1 Up 1 second (healthy)
|
||||
mtusi-lab4-cleancheck-api-2 Up 1 second (healthy)
|
||||
mtusi-lab4-cleancheck-cleaner-1 Up 38 seconds
|
||||
mtusi-lab4-cleancheck-haproxy-1 Up 1 second (healthy)
|
||||
mtusi-lab4-cleancheck-migrate-1 Exited (0) 2 seconds ago
|
||||
mtusi-lab4-cleancheck-postgres-1 Up 27 seconds (healthy)
|
||||
mtusi-lab4-cleancheck-s3-1 Up 12 seconds (healthy)
|
||||
mtusi-lab4-cleancheck-s3-bootstrap-1 Exited (0) 1 second ago
|
||||
mtusi-lab4-cleancheck-valkey-1 Up 27 seconds (healthy)
|
||||
```
|
||||
|
||||
Hook перезапустил LB, обе реплики, PostgreSQL, Valkey и S3: у них время
|
||||
работы меньше длительности hook. Уборщик hook не трогает (он переживает
|
||||
рестарт хранилищ сам) — `Up 38 seconds` со старта стенда. `migrate` и
|
||||
`s3-bootstrap` прошли повторно при старте реплик (no-op).
|
||||
|
||||
```text
|
||||
$ STOP_ONE_LOG=<файл> make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=http://localhost:8090 # 16 с
|
||||
{"observed_instances_before": 2, "successful_writes": 121, "failed_attempts": 0, "first_recovery_seconds": 1.08}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
$ cat <файл>; docker compose ps -a --format '{{.Name}} {{.Status}}' | grep api
|
||||
2026-10-29T12:46:50Z TARGET_INSTANCE_ID=91fbe934191d container=91fbe934191d1d08cd0b04dc85f5e0fbe67da16bdbcfd9e96321e021e217c08b mode=stop
|
||||
mtusi-lab4-cleancheck-api-1 Up 17 seconds (healthy)
|
||||
mtusi-lab4-cleancheck-api-2 Exited (0) 14 seconds ago
|
||||
|
||||
$ make replicas; curl -s -o /dev/null -w '%{http_code}\n' http://localhost:8090/health/live
|
||||
200
|
||||
$ STOP_ONE_LOG=<файл> make test-failover ACTION_SCRIPT=scripts/stop-one.sh BASE_URL=http://localhost:8090 # 16 с
|
||||
{"observed_instances_before": 2, "successful_writes": 116, "failed_attempts": 0, "first_recovery_seconds": 1.201}
|
||||
PASS: failover preserved confirmed data and existing session. Hook scope needs operator evidence.
|
||||
$ cat <файл>; docker compose ps -a --format '{{.Name}} {{.Status}}' | grep api
|
||||
2026-10-29T12:46:50Z TARGET_INSTANCE_ID=91fbe934191d container=91fbe934191d1d08cd0b04dc85f5e0fbe67da16bdbcfd9e96321e021e217c08b mode=stop
|
||||
2026-10-29T12:47:08Z TARGET_INSTANCE_ID=94a968393dd6 container=94a968393dd656fe53a6700f0d43221ac8d8ea8c3252fd0a377dc2a81d111417 mode=stop
|
||||
mtusi-lab4-cleancheck-api-1 Exited (0) 14 seconds ago
|
||||
mtusi-lab4-cleancheck-api-2 Up 17 seconds (healthy)
|
||||
$ make replicas
|
||||
```
|
||||
|
||||
Остановлены обе реплики по очереди: ID контейнера в строке
|
||||
`STOP_ONE_LOG` равен `TARGET_INSTANCE_ID`, выбранному тестом, и
|
||||
остановлен именно он (`Exited (0)`).
|
||||
|
||||
## Приватность bucket и вложения
|
||||
|
||||
```text
|
||||
$ make s3_check # 3 с
|
||||
S3 s3:8333 (host 127.0.0.1:8334), bucket messenger, image chrislusf/seaweedfs:4.48
|
||||
where check expected got verdict
|
||||
server anonymous access setting none none ok
|
||||
server api key put object 200 200 ok
|
||||
server api key get object 200 200 ok
|
||||
server api key head object 200 200 ok
|
||||
server api key get missing object 404 404 ok
|
||||
server api key list objects 403 403 ok
|
||||
server api key create bucket 403 403 ok
|
||||
server api key delete bucket 403 403 ok
|
||||
server api key get bucket policy 403 403 ok
|
||||
server api key put bucket policy 403 403 ok
|
||||
server api key get bucket acl 403 403 ok
|
||||
server api key put bucket acl public-read 403 403 ok
|
||||
server api key put object acl public-read 403 403 ok
|
||||
server api key put cleaner probe object 200 200 ok
|
||||
server cleaner key get object 200 200 ok
|
||||
server cleaner key head object 200 200 ok
|
||||
server cleaner key delete object 204 204 ok
|
||||
server cleaner key delete object again 204 204 ok
|
||||
server api key get deleted object 404 404 ok
|
||||
server cleaner key delete missing object 204 204 ok
|
||||
server cleaner key put object 403 403 ok
|
||||
server cleaner key list objects 403 403 ok
|
||||
server cleaner key list attachments prefix 200 200 ok
|
||||
server cleaner key list other prefix 403 403 ok
|
||||
server cleaner key create bucket 403 403 ok
|
||||
server cleaner key delete bucket 403 403 ok
|
||||
server cleaner key get bucket policy 403 403 ok
|
||||
server cleaner key put bucket policy 403 403 ok
|
||||
server cleaner key get bucket acl 403 403 ok
|
||||
server cleaner key put bucket acl public-read 403 403 ok
|
||||
server cleaner key put object acl public-read 403 403 ok
|
||||
server api key put object to other bucket 403 403 ok
|
||||
server api key get object from other bucket 403 403 ok
|
||||
server api key list other bucket 403 403 ok
|
||||
server api key delete other bucket 403 403 ok
|
||||
server cleaner key get object from other bucket 403 403 ok
|
||||
server cleaner key delete object in other bucket 403 403 ok
|
||||
server cleaner key list other bucket 403 403 ok
|
||||
server cleaner key delete other bucket 403 403 ok
|
||||
server anonymous get object 403 403 ok
|
||||
server anonymous head object 403 403 ok
|
||||
server anonymous get missing object 403 403 ok
|
||||
server anonymous list objects 403 403 ok
|
||||
server anonymous list buckets 403 403 ok
|
||||
server anonymous put object 403 403 ok
|
||||
server anonymous create bucket 403 403 ok
|
||||
host anonymous get object 403 403 ok
|
||||
host anonymous head object 403 403 ok
|
||||
host anonymous get missing object 403 403 ok
|
||||
host anonymous list objects 403 403 ok
|
||||
host anonymous list buckets 403 403 ok
|
||||
host anonymous put object 403 403 ok
|
||||
server listening outside loopback 8333 18333 8333 18333 ok
|
||||
network anonymous get object 403 403 ok
|
||||
network anonymous head object 403 403 ok
|
||||
network anonymous get missing object 403 403 ok
|
||||
network anonymous list objects 403 403 ok
|
||||
network anonymous list buckets 403 403 ok
|
||||
network anonymous put object 403 403 ok
|
||||
network port 8333 (S3 API / gRPC of gateway) open open ok
|
||||
network port 18333 (S3 API / gRPC of gateway) open open ok
|
||||
network port 8080 (loopback only) closed closed ok
|
||||
network port 8888 (loopback only) closed closed ok
|
||||
network port 9333 (loopback only) closed closed ok
|
||||
network port 18080 (loopback only) closed closed ok
|
||||
network port 18888 (loopback only) closed closed ok
|
||||
network port 19333 (loopback only) closed closed ok
|
||||
network port 39821 (loopback only) closed closed ok
|
||||
server temporary buckets left 0 0 ok
|
||||
server probe objects left 0 0 ok
|
||||
PASS: 70 checks, bucket messenger is private
|
||||
|
||||
$ python3 .claude/skills/run-mtusi-messenger/driver.py --port 8090 attachment-failover --mode stop # 4 с
|
||||
mode: stop; fixture sample.png: 111817 bytes
|
||||
sha256 uploaded: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
|
||||
sha256 downloaded: 99ea7533c441f79cd630d15ce4d58d1ec4e06f6f0efb3b77a5c088305cd1bd75
|
||||
step expected got x-instance-id
|
||||
alice uploads 201 201 94a968393dd6
|
||||
alice sends message 201 201 91fbe934191d
|
||||
stop-one.sh stop 0 0 94a968393dd6
|
||||
bob downloads 200 200 91fbe934191d
|
||||
bob reads metadata 200 200 91fbe934191d
|
||||
eve reads metadata 404 404 91fbe934191d
|
||||
eve downloads 404 404 91fbe934191d
|
||||
make replicas 0 0
|
||||
LB slots UP 2 2
|
||||
PASS: accepted by 94a968393dd6, served by 91fbe934191d after stop, sha256 matches, outsider gets 404
|
||||
|
||||
$ python3 .claude/skills/run-mtusi-messenger/driver.py --port 8090 attachment-storage # 2 с
|
||||
upload via 94a968393dd6: object_key messenger/attachments/bf97f566-2bc7-4fbd-bb65-9eee25af4404/original
|
||||
upload via 91fbe934191d: object_key messenger/attachments/3b703856-69cc-40c1-9249-f4033820e321/original
|
||||
docker diff 94a968393dd6: 2 changes
|
||||
C /app
|
||||
A /app/config.toml
|
||||
docker diff 91fbe934191d: 2 changes
|
||||
C /app
|
||||
A /app/config.toml
|
||||
bytea columns expected sha256 got sha256
|
||||
octet_length(sha256) expected 32 got 32
|
||||
filename not in key expected no got no
|
||||
object in bucket, bytes expected 111817 got 111817
|
||||
anonymous GET of the key expected 403 got 403
|
||||
downloaded sha256 = uploaded expected yes got yes
|
||||
original files in 94a968393dd6 expected 0 got 0
|
||||
original files in 91fbe934191d expected 0 got 0
|
||||
PASS: metadata in PostgreSQL, bytes only in the private bucket messenger, none in the API containers
|
||||
```
|
||||
|
||||
У `attachment-storage` строки второй загрузки повторяют первую и здесь
|
||||
опущены; полный вывод того же вида — `evidence/attachments/storage.md`.
|
||||
|
||||
## Свои тесты, сверка, отказы
|
||||
|
||||
```text
|
||||
$ make student_test BASE_URL=http://localhost:8090 # 42 с
|
||||
BASE_URL=http://localhost:8090 EXPECT_REPLICAS=2 uv run pytest
|
||||
collecting ... collected 254 items / 56 deselected / 198 selected
|
||||
coverage: 252 scenarios in 13 specs, 235 tested (70 by make failure_checks), 17 excluded
|
||||
key race through replicas: {'94a968393dd6': 5, '91fbe934191d': 5}
|
||||
===================== 198 passed, 56 deselected in 41.24s ======================
|
||||
|
||||
$ make reconcile # 5 с, dry-run, exit 0
|
||||
{"event": "Finished reconcile pass", "module": "attachment_reconcile_service", "method": "reconcile", "apply": false, "strategy": "batch", "deep": false, "listed_objects": 74, "checked_rows": 74, "found": {}, "fixed": {}, "remaining": 0, "fresh_objects": 0, "fresh_rows": 0, "lost_known": 0, "refused": false, "unlogged": 0, "unchecked": 0, "interrupted_by": null, "duration_ms": 197, "max_objects_per_second": 2000.0, "storage_objects": 74, "s3_requests": {"list": 1, "head": 0, "get": 0, "delete": 0}, "read_bytes": 0, "db_sessions": 3, "phase_ms": {"list": 131, "rows": 64, "stale": 2, "recheck": 0, "act": 0}, "level": "info"}
|
||||
|
||||
$ make test_isolated # 88 с
|
||||
[test_isolated] database=test_messenger objects=/buckets/messenger/test_messenger/ container=mtusi-lab4-cleancheck-test-api base_url=http://127.0.0.1:18088
|
||||
[test_isolated] make test
|
||||
PASS: lab4 public API scenario; infrastructure and grading evidence remain separate.
|
||||
[test_isolated] make student_test
|
||||
=========== 193 passed, 5 skipped, 56 deselected in 75.43s (0:01:15) ===========
|
||||
[test_isolated] cleanup
|
||||
[test_isolated] remove objects /buckets/messenger/test_messenger/
|
||||
[test_isolated] results: {'test': 0, 'student_test': 0}
|
||||
|
||||
$ make failure_checks # 857 с
|
||||
[failure_checks] project=mtusi-lab4-cleancheck-failures (working stand: mtusi-lab4-cleancheck)
|
||||
[failure_checks] start cleaner: grace 20 s, interval 1 s, reconcile interval 0 s (0 — off)
|
||||
[failure_checks] pytest -m fault
|
||||
collecting ... collected 254 items / 198 deselected / 56 selected
|
||||
================ 56 passed, 198 deselected in 834.00s (0:13:54) ================
|
||||
[failure_checks] postgres log: 467 lines, crash markers 0; "too many clients" 30, "administrator command" 148
|
||||
[failure_checks] cleanup
|
||||
[failure_checks] results: {'fault': 0, 'postgres': 0}
|
||||
```
|
||||
|
||||
Сверка нашла 74 объекта и 74 строки — вложения, загруженные шагами
|
||||
выше, — и ни одного расхождения. Пять пропусков `make test_isolated` —
|
||||
тесты реплик против одного процесса, с причиной «one API process
|
||||
(EXPECT_REPLICAS=1): replica checks need the stand with the load
|
||||
balancer». «too many clients» и «administrator command» в журнале
|
||||
PostgreSQL стенда отказов — внесённые тестами отказы (заполнение
|
||||
`max_connections`, остановка PostgreSQL), признаков аварийного
|
||||
перезапуска нет. После `make failure_checks` контейнеров и volumes
|
||||
проекта `mtusi-lab4-cleancheck-failures` не осталось, стенд клона
|
||||
работал все 17 минут.
|
||||
|
||||
## Уборка
|
||||
|
||||
```text
|
||||
$ docker compose down -v --remove-orphans # проект mtusi-lab4-cleancheck
|
||||
Volume mtusi-lab4-cleancheck_postgres_data Removed
|
||||
Volume mtusi-lab4-cleancheck_s3_data Removed
|
||||
Network mtusi-lab4-cleancheck_default Removed
|
||||
$ docker volume ls --format '{{.Name}}' | grep mtusi-lab4
|
||||
mtusi-lab4_postgres_data
|
||||
mtusi-lab4_s3_data
|
||||
```
|
||||
Reference in New Issue
Block a user