Реализовать lab2: PostgreSQL и постоянные Bearer-сессии
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Надежда Карпова
2026-11-05 01:43:30 +03:00
parent 65003b6119
commit 3daebda0cb
40 changed files with 4208 additions and 20 deletions
+15
View File
@@ -3,3 +3,18 @@
Храните небольшие обезличенные результаты: команды и stdout проверок, JSON/CSV агрегатов нагрузки, EXPLAIN, dashboard JSON, текст разбора отказа. Укажите дату, commit, аппаратные лимиты и профиль нагрузки.
Не добавляйте .env, session tokens, cookies, приватные ключи, credentials, реальные сообщения, raw dumps и signed URLs. Для скриншотов скрывайте секреты. Большие логи/бинарные traces сохраняйте отдельно по правилам преподавателя; одного скриншота без методики недостаточно.
## Результаты решения Карповой Н. С., БВИ2302 — на 5
Это реальные обезличенные результаты облачного стенда, дата по Москве — 5 ноября 2026. UTC-метки в файлах — 4 ноября. Поставка из ZIP, upstream commit неизвестен; точные исходники фиксирует source-sha256.txt.
- [grade5-functional.txt](grade5-functional.txt): проверки уровней 3–4, перенесённые own/concurrency lab1, cache TTL/hits/outage, rollback, restart всех трёх сервисов, expiry и отказ/восстановление БД.
- [grade5-study.txt](grade5-study.txt): исследование 120000 сообщений, два индекса и реальный backup/restore в новый PostgreSQL с новым volume.
- [query-study.json](query-study.json): все замеры, EXPLAIN (ANALYZE, BUFFERS), стоимость записи, fingerprints и времена восстановления.
- [environment.txt](environment.txt): ресурсы, версии, fsync/synchronous_commit и контейнеры.
- [build.txt](build.txt): финальная Compose-сборка и готовность сервисов.
- [openapi.txt](openapi.txt): полная валидация OpenAPI/JSON Schema.
- [skeleton-integrity.txt](skeleton-integrity.txt): сверка с ZIP преподавателя.
- [source-sha256.txt](source-sha256.txt): контрольные суммы поставляемого кода.
Методика, агрегаты, ограничения и объяснение результатов: [RESEARCH.md](../RESEARCH.md); соответствие критериям: [REPORT.md](../REPORT.md). Скриншоты не подделывались: по заданию допускаются текстовые доказательства команд и наблюдений.
+76
View File
@@ -0,0 +1,76 @@
UTC: 2026-11-04T22:04:55.006926+00:00
Command: docker compose up -d --build --wait
#1 [internal] load local bake definitions
#1 reading from stdin 699B done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 626B done
#2 DONE 0.0s
#3 resolve image config for docker-image://docker.io/docker/dockerfile:1
#3 DONE 0.2s
#4 docker-image://docker.io/docker/dockerfile:1@sha256:4edf897a3ffa55b89f906fc8cc78afdb3f1834cc9c7083565e611a8a7d5fe99e
#4 CACHED
#5 [internal] load metadata for docker.io/library/python:3.12.12-slim-bookworm
#5 DONE 0.2s
#6 [internal] load .dockerignore
#6 transferring context: 196B done
#6 DONE 0.0s
#7 [stage-0 1/8] FROM docker.io/library/python:3.12.12-slim-bookworm@sha256:593bd06efe90efa80dc4eee3948be7c0fde4134606dd40d8dd8dbcade98e669c
#7 DONE 0.0s
#8 [internal] load build context
#8 transferring context: 404B done
#8 DONE 0.0s
#9 [stage-0 4/8] RUN --mount=type=secret,id=proxy_ca if [ -f /run/secrets/proxy_ca ]; then export PIP_CERT=/run/secrets/proxy_ca; fi; pip install --no-cache-dir -r requirements.txt
#9 CACHED
#10 [stage-0 5/8] COPY src ./src
#10 CACHED
#11 [stage-0 6/8] COPY migrations ./migrations
#11 CACHED
#12 [stage-0 2/8] WORKDIR /app
#12 CACHED
#13 [stage-0 3/8] COPY requirements.txt .
#13 CACHED
#14 [stage-0 7/8] COPY contracts ./contracts
#14 CACHED
#15 [stage-0 8/8] RUN chmod -R a+rX /app && useradd --uid 10001 --create-home app
#15 CACHED
#16 exporting to image
#16 exporting layers done
#16 writing image sha256:30613bcdeff20685a51df3a0bdd45e560991ac73bbb33e933e434489b482f6c0 done
#16 naming to docker.io/library/mtusi2026lab2-api done
#16 DONE 0.0s
#17 resolving provenance for metadata file
#17 DONE 0.0s
mtusi2026lab2-api Built
Container mtusi2026lab2-db-1 Running
Container mtusi2026lab2-api-1 Recreate
Container mtusi2026lab2-cache-1 Running
Container mtusi2026lab2-api-1 Recreated
Container mtusi2026lab2-db-1 Waiting
Container mtusi2026lab2-db-1 Healthy
Container mtusi2026lab2-api-1 Starting
Container mtusi2026lab2-api-1 Started
Container mtusi2026lab2-db-1 Waiting
Container mtusi2026lab2-cache-1 Waiting
Container mtusi2026lab2-api-1 Waiting
Container mtusi2026lab2-cache-1 Healthy
Container mtusi2026lab2-db-1 Healthy
Container mtusi2026lab2-api-1 Healthy
Exit code: 0
+5
View File
@@ -0,0 +1,5 @@
UTC: 2026-11-04T22:38:59.847637+00:00
Command: python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
Exit code: 0
+25
View File
@@ -0,0 +1,25 @@
UTC: 2026-11-04T22:06:31.893524+00:00
Client date: 2026-11-05 Europe/Moscow
Kernel: Linux-6.18.57-x86_64-with-glibc2.41
CPU logical cores visible: 5
/sys/fs/cgroup/memory.max: 34359738368
/sys/fs/cgroup/cpu.max: 400000 100000
Command: docker version --format client={{.Client.Version}} server={{.Server.Version}}
client=29.9.2 server=29.9.2
Command: docker compose version
Docker Compose version v2.40.3
Command: docker compose exec -T db psql -U messenger -d messenger -Atc select version(); show fsync; show synchronous_commit;
PostgreSQL 17.6 (Debian 17.6-2.pgdg12+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
on
on
Command: docker compose exec -T cache redis-cli INFO server
redis_version:7.4.6
redis_mode:standalone
arch_bits:64
Command: docker compose exec -T api id
uid=10001(app) gid=10001(app) groups=10001(app)
Command: docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
mtusi2026lab2-api-1 mtusi2026lab2-api "sh -c 'python src/m…" api About a minute ago Up About a minute (healthy) 127.0.0.1:8080->8080/tcp
mtusi2026lab2-cache-1 redis:7.4.6-bookworm "docker-entrypoint.s…" cache 9 minutes ago Up 2 minutes (healthy) 6379/tcp
mtusi2026lab2-db-1 postgres:17.6-bookworm "docker-entrypoint.s…" db 20 minutes ago Up 2 minutes (healthy) 5432/tcp
+54
View File
@@ -0,0 +1,54 @@
UTC: 2026-11-04T22:39:51.907732+00:00
Command: python3 student-tests/run_all.py
RUN: make check
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
RUN: make test
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
RUN: /Library/Developer/CommandLineTools/usr/bin/python3 student-tests/security.py
PASS: malformed JSON, strict fields/types, whitespace, limits, cursor resource binding, invalid chat atomicity, concurrent username uniqueness
RUN: /Library/Developer/CommandLineTools/usr/bin/python3 student-tests/lab1_own_tests.py
PASS: own negative, access-control and multi-page tests
RUN: /Library/Developer/CommandLineTools/usr/bin/python3 student-tests/lab1_concurrency.py
PASS: 10 concurrent clients -> 100 successful messages -> 100 unique messages
RUN: /Library/Developer/CommandLineTools/usr/bin/python3 student-tests/level4.py
PASS: actual cached public profile, TTL <=60 seconds, at least 3 Redis cache hits
Container mtusi2026lab2-cache-1 Stopping
Container mtusi2026lab2-cache-1 Stopped
Cache outage diagnostic: profile_matches=True elapsed_seconds=0.204
PASS: Redis down: PostgreSQL fallback 0.204s, ready=200, invalid/absent/revoked sessions=401
Container mtusi2026lab2-cache-1 Starting
Container mtusi2026lab2-cache-1 Started
PASS: ephemeral Redis restart: cache is rebuilt; no session source of truth lost
PASS: injected failure AFTER chat INSERT: HTTP 503, transaction rolled back chat and members
PASS: same API remains usable after rollback
RUN: /Library/Developer/CommandLineTools/usr/bin/python3 student-tests/infrastructure.py
Before full restart:
api 28fbeae97d23eca5e256d399d79848f1d981bc78294f72a7539a3958c38b420a 2026-11-04T22:39:09.243190426Z 0
db dbee5490f591813b35c71f4b10be9450f26196ffaa97272b9d51c9e54cbba55c 2026-11-04T22:39:08.499371509Z 0
cache 7f2b559ca9eb198a44bbdd00a2e91c1d6f0b2e41a861c47570606082fa0e68d2 2026-11-04T22:39:37.450518717Z 0
DB postmaster: 2026-11-04 22:39:08.553299+00
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
After full restart:
api 28fbeae97d23eca5e256d399d79848f1d981bc78294f72a7539a3958c38b420a 2026-11-04T22:39:42.159768302Z 0
db dbee5490f591813b35c71f4b10be9450f26196ffaa97272b9d51c9e54cbba55c 2026-11-04T22:39:41.091549593Z 0
cache 7f2b559ca9eb198a44bbdd00a2e91c1d6f0b2e41a861c47570606082fa0e68d2 2026-11-04T22:39:41.155934302Z 0
DB postmaster: 2026-11-04 22:39:41.187536+00
Already applied 001_initial.sql
Already applied 001_initial.sql
PASS: two migration reruns; users/chats/messages/sessions/migrations counts unchanged: 36|13|113|31|1
Container lab2-expiry Creating
Container lab2-expiry Created
PASS: a real short-lived session authenticates before expiry and returns 401 after expiry
Container mtusi2026lab2-db-1 Stopping
Container mtusi2026lab2-db-1 Stopped
PASS: DB down: live=200, ready=503, authenticated request=503; no anonymous fallback
Container mtusi2026lab2-db-1 Starting
Container mtusi2026lab2-db-1 Started
PASS: DB recovered; same session works
PASS: all required functional checks completed
Exit code: 0
+52
View File
@@ -0,0 +1,52 @@
UTC: 2026-11-04T22:03:47.272430+00:00
Command: python3 student-tests/run_all.py
RUN: make check
python3 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
RUN: make test
python3 tests/smoke.py --base-url "http://localhost:8080"
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
RUN: /opt/codex/runtimes/codex-primary-runtime/dependencies/python/bin/python3 student-tests/security.py
PASS: malformed JSON, strict fields/types, whitespace, limits, cursor resource binding, invalid chat atomicity, concurrent username uniqueness
RUN: /opt/codex/runtimes/codex-primary-runtime/dependencies/python/bin/python3 student-tests/lab1_own_tests.py
PASS: own negative, access-control and multi-page tests
RUN: /opt/codex/runtimes/codex-primary-runtime/dependencies/python/bin/python3 student-tests/lab1_concurrency.py
PASS: 10 concurrent clients -> 100 successful messages -> 100 unique messages
RUN: /opt/codex/runtimes/codex-primary-runtime/dependencies/python/bin/python3 student-tests/level4.py
PASS: actual cached public profile, TTL <=60 seconds, at least 3 Redis cache hits
Container mtusi2026lab2-cache-1 Stopping
Container mtusi2026lab2-cache-1 Stopped
Cache outage diagnostic: profile_matches=True elapsed_seconds=0.007
PASS: Redis down: PostgreSQL fallback 0.007s, ready=200, invalid/absent/revoked sessions=401
Container mtusi2026lab2-cache-1 Starting
Container mtusi2026lab2-cache-1 Started
PASS: ephemeral Redis restart: cache is rebuilt; no session source of truth lost
PASS: injected failure AFTER chat INSERT: HTTP 503, transaction rolled back chat and members
PASS: same API remains usable after rollback
RUN: /opt/codex/runtimes/codex-primary-runtime/dependencies/python/bin/python3 student-tests/infrastructure.py
Before full restart:
api 9ae2e8de18d5a000eb0bef30af317c67e92bc0ee1db5455e646a29262aec9e1a 2026-11-04T22:01:53.486440398Z 0
db 9714c57601ade4f1458923203e668eee6ae1f45cf97382a1fc669f564da39317 2026-11-04T21:48:09.56075614Z 0
cache 438fe5a917be32774249ad31467c43ec1309c28a6fd7e9c50955384fcee3838b 2026-11-04T22:03:30.50288512Z 0
DB postmaster: 2026-11-04 21:48:09.71223+00
python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080"
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
After full restart:
api 9ae2e8de18d5a000eb0bef30af317c67e92bc0ee1db5455e646a29262aec9e1a 2026-11-04T22:03:37.04495913Z 0
db 9714c57601ade4f1458923203e668eee6ae1f45cf97382a1fc669f564da39317 2026-11-04T22:03:36.308873498Z 0
cache 438fe5a917be32774249ad31467c43ec1309c28a6fd7e9c50955384fcee3838b 2026-11-04T22:03:36.096145205Z 0
DB postmaster: 2026-11-04 22:03:36.469068+00
Already applied 001_initial.sql
Already applied 001_initial.sql
PASS: two migration reruns; users/chats/messages/sessions/migrations counts unchanged: 83|27|327|74|1
PASS: a real short-lived session authenticates before expiry and returns 401 after expiry
Container mtusi2026lab2-db-1 Stopping
Container mtusi2026lab2-db-1 Stopped
PASS: DB down: live=200, ready=503, authenticated request=503; no anonymous fallback
Container mtusi2026lab2-db-1 Starting
Container mtusi2026lab2-db-1 Started
PASS: DB recovered; same session works
PASS: all required functional checks completed
Exit code: 0
+18
View File
@@ -0,0 +1,18 @@
UTC: 2026-11-04T22:40:12.450298+00:00
Command: python3 student-tests/research.py
Fresh isolated databases: lab2_study_73b956d721 lab2_study_73b956d721_restored
Seeded 120000 synthetic messages: 100000 + 19000 + 100*10
PASS: 2 indexes, 3 rounds, 3 query profiles, 20 measured reads/profile, real 5000-row writes with rollback
PASS: pg_dump -> NEW PostgreSQL container + NEW volume -> table counts + ALL 120000 messages SHA256 + selected messages match
Backup 0.319s; restore 1.750s; verification 0.930s; dump 4100901 bytes
global 5000-row insert ms: [24.202, 23.839, 23.957]
global hot-middle median ms per round: [0.116, 0.111, 0.112]
global medium-first median ms per round: [5.131, 4.756, 4.722]
global tiny-first median ms per round: [5.662, 5.719, 5.748]
chat_first 5000-row insert ms: [24.617, 24.58, 24.879]
chat_first hot-middle median ms per round: [0.111, 0.115, 0.117]
chat_first medium-first median ms per round: [0.111, 0.111, 0.117]
chat_first tiny-first median ms per round: [0.063, 0.062, 0.06]
Research source database and recovered volume retained for inspection; recovery process stopped; no dump/credentials included in evidence.
Exit code: 0
+18
View File
@@ -0,0 +1,18 @@
UTC: 2026-11-04T22:04:19.320899+00:00
Command: python3 student-tests/research.py
Fresh isolated databases: lab2_study_d495852d11 lab2_study_d495852d11_restored
Seeded 120000 synthetic messages: 100000 + 19000 + 100*10
PASS: 2 indexes, 3 rounds, 3 query profiles, 20 measured reads/profile, real 5000-row writes with rollback
PASS: pg_dump -> NEW PostgreSQL container + NEW volume -> table counts + ALL 120000 messages SHA256 + selected messages match
Backup 0.679s; restore 6.288s; verification 2.288s; dump 4100912 bytes
global 5000-row insert ms: [68.552, 62.403, 91.077]
global hot-middle median ms per round: [0.322, 0.292, 0.504]
global medium-first median ms per round: [22.437, 22.073, 23.842]
global tiny-first median ms per round: [26.97, 27.168, 27.924]
chat_first 5000-row insert ms: [70.005, 65.643, 78.178]
chat_first hot-middle median ms per round: [0.445, 0.335, 0.303]
chat_first medium-first median ms per round: [0.249, 0.276, 0.282]
chat_first tiny-first median ms per round: [0.123, 0.147, 0.142]
Research source database and recovered volume retained for inspection; recovery process stopped; no dump/credentials included in evidence.
Exit code: 0
+13
View File
@@ -0,0 +1,13 @@
User-provided lab1 archive SHA256: 956c17391860b6b432173ba2763ff7204d4b03c7a44e0422919b70b994377c1f
Source identity supplied by user: Карпова Надежда Сергеевна, БВИ2302
Original source files (not copied over lab2 contracts/public tests):
eb41f004c3bbd1e4ae33f97b66369c280957648f8d7aa5d63557f6ec0d522deb lab1/main.py
10e085dbfb4e67b58418a5cb2a12ed6ad06c7c76c99543b63028711ffa6eb8fa lab1/REPORT.md
213debb6d7bd76a5ed7043e6ab8e29af4415a7db3ef3dd39b47917736ce8551b lab1/tests/own_tests.py
0fd715e787877d20ceb4119424d123855076be12d199b2163050f05cba600101 lab1/tests/concurrency.py
d2c40189937c3a965593b95a38e98037122c1a3b9213a41eb07fd5f6efafac4a lab1/tests/benchmark_track1.py
Adapted test files:
2503ff8f91d802dd29a83f94ff247cf0978b8b7fa9ea1dd7a6885771404b5ca4 student-tests/lab1_own_tests.py
10e46adcffd8b97aa80aa41670d8e78f016735fb5ad59f9c5346ffa9fc57d792 student-tests/lab1_concurrency.py
Changes to tests: add password to synthetic registrations, Basic login, Bearer headers; original assertions retained.
Application handlers rewritten for PostgreSQL/Redis/Flask; do not claim original main.py was copied unchanged.
+6
View File
@@ -0,0 +1,6 @@
UTC: 2026-11-04T21:50:01.263099+00:00
Command: make validate PYTHON=/tmp/lab2-validation/bin/python
/tmp/lab2-validation/bin/python scripts/validate_openapi.py
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
Exit code: 0
+6
View File
@@ -0,0 +1,6 @@
UTC: 2026-11-04T22:39:09.887252+00:00
Command: python3 tests/resilience.py --mode persistence --action-script scripts/restart.sh
Executing explicit persistence hook; hook output suppressed to avoid leaking secrets.
PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence.
Exit code: 0
File diff suppressed because it is too large Load Diff
+5
View File
@@ -0,0 +1,5 @@
UTC: 2026-11-04T22:39:00.863381+00:00
Command: python3 student-tests/security.py
PASS: malformed JSON, strict fields/types, whitespace, limits, cursor resource binding, invalid chat atomicity, concurrent username uniqueness
Exit code: 0
+31
View File
@@ -0,0 +1,31 @@
Original teacher ZIP SHA256: 8a5f58dfc8b2a176e84aa13e2a54d0d27e3d6f8f8d78bd3bd83755912e1b492d
Changed original files: REPORT.md (filled report), evidence/README.md (appended evidence index).
All other original files are byte-for-byte unchanged:
.dockerignore
.env.example
.github/pull_request_template.md
.github/workflows/contracts.yml
.gitignore
CONTRIBUTING.md
COURSE.md
Dockerfile.example
MAINTAINERS.md
Makefile
README.md
compose.example.yaml
contracts/README.md
contracts/examples.json
contracts/infrastructure.json
contracts/openapi.json
examples/requests.http
infra/README.md
lab.json
requirements-dev.txt
scripts/check_contract.py
scripts/restart.example.sh
scripts/validate_openapi.py
tests/README.md
tests/client.py
tests/load.py
tests/resilience.py
tests/smoke.py
+5
View File
@@ -0,0 +1,5 @@
UTC: 2026-11-04T22:39:00.388888+00:00
Command: python3 tests/smoke.py
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
Exit code: 0
+21
View File
@@ -0,0 +1,21 @@
961a72eea39d30fde2f04441337703cdbfb7f0c2011b1d7e6cc4c7f687ca6891 Dockerfile
0d7e46e04e877cbac7d19e25de18d7e1f1f03584a821b30e9e8fa070f90fc0e3 compose.yaml
67bbcdf029a6b100b6385e2f35a31b4ee7db42d763a1c0dc71d4da58bdbe250a migrations/001_initial.sql
fc8f9d5866863123e6ab7aa42b92d59752b23b995c1157bf67d67d4597f7715f requirements.txt
fc0d9a9330b62d6182c302a16c07e9ea26dee1c3cbbaab8be09ce0943fe3e040 scripts/capture.py
7c4402c2a6ab80d3b4676e1866d6ecc87b6daea14c080bcb9be9a7e8b959d671 scripts/check_contract.py
3a812bcb0e481c83fb059844556968ad1af5d45c67d43c2cbae51f9ba421b1e7 scripts/init-local.py
0328246ba75defbced992104e986fde973f63e3830d83251eced5953263e944b scripts/restart.example.sh
4f5f7aafbdef689a1b804dfb21f072e40010b126dc7dfe6dce8b8d99642e2c88 scripts/restart.sh
4e981acbfc10dac58817bf922d5896e996798551fedc1b2385130e1cddb13d54 scripts/validate_openapi.py
36636d23ef3167a8e73b455f6127c89e87ae846031b380c3f8ab8a957f3f1468 src/app.py
62b0cf236fd5633b640c92d5f587bf5621990ea3d3b55a9c8cacc13a353f1f88 src/migrate.py
a4e10d1ea8d7c9ccdf9483d89ac7be7f4822530bf5569227821ff88099efc973 student-tests/expiry.py
127fe75d0d835c37a1adb55eaccfd455e831fefd09e70f78072fc7f7c7e30ec1 student-tests/infrastructure.py
10e46adcffd8b97aa80aa41670d8e78f016735fb5ad59f9c5346ffa9fc57d792 student-tests/lab1_concurrency.py
2503ff8f91d802dd29a83f94ff247cf0978b8b7fa9ea1dd7a6885771404b5ca4 student-tests/lab1_own_tests.py
ff018b991dfb699575faccafcf26ca1c79279dbb721bdb1cbf5c6238c446e674 student-tests/level4.py
7632d25b51ad2be9f7d05f59b8479f1e44c75c2952b5cee2be66ca322ffc4c68 student-tests/research.py
a535c111539b8edde88345622067e316fdf26f282a8b5cbf87e7005d127e4a09 student-tests/research_worker.py
2d3123ed5b459deaa888ad86bf0acbaa4df53307d29585340ee4572fb085ca4e student-tests/run_all.py
c358a5e3c8fbf74e2485ce22f4e17564c84eb7402a5204c4d9029b3c88bf173d student-tests/security.py