ЛР2 на 3

Co-authored-by: Югай Артур Рустамович <f1ekserr@yandex.ru>
This commit is contained in:
2026-11-16 22:19:31 +03:00
co-authored by Югай Артур Рустамович
parent 65003b6119
commit 8e06e7634f
29 changed files with 1784 additions and 34 deletions
+7
View File
@@ -0,0 +1,7 @@
{
"ttl_seconds": 2,
"expiry_unchanged_on_restart": true,
"before_restart": 200,
"after_expiry_and_restart": 401,
"new_login": 201
}
+17
View File
@@ -0,0 +1,17 @@
{
"public_persistence": "PASS",
"cursor_after_restart": "PASS",
"logout_after_restart": "PASS",
"migration_replay": "PASS",
"database": {
"users": 55,
"chats": 19,
"members": 38,
"messages": 118,
"sessions": 51,
"migrations": 1,
"expiry_fingerprint": "0aeb1b0d92290be0e10e5671487fda98",
"passwords_are_argon2id": true,
"session_hashes_only": true
}
}
+43
View File
@@ -0,0 +1,43 @@
{
"project": "kuznetsov-lab2",
"before": {
"api": {
"id": "1e398850630740acd3ed5db30568b82af4232391bd9c235896cc09e860af88f0",
"image": "sha256:7c648de46909df8dd4c0e6676fc2c990a113960415c513549ee8fc2c5aafeea3",
"started_at": "2026-11-16T19:17:01.565171373Z",
"running": true,
"user": "messenger",
"volumes": []
},
"db": {
"id": "06da5fd9fc7627b7b2abf38517a7fc1383d4dbcef905196eb98a39d826f34754",
"image": "sha256:665dc7b37ac52a17e298511414c21d23ffa4e6a6ef6225b3e5d59c7afb35e994",
"started_at": "2026-11-16T19:16:58.108621772Z",
"running": true,
"user": "",
"volumes": [
"kuznetsov-lab2_pgdata"
]
}
},
"after": {
"api": {
"id": "1e398850630740acd3ed5db30568b82af4232391bd9c235896cc09e860af88f0",
"image": "sha256:7c648de46909df8dd4c0e6676fc2c990a113960415c513549ee8fc2c5aafeea3",
"started_at": "2026-11-16T19:17:11.532370095Z",
"running": true,
"user": "messenger",
"volumes": []
},
"db": {
"id": "06da5fd9fc7627b7b2abf38517a7fc1383d4dbcef905196eb98a39d826f34754",
"image": "sha256:665dc7b37ac52a17e298511414c21d23ffa4e6a6ef6225b3e5d59c7afb35e994",
"started_at": "2026-11-16T19:17:11.161614921Z",
"running": true,
"user": "",
"volumes": [
"kuznetsov-lab2_pgdata"
]
}
}
}
+63
View File
@@ -0,0 +1,63 @@
{
"date_utc": "2026-11-16T19:16:34.757511+00:00",
"platform": "Windows-11-10.0.26200-SP0",
"source_commit": "65003b61195361aac238f19c9bff0027ca58e09e",
"worktree_dirty_at_start": true,
"project": "kuznetsov-lab2",
"status": "PASS",
"persistence": {
"public_persistence": "PASS",
"cursor_after_restart": "PASS",
"logout_after_restart": "PASS",
"migration_replay": "PASS",
"database": {
"users": 55,
"chats": 19,
"members": 38,
"messages": 118,
"sessions": 51,
"migrations": 1,
"expiry_fingerprint": "0aeb1b0d92290be0e10e5671487fda98",
"passwords_are_argon2id": true,
"session_hashes_only": true
}
},
"expiry": {
"ttl_seconds": 2,
"expiry_unchanged_on_restart": true,
"before_restart": 200,
"after_expiry_and_restart": 401,
"new_login": 201
},
"dependency": {
"live_without_db": 200,
"ready_without_db": 503,
"business_without_db": 503,
"recovered": 200
},
"containers": {
"api": {
"id": "1e398850630740acd3ed5db30568b82af4232391bd9c235896cc09e860af88f0",
"image": "sha256:7c648de46909df8dd4c0e6676fc2c990a113960415c513549ee8fc2c5aafeea3",
"started_at": "2026-11-16T19:17:11.532370095Z",
"running": true,
"user": "messenger",
"volumes": []
},
"db": {
"id": "06da5fd9fc7627b7b2abf38517a7fc1383d4dbcef905196eb98a39d826f34754",
"image": "sha256:665dc7b37ac52a17e298511414c21d23ffa4e6a6ef6225b3e5d59c7afb35e994",
"started_at": "2026-11-16T19:17:34.166389334Z",
"running": true,
"user": "",
"volumes": [
"kuznetsov-lab2_pgdata"
]
}
},
"docker": "29.9.3",
"resources": {
"cpus": 12,
"memory_bytes": 16591364096
}
}
+179
View File
@@ -0,0 +1,179 @@
$ ".\.venv\Scripts\python.exe" -X utf8 -m pip install --disable-pip-version-check --no-input --progress-bar off --quiet -r ".\requirements.lock" -r ".\requirements-validation.lock"
Environment ready; existing settings and secrets preserved
$ ".\.venv\Scripts\python.exe" -X utf8 scripts/check_contract.py
PASS: offline skeleton structure, local refs and Python syntax; application NOT tested.
$ ".\.venv\Scripts\python.exe" -X utf8 scripts/validate_openapi.py
PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested.
$ docker compose --project-name kuznetsov-lab2 --env-file .env config --quiet
$ docker compose --project-name kuznetsov-lab2 --env-file .env config --quiet
$ docker compose --project-name kuznetsov-lab2 --env-file .env build api
Image mtusi-messenger:kuznetsov-lab2 Building
#1 [internal] load local bake definitions
#1 reading from stdin 1.18kB 0.0s done
#1 DONE 0.0s
#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 728B done
#2 DONE 0.0s
#3 [internal] load metadata for docker.io/library/python:3.13.14-slim-bookworm@sha256:67a1e1f215ccda113cfc024e8639049257e88f273898f595b61476d128d387e8
#3 DONE 0.0s
#4 [internal] load .dockerignore
#4 transferring context: 216B 0.0s done
#4 DONE 0.0s
#5 [1/6] FROM docker.io/library/python:3.13.14-slim-bookworm@sha256:67a1e1f215ccda113cfc024e8639049257e88f273898f595b61476d128d387e8
#5 resolve docker.io/library/python:3.13.14-slim-bookworm@sha256:67a1e1f215ccda113cfc024e8639049257e88f273898f595b61476d128d387e8 0.0s done
#5 DONE 0.0s
#6 [internal] load build context
#6 transferring context: 70.23kB 0.0s done
#6 DONE 0.0s
#7 [2/6] WORKDIR /app
#7 CACHED
#8 [3/6] COPY requirements.lock .
#8 CACHED
#9 [4/6] RUN python -m pip install --no-cache-dir -r requirements.lock && useradd --uid 10001 --create-home messenger
#9 CACHED
#10 [5/6] COPY src ./src
#10 DONE 0.0s
#11 [6/6] COPY migrations ./migrations
#11 DONE 0.0s
#12 exporting to image
#12 exporting layers 0.1s done
#12 exporting manifest sha256:80fb9067e4bcfe6f7c134efe307969d54ff72de828b07281687bc3a4a3f1734e 0.0s done
#12 exporting config sha256:3cd872e9f0b2aba5dbea2556e722e00db041ee79c0fd126d2c03f44525066938 0.0s done
#12 exporting attestation manifest sha256:b1049f4bff79686bf39c12f60918c1b805330e3a74a117df84261c8aaed05852 0.0s done
#12 exporting manifest list sha256:7c648de46909df8dd4c0e6676fc2c990a113960415c513549ee8fc2c5aafeea3 0.0s done
#12 naming to docker.io/library/mtusi-messenger:kuznetsov-lab2 done
#12 unpacking to docker.io/library/mtusi-messenger:kuznetsov-lab2 0.0s done
#12 DONE 0.2s
#13 resolving provenance for metadata file
#13 DONE 0.0s
Image mtusi-messenger:kuznetsov-lab2 Built
$ docker compose --project-name kuznetsov-lab2 --env-file .env up -d --no-build db migrate api
Volume kuznetsov-lab2_pgdata Creating
Volume kuznetsov-lab2_pgdata Creating
Network kuznetsov-lab2_default Creating
Network kuznetsov-lab2_default Creating
Volume kuznetsov-lab2_pgdata Created
Volume kuznetsov-lab2_pgdata Created
Network kuznetsov-lab2_default Created
Network kuznetsov-lab2_default Created
Container kuznetsov-lab2-db-1 Creating
Container kuznetsov-lab2-db-1 Created
Container kuznetsov-lab2-migrate-1 Creating
Container kuznetsov-lab2-migrate-1 Created
Container kuznetsov-lab2-api-1 Creating
Container kuznetsov-lab2-api-1 Created
Container kuznetsov-lab2-db-1 Starting
Container kuznetsov-lab2-db-1 Started
Container kuznetsov-lab2-db-1 Waiting
Container kuznetsov-lab2-db-1 Healthy
Container kuznetsov-lab2-migrate-1 Starting
Container kuznetsov-lab2-migrate-1 Started
Container kuznetsov-lab2-migrate-1 Waiting
Container kuznetsov-lab2-migrate-1 Exited
Container kuznetsov-lab2-api-1 Starting
Container kuznetsov-lab2-api-1 Started
API ready: http://127.0.0.1:18102
$ ".\.venv\Scripts\python.exe" -X utf8 tests/smoke.py --base-url http://127.0.0.1:18102
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
$ ".\.venv\Scripts\python.exe" -X utf8 -m unittest discover -s student-tests -v
test_auth_and_access (test_api.ApiTests.test_auth_and_access) ... ok
test_bad_cursors_and_limits (test_api.ApiTests.test_bad_cursors_and_limits) ... ok
test_chat_pagination (test_api.ApiTests.test_chat_pagination) ... ok
test_chat_validation_is_atomic (test_api.ApiTests.test_chat_validation_is_atomic) ... ok
test_invalid_json_and_content_type (test_api.ApiTests.test_invalid_json_and_content_type) ... ok
test_message_fields_and_unicode (test_api.ApiTests.test_message_fields_and_unicode) ... ok
test_message_pagination (test_api.ApiTests.test_message_pagination) ... ok
test_parallel_messages (test_api.ApiTests.test_parallel_messages) ... ok
test_parallel_username (test_api.ApiTests.test_parallel_username) ... ok
test_read_after_write (test_api.ApiTests.test_read_after_write) ... ok
test_user_fields (test_api.ApiTests.test_user_fields) ... ok
test_logout_only_revokes_current_session (test_sessions.SessionTests.test_logout_only_revokes_current_session) ... ok
test_malformed_basic_and_body (test_sessions.SessionTests.test_malformed_basic_and_body) ... ok
test_only_bearer_identifies_user (test_sessions.SessionTests.test_only_bearer_identifies_user) ... ok
test_password_boundaries_unicode_colon_spaces (test_sessions.SessionTests.test_password_boundaries_unicode_colon_spaces) ... ok
test_password_required_and_limits (test_sessions.SessionTests.test_password_required_and_limits) ... ok
test_wrong_and_unknown_credentials (test_sessions.SessionTests.test_wrong_and_unknown_credentials) ... ok
----------------------------------------------------------------------
Ran 17 tests in 5.307s
OK
$ ".\.venv\Scripts\python.exe" -X utf8 tests/resilience.py --mode persistence --action-script ".\scripts\restart.cmd" --base-url http://127.0.0.1:18102
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 --project-name kuznetsov-lab2 --env-file .env run --rm --no-deps migrate
Container kuznetsov-lab2-migrate-run-d87d482ec5d5 Creating
Container kuznetsov-lab2-migrate-run-d87d482ec5d5 Created
Already applied: 001_initial.sql
$ docker compose --project-name kuznetsov-lab2 --env-file .env run --rm --no-deps migrate
Container kuznetsov-lab2-migrate-run-eaca47dfbaf5 Creating
Container kuznetsov-lab2-migrate-run-eaca47dfbaf5 Created
Already applied: 001_initial.sql
PASS: old session/cursor, durable logout and repeatable migrations
$ docker compose --project-name kuznetsov-lab2-ttl --env-file .env up -d --no-build db migrate api
Network kuznetsov-lab2-ttl_default Creating
Volume kuznetsov-lab2-ttl_pgdata Creating
Volume kuznetsov-lab2-ttl_pgdata Creating
Network kuznetsov-lab2-ttl_default Creating
Volume kuznetsov-lab2-ttl_pgdata Created
Volume kuznetsov-lab2-ttl_pgdata Created
Network kuznetsov-lab2-ttl_default Created
Network kuznetsov-lab2-ttl_default Created
Container kuznetsov-lab2-ttl-db-1 Creating
Container kuznetsov-lab2-ttl-db-1 Created
Container kuznetsov-lab2-ttl-migrate-1 Creating
Container kuznetsov-lab2-ttl-migrate-1 Created
Container kuznetsov-lab2-ttl-api-1 Creating
Container kuznetsov-lab2-ttl-api-1 Created
Container kuznetsov-lab2-ttl-db-1 Starting
Container kuznetsov-lab2-ttl-db-1 Started
Container kuznetsov-lab2-ttl-db-1 Waiting
Container kuznetsov-lab2-ttl-db-1 Healthy
Container kuznetsov-lab2-ttl-migrate-1 Starting
Container kuznetsov-lab2-ttl-migrate-1 Started
Container kuznetsov-lab2-ttl-migrate-1 Waiting
Container kuznetsov-lab2-ttl-migrate-1 Exited
Container kuznetsov-lab2-ttl-api-1 Starting
Container kuznetsov-lab2-ttl-api-1 Started
API ready: http://127.0.0.1:18112
$ docker compose --project-name kuznetsov-lab2-ttl --env-file .env restart --timeout 5 api
Container kuznetsov-lab2-ttl-api-1 Restarting
Container kuznetsov-lab2-ttl-api-1 Started
PASS: TTL=2, expired token rejected after API restart; fresh login works
$ docker compose --project-name kuznetsov-lab2-ttl --env-file .env down --timeout 10
Container kuznetsov-lab2-ttl-api-1 Stopping
Container kuznetsov-lab2-ttl-api-1 Stopped
Container kuznetsov-lab2-ttl-api-1 Removing
Container kuznetsov-lab2-ttl-api-1 Removed
Container kuznetsov-lab2-ttl-migrate-1 Stopping
Container kuznetsov-lab2-ttl-migrate-1 Stopped
Container kuznetsov-lab2-ttl-migrate-1 Removing
Container kuznetsov-lab2-ttl-migrate-1 Removed
Container kuznetsov-lab2-ttl-db-1 Stopping
Container kuznetsov-lab2-ttl-db-1 Stopped
Container kuznetsov-lab2-ttl-db-1 Removing
Container kuznetsov-lab2-ttl-db-1 Removed
Network kuznetsov-lab2-ttl_default Removing
Network kuznetsov-lab2-ttl_default Removed
$ docker compose --project-name kuznetsov-lab2 --env-file .env stop --timeout 10 db
Container kuznetsov-lab2-db-1 Stopping
Container kuznetsov-lab2-db-1 Stopped
$ docker compose --project-name kuznetsov-lab2 --env-file .env start db
Container kuznetsov-lab2-db-1 Starting
Container kuznetsov-lab2-db-1 Started
PASS: DB outage -> live=200, ready/business=503; session works after recovery
$ ".\.venv\Scripts\python.exe" -X utf8 tests/smoke.py --base-url http://127.0.0.1:18102
PASS: lab2 public API scenario; infrastructure and grading evidence remain separate.
PASS: full lab2 verification