From bc1d7aa7713858acb5d65b61d07e69a640f1ee97 Mon Sep 17 00:00:00 2001 From: Artyom Date: Sat, 7 Nov 2026 02:35:40 +0300 Subject: [PATCH] Port final lab 5 validation, session and PNG recovery fixes --- evidence/forward-port.md | 28 + evidence/forward-published/quality.txt | 14 + .../forward-published/source-inventory.json | 1974 +++++++++++++++++ evidence/forward-published/student-test.txt | 78 + infra/haproxy/haproxy.cfg | 6 +- infra/rabbitmq/definitions.json | 2 +- .../forward-lab5-published-fixes/tasks.md | 10 +- openspec/config.yaml | 4 +- .../attachments/infrastructure/images.py | 86 +- .../attachments/infrastructure/png.py | 118 + .../identity/application/handlers.py | 2 +- src/messenger/identity/domain/values.py | 2 + .../identity/entrypoints/authentication.py | 4 +- .../identity/infrastructure/postgres.py | 4 +- .../identity/infrastructure/valkey.py | 30 +- src/messenger/messaging/domain/values.py | 4 + student-tests/adapters/test_rabbitmq.py | 12 +- student-tests/api/test_attachments.py | 6 +- student-tests/api/test_cache.py | 105 +- student-tests/api/test_nul_validation.py | 95 + student-tests/api/test_sessions.py | 28 + student-tests/pictures.py | 27 + student-tests/png_trns_fixtures.py | 122 + student-tests/stack/test_attachment_faults.py | 4 +- student-tests/tools/forward_conditions.py | 59 + student-tests/tools/forward_network.py | 130 ++ student-tests/tools/forward_runtime.py | 386 ++++ student-tests/tools/lb_errors/client.py | 43 + student-tests/tools/lb_errors/compose.yaml | 25 + student-tests/tools/lb_errors/server.py | 20 + student-tests/unit/test_authentication.py | 52 + student-tests/unit/test_haproxy_errors.py | 26 + student-tests/unit/test_image_inspection.py | 279 +++ student-tests/unit/test_nul_inputs.py | 95 + student-tests/unit/test_png_memory.py | 110 + student-tests/unit/test_png_transparency.py | 67 + student-tests/unit/test_png_upload.py | 83 + student-tests/unit/test_renderer.py | 42 +- student-tests/unit/test_session_cache.py | 161 ++ student-tests/unit/test_worker_delivery.py | 63 + tools/plot_observability.py | 10 +- 41 files changed, 4363 insertions(+), 53 deletions(-) create mode 100644 evidence/forward-port.md create mode 100644 evidence/forward-published/quality.txt create mode 100644 evidence/forward-published/source-inventory.json create mode 100644 evidence/forward-published/student-test.txt create mode 100644 src/messenger/attachments/infrastructure/png.py create mode 100644 student-tests/api/test_nul_validation.py create mode 100644 student-tests/png_trns_fixtures.py create mode 100644 student-tests/tools/forward_conditions.py create mode 100644 student-tests/tools/forward_network.py create mode 100644 student-tests/tools/forward_runtime.py create mode 100644 student-tests/tools/lb_errors/client.py create mode 100644 student-tests/tools/lb_errors/compose.yaml create mode 100644 student-tests/tools/lb_errors/server.py create mode 100644 student-tests/unit/test_haproxy_errors.py create mode 100644 student-tests/unit/test_image_inspection.py create mode 100644 student-tests/unit/test_nul_inputs.py create mode 100644 student-tests/unit/test_png_memory.py create mode 100644 student-tests/unit/test_png_transparency.py create mode 100644 student-tests/unit/test_png_upload.py create mode 100644 student-tests/unit/test_session_cache.py create mode 100644 student-tests/unit/test_worker_delivery.py diff --git a/evidence/forward-port.md b/evidence/forward-port.md new file mode 100644 index 0000000..0fca3a0 --- /dev/null +++ b/evidence/forward-port.md @@ -0,0 +1,28 @@ +# Поздний перенос ЛР5 → ЛР6 + +Источник только immutable snapshot `lab5-c7b8feb805d151e878d77b0dff47320a9436b172`; диапазон `f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071..c7b8feb805d151e878d77b0dff47320a9436b172`. Исходный HEAD ЛР6 `237a7c93e507b984add5b49c51c6720a6bfca505`, дерево было чистым. Полный перечень всех изменённых путей, SHA-256 источника и решение по каждому: [source-inventory.json](forward-published/source-inventory.json). + +## Перенос + +| Группа | Изменение | Разрешение | +|---|---|---| +| identity handlers/postgres/valkey | Отзыв сессии, блокировка чтения, nonce заполнения кэша | Полный diff; SQLAlchemy и Lua, схема без изменений | +| identity authentication/values, messaging values | NUL и не-ASCII Basic | Полный diff; ошибки по существующему контракту | +| attachments images.py и png.py | Проверка IDAT, исходная tRNS глубина, tiles памяти | Полный diff; OTel S3/worker не изменён | +| infra/haproxy/haproxy.cfg | JSON escaping request_id в 502/503/504 | Полный diff | +| infra/rabbitmq/definitions.json | delivery-limit=-1 | Сохранено описание lab6 и существующая топология/DLX | +| student-tests (все пути inventory) | Регрессии источника | Сохранены OTelJobObserver/provider ЛР6; прямые handle_job получают observer. Boundary PNG генерируются локально, без зависимости от evidence ЛР5; default project/port заменены на ЛР6 | +| openspec/specs (10 capabilities) | 11 изменённых requirements | Полные delta blocks, исходные префиксы capabilities сохранены | +| openspec/config.yaml | Версии SQLAlchemy/Alembic, provenance | Применимые строки влиты, контекст ЛР6 сохранён | + +## Неприменимые артефакты + +AGENTS.md, REPORT.md и evidence/README.md источника относятся к ЛР5 и не заменяют документы ЛР6. Результаты evidence источника относятся к другому приложению/SHA и не копируются как доказательство ЛР6. Исполняемая логика двух targeted.py адаптирована в student-tests/tools/forward_runtime.py; их файлы результатов не импортированы. Четыре новых source OpenSpec archives — история выполненных этапов ЛР5; их требования перенесены объединённым change `forward-lab5-published-fixes`, их завершение не выдаётся за проверку ЛР6. Каждый исключённый путь перечислен в inventory с причиной. Применимых runtime-изменений не пропущено; source diff не затрагивает Dockerfile, зависимости, Alembic или compose runtime. + +## Документация + +Context7 resolve для SQLAlchemy и RabbitMQ вернул `Monthly quota exceeded`. Использован официальный fallback: [SQLAlchemy 2.0 with_for_update](https://docs.sqlalchemy.org/en/20/core/selectable.html#sqlalchemy.sql.expression.GenerativeSelect.with_for_update) подтверждает read+key_share; [RabbitMQ 4.1 quorum delivery limit](https://www.rabbitmq.com/docs/4.1/quorum-queues#disabling-the-limit) содержит policy delivery-limit=-1. Новых зависимостей нет; версии остаются закреплёнными. + +## Проверки и затронутые измерения + +Изменение auth/cache влияет на HTTP/DB путь трека, поэтому повторяются все 15 серий с прежними параметрами; `evidence/track5` остаётся историческим результатом bc0b1620825b53fd3a3019623326ebf68cbbbeec. Новые PNG/доставка проверяются через runtime ЛР6 с включённой OTel, включая память, recovery и трассы. Статус и наблюдения будут дополнены после фактического завершения команд. diff --git a/evidence/forward-published/quality.txt b/evidence/forward-published/quality.txt new file mode 100644 index 0000000..e9ec831 --- /dev/null +++ b/evidence/forward-published/quality.txt @@ -0,0 +1,14 @@ +date: 2026-11-06T23:35:28Z commit: 97feb04b3f2a6008f636e1fdbdf284b1c97282a1 +environment: {"COMPOSE_PROJECT_NAME": "mtusi2026lab6", "LB_HTTP_PORT": "18086", "LB_STATS_PORT": "26085", "BASE_URL": "http://127.0.0.1:18086", "NO_PROXY": "localhost,127.0.0.1,::1"} +$ make check validate lint +python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +.venv/bin/python scripts/validate_openapi.py +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. +.venv/bin/ruff check src student-tests scripts/obs_cost_summary.py scripts/obs_cost.py scripts/obs_incidents.py scripts/obs_recovery.py scripts/capture_evidence.py alembic scripts/scaling.py tools scripts/probe.py scripts/limits.py scripts/lab4_scenarios.py scripts/lab4_seed.py scripts/upload_memory.py scripts/reconcile_check.py scripts/reconcile_track.py scripts/make_images.py scripts/pipeline_suite.py scripts/pipeline_evidence.py +All checks passed! +.venv/bin/ruff format --check src student-tests scripts/obs_cost_summary.py scripts/obs_cost.py scripts/obs_incidents.py scripts/obs_recovery.py scripts/capture_evidence.py alembic scripts/scaling.py tools scripts/probe.py scripts/limits.py scripts/lab4_scenarios.py scripts/lab4_seed.py scripts/upload_memory.py scripts/reconcile_check.py scripts/reconcile_track.py scripts/make_images.py scripts/pipeline_suite.py scripts/pipeline_evidence.py +216 files already formatted +.venv/bin/ty check src student-tests alembic +All checks passed! +exit_code: 0 elapsed_seconds: 0.590 diff --git a/evidence/forward-published/source-inventory.json b/evidence/forward-published/source-inventory.json new file mode 100644 index 0000000..c7c1f77 --- /dev/null +++ b/evidence/forward-published/source-inventory.json @@ -0,0 +1,1974 @@ +{ + "source_from": "f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071", + "source_to": "c7b8feb805d151e878d77b0dff47320a9436b172", + "target_before": "237a7c93e507b984add5b49c51c6720a6bfca505", + "files": [ + { + "source_status": "M", + "file": "AGENTS.md", + "decision": "not-applicable", + "reason": "Protected target document: keep lab6 content.", + "source_sha256": "dd8b55fa4cf24f4ae3c914c8f884b799452019c87c57afeb01ea5818fd067813" + }, + { + "source_status": "M", + "file": "REPORT.md", + "decision": "not-applicable", + "reason": "Protected target document: keep lab6 content.", + "source_sha256": "ac6e6d7e1005f814e6059b8848fa83ad278f75c7adc8ee5412fa025c8da21ecb" + }, + { + "source_status": "M", + "file": "evidence/README.md", + "decision": "not-applicable", + "reason": "Protected target document: keep lab6 content.", + "source_sha256": "beff30b6dfa0f7e362e6e7176db09528c8c725952f3a96baf1b7ca62dd840e16" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/RESULTS.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e4dd4dfc47ae8095458028235b1e89373b815edeeceddbd09f116f9ad9f4450b" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/active-changes.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b817c4f054d652d43cc5b0059aa3808fe18d4a4582a3676c34f0d9418efa992d" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/audit-files.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "864e3a7032755da30afeef71431649e87c955cea4dc48021c14575b5ac243ded" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/audit.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "68e3f1a5806fe4b65f1e8e8efe0b66c5e55cccd4ce492b7a325d4cc89323ca69" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/build.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "62ca4051248a5ba0c1d5380456dc972572da8c08e27b840992b24f500ab57bb7" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/checks.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "6a1195478b3eb211d21352cb6ed00e690196ccc54e0db3a3fe3ac4e5f6b19336" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/conditions-after.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e72877504561b2e4ab95ffa5ad2e616ff3599ba0887fd10b378f9425cf62376c" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/conditions.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "c970c484ad92ada00d33f4df86113928b0ef0321b1b7740441a8c1e10f4b5c30" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/container-events.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "bfce3b6295e23ea06f4f29beb1b83b4a5b2ec5e07c4230d3ba68d1dc0c241d39" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/down.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "0b80c02939c9224df3e8f5f98ae6320b6ffc71a8a28c001e7b3ee9ae113a6f39" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/env.sh", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "fa41c289402a362827d3edc88bd0e8301e55d279df09f658f800a94bff96b05d" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/final-audit.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "2c6308899417e6da60875de9c262828fe7caccd30bffb223d8ce53635f5845ad" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/final-checks.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "7405e049b92aa01667afe431a64e3c6d5ffc1827c03a4bed480a5158802a08d8" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/final-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "dd5432219d35baeee61392605910c2864b71b83e8972377254eff268670422c5" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/findings.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a2b9cc2a425aa0326fd72c6bdab9a5dc69ea4d90fef2c3ce239fbbb514e978a1" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/linux-child.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "c293f49bd273fe7c3c6bb0ac90f2ccb28a02117a4fdae758d04e8c006d4e89ab" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/linux-runner.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "680052df464d87d97a9717469d53d27f4f2391f740b0aaa23fa52a77a52c9a83" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/linux.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "febd60518391e7d6f479908e48856a6c0a774fd5763f33cf02655e414d6b1fe3" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/linux.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "51f31e560852514bdba1777db1ceade9284ff13610d60afaf7a128f171cd7b29" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/openspec.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "dc82d21ab66012b5960a0f76e82eef10d7df082497119d18efb7aed5009efd3d" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/png-boundary.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a6452fb7b502597058641878464ee383eab334b0d77377bfe54565aeb4279df1" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/png-boundary.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1aba30dc29b1bae3f7e1d8fb64a7e331effb85fa45a2f3a123ddbe7dd743c6ad" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/png-http.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "0dab50ef2d4ed22425d27ccdefaac316ed4b8c7b0a759c2c616eb9239ebba618" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/png-http.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "68ae6e09e67a9df204f0346ebec3b9b185bcf2c67a0a0946aff620408ba867a2" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/reset-worker-peak.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "97c9b5d430649b61f83fb7904414690f50e742b0b53e39c9b4324d60c1b6b2f9" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/retained-volumes.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "27347d997d6f8466d94b0a5bb06350f183c5e30ef9ad2c3858cdc24a316bf5e4" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/running-containers-after.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "44b284098615df613f91d9bc745f236f6ede62f1ea95a9de06e10ed712ffb799" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/runtime.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1f35a3f37a7e4d4689c8154384b08c9800077d4f77251d576f03921605a28b2e" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/scan-secrets.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "27130687bae2d636d9780759559524b347ec3733aa2df722c837378f2d2f39b1" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/secret-scan.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "27f7763fd6af6a10d3ddd0c8ae0a3f71dcad4eeb000afa5af5379bb646fb8e30" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/sha256.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b94290d5b6ba036aecc91a365f94f3fa0fe38ebbe94ac97829067ae8fb9f78aa" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/smoke.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ba0b81113210431ecfe0a085024efd650b4963e1eaf21b2837f6163523a70afc" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/stopped-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f543710a6a0f639673d62148635409ecec6bea71c8987dc036017d4692505bed" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/student-test.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1cf669fbca4aee91e87e74089522325f7214ad6406c031013a73c8b935593ac1" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/targeted.py", + "decision": "manual-port-tool", + "reason": "Executable probe logic adapted into student-tests/tools/forward_runtime.py; source results and fixtures are not imported.", + "source_sha256": "cba7c461fded4eb88247f113a2328780fe985a3c1bdc27a26df47277a2374ffc" + }, + { + "source_status": "A", + "file": "evidence/final-memory-validation-2026-11-07/up.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1fd736cd42363f734649be3011f92abee46bc9210b4fd513aa2daba9d5f4a666" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/RESULTS.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4d918715650d58f320e0884b17c1d9e32276f07c741d515f2c10ee5f18c583cc" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/active-changes.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f75e218e916653ad195abc458a187238930ee0cb74b3dff3bceff633f63b3a2f" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/audit.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "6f1202bc4c225513a3cf65f4661f57dff02fa03eb1d3b30e15221096e31b4344" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/build.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "12dd0f1dcb5aab6a5ef66aa8aa88466f35ed5d4e6b46c01c4048ef269d260d1f" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/checks-final.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "c3c7720032cb1ddd357056fb5ceffd481d5b918ca2c618570fef2276341713c4" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/checks.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f04184507396267b800955824155b4adc52fc561ca7c4427b195b0a28ef0a78d" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/cleanup-recheck.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "dc6162f26b2aa3ec219c2a323bd38fecb7700e10fc1ac26db3b73c6df56c8442" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/cleanup-recheck.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "238e1c1d2eb739b105f621198c1cce3614d1cbf5f7a01ebaf30a9edbfc84fa93" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/delivery-targeted.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "087921045c843d5ef6b9519ad23ccc4e35fbafa8d0b526fd17b57f2dcc89f2b8" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/delivery-targeted.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ab62360225b4cff3cd99f51abbccd637101699070c4237d672cb198b77a5f9f0" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/down.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "994c14a80ffafc46a7a51b16af856cbfdfe4bc518ade4b0d85a1809ed4cf446f" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/env.sh", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "06cc16c51f3ea5fe5bc703a1c4c44901a1c079a452c4df57e723f0f30f7b666a" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/final-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "eca334ad0581d40039451984bbd5a294adb3367a605f75366b8dddd946006be4" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/final-doc-audit.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1bb59e2139b15012e1050a5f67c9cbbb0be886173e7201f3c612c48f8158e0ae" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/findings.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1bee1d38c4975c2a5b282131de001a7406751e2373ce29908ad49baf64754f83" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/fixtures/gray16-40mp.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b59784ae916d50b41b15afa4bdd474a8699f099da55efd53580d3f97180f3800" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/fixtures/gray2-40mp.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e1238de6a5be9dbce36abee904f7233f8ff7be59e405b528671940630cce11f6" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/fixtures/gray4-40mp.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "64e665928c08ac3721324af4f8e2e9d2e98230dc1be389dde7bbf365650b08cd" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/fixtures/rgb16-40mp.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "3c4418a6f6a7676298b30b70ebbde9d12929f1345152f4fae979caf5ba1cb3f7" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/historical-hashes.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "865452375e881103a36f9991388a33ae20ca957718222e474f50778bedca53b7" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/image-runtime.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "89b07842b945ac8873e6077a51782be7642b9f36e3fc45bacf5e2811ef1bd90d" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/invoke-probe.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "fb4a472315b5b08fa8b312868241902cb3ca827ca4af8fdaf7aabac57722476d" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/openspec.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "87a9b001f1780bca8d822372eb43d8b1b6225b66380a235c573a8c12f235f033" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/png-http.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "8871e5adc7c030edaf8357807597e8f38045d24ca6e20825e73864392451596d" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/png-http.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "bf399ba45062574f2c7295dfb5255cde84065b2c621d34e91c0682c96ce88c8f" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/png-limits.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ead7292827f5da0bf87e7d2209c5db26738361b61332b5ae2dd1855a3220f89f" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/png-limits.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ec52bf98f582f1db46a573ab2c8f9097108adb55ec8c5ebab653fb22a45ad216" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/policy.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f47b54dd4b522870ddd464d62a0076bd4fdd7793506834af83167af4d75738b2" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/postgres-outage-retry.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "efd5a60a6d8ac1f0b927f8e4dae35183444c887b12bbc76efc589d4b60b3b608" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/postgres-outage-retry.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "48191931290985ab5ee3a4f606f5871e751af74d92262d9a95375f845a8e528b" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/postgres-outage-worker.log", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "860a8f2c3a41efa2068cd2c0f614c02e605af50b12f13118c0b4f8bba5d0949d" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/postgres-outage.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "6ef2b1a692692d073d5095e308633a57b3f8b77c907ef2a005c3de7405bd03b2" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/postgres-outage.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "03ae2413b4d24ca545fe7118dfbca42e19c787df082085be09b57881e8c6ef3b" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/probe-copy-fixtures.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f0e163372b70e3550047572dc5d293c73fb971fcb22e84570983a98d41c21297" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/probe-copy-script.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b41b5bbc44740bf143c6a7b3ecd0a11b5278be0c7949085c329c124837a1dc31" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/queues.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "269a2934d5b03d25c1028b1677dc7a57b7444bba646ffbb46d374473858cde9e" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/recheck-cleanup.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d976b607d40be26b2fc9d2ed1a330bc517b099ffce10eff0756629f85ab30a44" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/resource-probe-retry.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d2ce23c775e6b460c16ef30fb9ade683508c05a5cfbf700cb2f8f2b5f30ded47" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/resource-probe-worker.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e0fd41c717ef20143f9b7433197ec4007c23bcb047a20d6f884eda7ba47735f8" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/resource-probe-worker.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d3e1e5cfef280cbaddbd915ffee91a109ddf2e19e7fc4771333b79826b95e587" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/resource-probe.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5ac1b3087a22ce8c9b0d3e988b78a8c5ae385436ef5b8cdf2ccb57fe1a0a0359" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/resource-probe.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5c4dc9697e8bbfcfd897375ec346c48ade105bdabc4a068406785eac89056df0" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/retained-volumes.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "dfa358841d4bd6258e01a9d19756596ccfafcc64338a2f1336be41db557ea1ff" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/running-containers-after.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "aea44e7b644394fe4dffc8d50afe64ae3189f9c0d1221530e6320e095ee9bd1b" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/runtime-containers.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "85da009405a52ea1654d6cb396ef9b7a16cd50c37a09888f3ff9c3a358255b4b" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/scan-secrets.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "de87d9de67d0d8addab791b45725b8afe96dfb3bf84fa1d6bec46b7850494e79" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/secret-scan.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e8d73dbc0b91a8545907368c8e99b5bd16dc0ed6e89a9c46c03b59bdbb9fc95b" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/sha256.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "226b8207061baa9b5fb2609bc7bce355f57f40caef2e7b488076000ecb486ef2" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/smoke.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f667f89d95ccfc52ac942cae11c2cdd6bfc8d1a192eb9cdf1b24f3ba02a8888d" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/stopped-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5e32c5318af95dd450c8bd7420c8cd87e7c63a54cfef0e87d1e62aeef4b73771" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/student-test.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "299662f32cd80c0c69e1b4f281b97a38c9d81c44be2501dda6a3be02df692ab8" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/targeted-initial.py", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5ccd725d3d07f82d53b8ee2f7f3614cd22f354891b6c220cb5572f8eb94b64dc" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/targeted.py", + "decision": "manual-port-tool", + "reason": "Executable probe logic adapted into student-tests/tools/forward_runtime.py; source results and fixtures are not imported.", + "source_sha256": "0ef9974190761b0226f0c87ba3196f360fa0cb7f9761da14790da0747200b871" + }, + { + "source_status": "A", + "file": "evidence/final-validation-2026-11-07/up.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "8089a2eacd964d323f040fabee30988d68287b86bffdfb107b7a231b63b4b914" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/RESULTS.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b2eca55648633e5e42d949455cd7f5c9d5483dc322f7dd8f429a3cc061179cc1" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "54bc70e53d69969580bd0c88f373778f2a029e2329bbccac7844ff16055deceb" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/baseline-regressions.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b0525cea37ce47958dc95e02866c1f014239a6cc8500cf76bf448d2b4f1423c9" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/baseline.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f6520adb750693e1c7ad31cdad2d1de327a302d15a17a763a035f35ea5b759f5" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/cache-outage.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "fbe1eb591256b35a93a8fd3f4fb299caf22f57159f0b68c984f7c75e5e8be9fc" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/checks-before-commit.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1b8bd42a69e070cffb07e12449ec749066ec92407fa5d94bd8ad766f40d93dff" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/checks-final.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d0d3a9f7a24914365c772eabceb4ad2238c5922e30c866a26c5274f8fb570e81" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/clock-observation.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d7ae11b8c7970cc71775f46fa0a1474e113da4cae9229d8f28bf85312dd8acc4" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-before.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4ef9320729dc38a49b7e8dc3338a862fd69946ceaf64b4aed004bc6ac23ab1cc" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-level4-middle.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "677c0e3499a45daf06cc5bc6f46338ceb873f4203ae137b8cb1c9606f13538eb" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-level4-start.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "0cb8a9314b3afd4704c762b1b611f80beb9f30795475642ad2a22452f87993c0" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-stopped.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5ed4cc9e6c6969cd16b699a24ac747c7b4ee4c8b189be2f57cd610622891f00d" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-track-after1.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "65e7d5a4652e102e6ad8ecbf74356b1c468e2d5ddaee492af21432d646aa4bdf" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-track-after2.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "fa3a1808cc215afb3a422fe582c2d4cae5cf480411f4150977be30f9e24bf462" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-track-after3.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1054464f5526ee719579fbda81b9e7605a97a660fec9bdfc52f6e68ce94cfad1" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/conditions-track-start.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "64e99f2110c3ccf029fba7fe30bd1c9f01615cb5b43ffd77fe4a0f09e7030245" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/down.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "9dbe77c3dc7b1a17798bd117fd1c8b4cb9ab01a6122376ca5ab38d147ac7b9ff" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/failover-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4468a88f349073027fb07b2c81406e480e1b503b64fb828e58ecee688d7b2091" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/failover.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "fcd1b67b77aa7936f9f0ae1c48982e9e4ad9f2e8b9705d2b856ff8cf360fdaa9" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/final-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e2ea3d831281e9cc6cc9b03ea1f00172e4eda23fb7244b8d9b60f7d211b5ec64" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/final-smoke.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "eec6f2507465824cd920fe78bf876dfbf8b905e84ebcd7b9d51e80d16d4c064b" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/findings.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "2f0db619bebbc615dc33f78599210201e1d9441139adb33687dea7a46fc1f15b" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/forward-audit.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "675a9fcf1fb817bb043c8bcde35079617294da9c7832a529c4d7bfa2adc8f52d" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/haproxy-errors.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "bf3b0b33f997fefc542860389e8a0fcc1856bbb17cd25b6103911610e87806a3" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/images.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "adb50435b1c24cc0deb913c49ed19e3fdd4287b73719d418accad013ebb7489d" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/level4-command.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "2b9e49afc9e9ec0e8a8f2a3c491906b72c7439b4a2e30ff6ed0a96d9be4c73ed" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/level4.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "904e2c40a6737947b1867c9051a36920c007f49ad59de057a168c1dcc345d87c" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/lint-runtime.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5e3c5752c468b6f747e4dbafd91954660f8b80f820b63ff34704641e7d5db970" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/network-regressions.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "30f0735c6d0bd2370cf39ac6855c06750ba18b282b978dcf6dddcf293145e02b" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/openspec-final.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a34016edea7844300b98aaf38e713df8b4b217924b515881b33a599cd1603b24" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/persistence-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "229bf4c9809cf0e6a1d9cfd162949b413d7f990f57a30fbcd5f9c5b6e3f81e92" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/persistence.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "06574967e1dab9742841d54cabb7b0109aa063316e08c8db5525234f084f92de" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/restore.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "96805ba0f8cba25cb90f385809d0a0a6c75b468a25f87006d729fedc51759c7d" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/retained-volumes.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ef4b62f79ed1cd0dc1e7313d65873c6a6ab35ff933bd8673a3431d3df5691449" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/smoke.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "709ddeeb3aa1c4e0b516d4b66038b0421929ee519665d79feccc907cc7bc89ac" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/source-inventory.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "8977c7883b08b4a2ce7385ddf1c8da11bb4344e586dc71ba637118fcf9d8f506" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/source-name-status.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "81abf426ff31f0253a5ced9ae43fdbbf2a56460afe7b5d299a32c6f664196b93" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/specs-validation.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "79fe9fdb0bb258d6d7788a79d96587b748233001e97f2acd38bf9bfe0376d515" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/stopped-containers.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f7ac8e8c29b18a83193a089a2dd75aa0dfc103e54173e2421b853c00a0113338" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/student-test.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "2976f98e550a14ee2c385f8a1b34a37626fdc602dfc6f848fbf81b0f105834fc" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/summary.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "406cea849c5a294a7a744e18056ed54a554cccdf3f5b1133d580ea67cdc1a57f" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/track-run1.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5e90e87bcbf43115df39a37b95f50141772d92e3005f445e1a0c9b5d04050ad0" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/track-run1.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "7966b1f45232223055f58b0031a6eeee987d42d5789798ec17df711f40c207ac" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/track-run2.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "16fe12bd42f958a0d4962182da65bd4ee69e4b896fbce47daea724b0a1c618e8" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/track-run2.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1ff4b753ab5627ee5393977203d5dc83f59d4c9e990e7171fc63a06061ceecb3" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/track-run3.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d190b7a1b4962c520d46931dc63601ed2655f1b4063bc7fea01b78b049a0bede" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/track-run3.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4b8254db242784c6db3a0db7a8e363269a1aa486a1b26caaee254100f1ab0a52" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/unit-regressions.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "26d5cf96bdf415c5b17fe2a596b9228834995418b1b33a83c146f59617debc5a" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/up.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "0baaa49727722eaf24ac4d8b3e083c09bbb53e278e557e42551221d0c59e5856" + }, + { + "source_status": "A", + "file": "evidence/forward-final-2026-11-06/upload-negative.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "6cb7ad695b0715a2865e81d113bff729bf98d106a29c419e2ff16f7ee067c4b8" + }, + { + "source_status": "A", + "file": "evidence/forward-port.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d4d48ed1fabf361e35737b2d271a079dc222d0da52b8f38c0e96731aed036f53" + }, + { + "source_status": "A", + "file": "evidence/load-validation.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "59d29c9ca1978dab6d6bd92ccde5ad67bf62668767283b2a31d9f79ada3a840e" + }, + { + "source_status": "A", + "file": "evidence/report-audit-2026-11-07.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b7a27515584dfb6b55655047af3ee062b62742b88152b2084bf6a8a9160722eb" + }, + { + "source_status": "A", + "file": "evidence/report-memory-audit-2026-11-07.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "451bcba2f8b5061673938a61e2627a42c5ea55aea581b6f3ba3773dac3173ea0" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/RESULTS.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "6f77ba7437db67ba7005b19ac657ed0cde917b7728488fc59f517b13f57618d1" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/active-changes-after.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b00cf723b88fd2254414abeb7b15015c4fb94a28303b44b59ea542fc57bbdcda" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/boundaries.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1e326b4f56c3766bd4e38495df7fea6ea9e0b23f9971d64cfceec7a3baad0290" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/check.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/checks.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "aeb272dc50e7791036cc37648f23475a9eb6571e9aff1ab852fea4480bc8d1f6" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/diff.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/findings.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d04edc436e8b49203921c01256d887153a198362e276131aec35bd1ed5334546" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/lint.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f6bf28d4d929c359f6c7dcb5bcaf0ac82db5cb2717bb4c06e1cc1699c1f854fd" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/openspec-after-archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b185f34cf979a6739249722b3df8000dcfbd0618b424dae99130e059d7cd20c7" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/openspec.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "838cead6f8f012007e3550202e2c1990c12e82a16035ed158e89ccb94b5c9cae" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/regressions-after.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "54b30c93b5a15f0417a80917e8fed491c2ff7813b4ae0477d108607ee1cfbff9" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/regressions-before.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4234bcdf1c0de9fa1c9783f68d98cd7d11b665e87e0073ebf8f08f9277955e2c" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/regressions-fixture-error.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "8af096b48dcb260f48f746989f1f587c10201c801f805ba1eabcd54141c212b3" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/unchanged-rendering.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f034c3f9c459a13301fa167549e7727da733cf33df822bd1e189a6bf9b78dac6" + }, + { + "source_status": "A", + "file": "evidence/review-fixes-2026-11-06/validate.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "422aec45ba93e5567e0de199fa32116a48c970ca3b82738b40f0ed7681ef621f" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/RESULTS.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "22ae535500e9aa2479851a139126a3e36143eda3e55022ba8df44a834eebc660" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/active-changes-after.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b00cf723b88fd2254414abeb7b15015c4fb94a28303b44b59ea542fc57bbdcda" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/active-changes-before-move.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "99136b09ad0ffbbdddc938f0ec5ffab8b4e2b29b7311c44f55a5cbc72d0b7f1f" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/boundaries.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a4d0778a9ba058ff75b48cb3a145ac59e8c7ae9f3764db8fb6a0425c242bf8d2" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/check.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/checks.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e6e02b0d179e47434fa439c953a0518f002794fcc37a57d9016eda771a61d2ad" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/compatibility-command.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "09d5bbe4568422aa69917031cf1e6ba8ccc3cf7f241ac88343812f8bf231176d" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/compatibility.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "bd3bf1841e476fcc62d6266123bfcf21dc259bf89160a4dda31ba301f429c57d" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/findings.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "449ab0c9fc33060b54310c622684287525c5508204a47e7aacda1e44dc77b037" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/lint-archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4d6c5ac9c907f1066911fd027b328c8d9038ef46ded69c392c54d9f8d27d4865" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/lint-implementation.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4d6c5ac9c907f1066911fd027b328c8d9038ef46ded69c392c54d9f8d27d4865" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/offline-tests.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "9efe9e43fc7e9d7a2bde18e3d54efdeeb2387a1081457ef8b2615451f2583fe9" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/openspec-after-archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b185f34cf979a6739249722b3df8000dcfbd0618b424dae99130e059d7cd20c7" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/openspec-before-archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "360f59e3eb964da51f37ce7c00637e41e835670a5c657b2055a496f2f36a76f9" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/openspec-before-move.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "360f59e3eb964da51f37ce7c00637e41e835670a5c657b2055a496f2f36a76f9" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/regression-before-command.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b3a571ede4d8fe5239bb3a3f4bcb1a1d9ce257d1e580f4aac64cdcb178cc41be" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/regression-before.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "02649ec20f6bbd4ec299d457f704d3c1473eda82b6da7b9808a733fdce947123" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/specs-sync.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b185f34cf979a6739249722b3df8000dcfbd0618b424dae99130e059d7cd20c7" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/static-audit.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "4c6b5bb3e410c6df9a21037313828cea2b0393de610b94646f27bde3c22b9cf7" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/unchanged-rendering.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f5bf484467198d9cec40affd97c42cfcd0a37c40c49a20ea604ce14babc292e8" + }, + { + "source_status": "A", + "file": "evidence/review-png-memory-2026-11-07/validate.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "422aec45ba93e5567e0de199fa32116a48c970ca3b82738b40f0ed7681ef621f" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/RESULTS.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1dc297dd094fbcc7e6afa6a5e8409f15e5d042fdcf10a759ad1662e8271678f2" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/active-changes-after.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b00cf723b88fd2254414abeb7b15015c4fb94a28303b44b59ea542fc57bbdcda" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "99757ad145b9ed6aad77b916af9f323354eefaeecfcf662c5e02ac48446ca7b0" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/boundaries.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a4d0778a9ba058ff75b48cb3a145ac59e8c7ae9f3764db8fb6a0425c242bf8d2" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/check.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "5f42d25d7cd8c1d2fb31ccf28a2872fbb91d38ed094024181e5ace9671667ee6" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/checks.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "cb0927da733d3d976e0ace5c332d80fa77a7671e2a390dc89107f274741bd9ed" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/compatibility-command.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "95ba9053755205121bb9682c43a3ed3133576c925e7057d61cfdf46763a90629" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/diff.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/findings.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d04edc436e8b49203921c01256d887153a198362e276131aec35bd1ed5334546" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "cab4b1fd18b190d9f4ceaad6c86489b4a202ab268a5f8dfc8bd8d872c95c3885" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures/gray2-white.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e7fb8f48857222f73ff511b4c154debdb412160f57934e9d689f6effa11876e2" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures/gray2.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "80754a3aa0c8a6014dc7a282b2009d49d064a5c02ed48e634d05d01c0aa3df6b" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures/gray4-white.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b0134c845a567491cd53a9bec3ebe8696ff1174b74b8112d6854fea3067c5cff" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures/gray4.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d0ed5b64b3b875be881dd286bedb7948fd06570f9ef1d2cfe41b665a838e426b" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures/rgb16-white.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "735cd3ea79092d8372f203c00ab6c4d4e8d8ae77b9a2d0c100cb96a275e260fb" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/fixtures/rgb16.png", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "e8e5f64cf3a0312b17549aed29f062e3cb03d0c1bf327396c6a25c4b88dec89f" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/lint-initial.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f85474c18597cb45db0a26970c5af0dfe57c184e7c1c83a938738400613a3edb" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/lint.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "f85474c18597cb45db0a26970c5af0dfe57c184e7c1c83a938738400613a3edb" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/offline-tests.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "575d3f2d3c7e38ddbf0828973649808436411268707a8fc0dd37d325c6e4877a" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/openspec-after-archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "b185f34cf979a6739249722b3df8000dcfbd0618b424dae99130e059d7cd20c7" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/openspec-before-archive.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1cdcfb042fddf70093f6370e0a253eac7f8c2aeae60c69b671577f948af41a4f" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/regressions-after.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "baa3a9c25a43343f5d6b627ef218bce4ba9996cf7a0b83131021391d3e4665c5" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/regressions-before.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a2b54cc35e5429210a9bea1845546c990d0a39ebc04c86b5ad60198d2f33c75e" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/staged-diff-before.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "992f54889c56c5f13736ccab6bcec4febae09bad279a9fc0cbefee2e72484579" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/unchanged-rendering.json", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "a3d3a30a7c410708bfd3bd4546e23d6f1b0db73dabfbc9766d445b09a1db8f6a" + }, + { + "source_status": "A", + "file": "evidence/review-trns-depth-2026-11-06/validate.txt", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "422aec45ba93e5567e0de199fa32116a48c970ca3b82738b40f0ed7681ef621f" + }, + { + "source_status": "M", + "file": "infra/haproxy/haproxy.cfg", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "50a0f551f0d77462aeb25354ba72fcdc49ef2503b92054b11888f680e6245e04" + }, + { + "source_status": "M", + "file": "infra/rabbitmq/definitions.json", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "91c430622ed4f4d9c446d9c81b70d1b431fbad87c18b3dedd1feb34454d4b2a8" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-fix-png-trns-source-depth/.openspec.yaml", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "42fbead5cdbd3e909d4fb714c4e8f9cf79c38c118b1efc7f0fbcfb2628fa6a2b" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-fix-png-trns-source-depth/design.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "52f3afbd1cbd0d7fe25457e3313111a17c9b08708f7ac6936a53f38249f52d88" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-fix-png-trns-source-depth/proposal.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "3810677c8b7bb6f013475418cf71ad260f3b4a3846a5d7b4cf6992bd9c133451" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-fix-png-trns-source-depth/specs/lab5-image-variants/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "7097ec082eeccbb1102e8fe44b29a42f041d44e58d61e88e003779e86310b945" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-fix-png-trns-source-depth/tasks.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "08a0ff877ce46322365a3d900865b460b2214234e5263e62726411b5a22b1322" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/.openspec.yaml", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "42fbead5cdbd3e909d4fb714c4e8f9cf79c38c118b1efc7f0fbcfb2628fa6a2b" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/design.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d2aff5d9440f00332329d24f741092dd4eba04026b861143bc785001a7421308" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/proposal.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "42a8ea4a2d5772a0bb730cd0d6ef88076921cba47bde07eb46f3e222929d4749" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab1-messenger-chats/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "873563abca0a2cc15f76ae4d9603ff389e7ee1bd61e2cae14709bb23f33a9dff" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab1-messenger-history/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "1080460b82efe41843a746ce89a219a598c7f2684a42810dc8d0de5a63185594" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab1-messenger-identity/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "7e85df0d8d5564bdac1e23f1b8b456d1b7c6b562dd731c86c9c03f0b9ed87756" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab2-auth-sessions/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ba19fa49f8e61f206a7887e750b02f73369ac2f4130280f0ed34957ae205f52d" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab2-session-cache/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "73119d09886aa84203c95272ffd2e417dc03fe7cc6148e23ed77f9a06864f7b3" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab3-load-balancing/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "72794724ba16300769584d13c50148e9ce6cb2780228e627981841ffee6ed552" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/specs/lab4-attachments/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "72cef6a5cbd396cb4406b0514b4368a7f13e434b101fbb76ec0f1b80fdcf9640" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-forward-lab4-final-review-fixes/tasks.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ee2d5cf821d3b53caa55d2ea8405a49a515e738ba237449873185371b45e80a0" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/.openspec.yaml", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "42fbead5cdbd3e909d4fb714c4e8f9cf79c38c118b1efc7f0fbcfb2628fa6a2b" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/design.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "ca1ecbb7590325dda850a0d4c41acdd6a46fd7a7f20e647be34b329a254f8ae5" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/proposal.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "318cd3dc0365ca95216c927671fb91811e1538670c596b0fb5b3d2dfb633d273" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/specs/lab5-image-variants/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "23514943f386cf9109f727d3862c022d8c88c46944775c54159082f8c7ffa1cc" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/specs/lab5-job-delivery/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "338969fe734c957dc4c566787af57f0703365e36dad1c1088f2792c505f22913" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/specs/lab5-job-recovery/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "135643fb7d598d4dd13ce634c76cc780962019a9a95c27cd480c2cef925b147f" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-06-lab5-critical-review-fixes/tasks.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "9139e28006f967dd5b4b1826819230f5561ea4260e2d799713ed0d4b6be143b8" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-07-fix-lab5-png-memory/.openspec.yaml", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "273fea3c6a19b7108aad9607468b03a0a122e03d8660eb157f3cd8c7e4a46737" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-07-fix-lab5-png-memory/design.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "bb5f6cbafcd3828d7e81ff14954d04bc22ac42668c71178ea5c62a6baa08f72e" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-07-fix-lab5-png-memory/proposal.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "d15889bf0f14b253009c072048b1822dbe8e08b8a230a0d1939f817939139a37" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-07-fix-lab5-png-memory/specs/lab5-image-variants/spec.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "8686927a82a34a2b40e948a6680d0f360b1748b8ce87f8d883ef2cca70bb9a72" + }, + { + "source_status": "A", + "file": "openspec/changes/archive/2026-11-07-fix-lab5-png-memory/tasks.md", + "decision": "not-applicable", + "reason": "Source-only results/workflow history; never evidence of lab6 runtime. Behavior requirements ported separately.", + "source_sha256": "67dd25059098324246d13204d36c553e4b91f32d6a7efc5da7abb5594fa8b040" + }, + { + "source_status": "M", + "file": "openspec/config.yaml", + "decision": "manual-merge", + "reason": "Only pinned versions and provenance guidance; retain lab6 architecture and rubric.", + "source_sha256": "83ac1f4961c4d64c8e2c37b3a44540a5f71ba0541eb92d1920c9278ffb00fb41" + }, + { + "source_status": "M", + "file": "openspec/specs/lab1-messenger-chats/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "0b675070ab7419274ef5e8f1b45f06fd95c34a71ffbb215f04694ca311639609" + }, + { + "source_status": "M", + "file": "openspec/specs/lab1-messenger-history/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "c7029b1ce2d42852ec753264c00ed3a7fc8699137d1bc0c8e2db6f90a564b5a2" + }, + { + "source_status": "M", + "file": "openspec/specs/lab1-messenger-identity/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "d3bfa4f488d83e3fef064a028a6c4a9e89994d624429e78c3fb13e563b33fedc" + }, + { + "source_status": "M", + "file": "openspec/specs/lab2-auth-sessions/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "7def2e21da83bb6eeb9f8ffdef059027a30375cd70e537be9a7b12b2ee8c7f62" + }, + { + "source_status": "M", + "file": "openspec/specs/lab2-session-cache/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "a47c6c8c386f62231da9b7a52e62f5cd8f60f818f9a1180b9cd2376597696693" + }, + { + "source_status": "M", + "file": "openspec/specs/lab3-load-balancing/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "e89cf4188e74649c4577f0d18f83faf6e77f67ee7b438b5e040a1137fa6c88b0" + }, + { + "source_status": "M", + "file": "openspec/specs/lab4-attachments/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "40c4294f7e88917f00500b8b2f162af2812f58a4347f43654b44268f973741a6" + }, + { + "source_status": "M", + "file": "openspec/specs/lab5-image-variants/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "5473601ca6d24a244e7c5023466a2bb5708ce16a46415bd81b35fe5e5baed578" + }, + { + "source_status": "M", + "file": "openspec/specs/lab5-job-delivery/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "75dd3a0ca227838b6b05758aab7c8d43986e811e3621b282565dcc7846552a08" + }, + { + "source_status": "M", + "file": "openspec/specs/lab5-job-recovery/spec.md", + "decision": "delta-spec", + "reason": "Merge changed requirement blocks through the lab6 forward change.", + "source_sha256": "82f1a37c9c01555fd9bbb0e5a3052c0ed06fc90cbdf5354db43f2b3c6cd3219b" + }, + { + "source_status": "M", + "file": "src/messenger/attachments/infrastructure/images.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "97c6e9c1ef13c8854be9cd2cc11e4279d1d340ba3ab360dfa3e05772923ea743" + }, + { + "source_status": "A", + "file": "src/messenger/attachments/infrastructure/png.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "50491204d8a3667371962f43830a2b53a8b478b5941238a8db211a8a77cc57ff" + }, + { + "source_status": "M", + "file": "src/messenger/identity/application/handlers.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "7ef32d82c687045613a12ff4d3a66376bf942ac590697f9390894b01fbc3b8f2" + }, + { + "source_status": "M", + "file": "src/messenger/identity/domain/values.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "407688bf7516c617365e021ee61abffb51e462c17640062a66a636cc25c96534" + }, + { + "source_status": "M", + "file": "src/messenger/identity/entrypoints/authentication.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "ceaf2bf6a639fd8004de101372fca37b32f13ee6cbc6e0c159e871cc54110c6a" + }, + { + "source_status": "M", + "file": "src/messenger/identity/infrastructure/postgres.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "a3c4824c5eeff98e3e5d0769d5c92733ea45d1bcd5735b61cbb21b2f41975bd4" + }, + { + "source_status": "M", + "file": "src/messenger/identity/infrastructure/valkey.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "d7eb27d20c0b8b5c74214ea863fd9f17c64b171e1ebecf9930cd9c458a7069fa" + }, + { + "source_status": "M", + "file": "src/messenger/messaging/domain/values.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "eebba913911ef4c533f1d9715445e1471ad538c3631548ad36c44f4c092e9e5f" + }, + { + "source_status": "M", + "file": "student-tests/adapters/test_rabbitmq.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "d18b135dc387077d9e165169a1b04050c9241349a7bafc2cd92fdf3227593def" + }, + { + "source_status": "M", + "file": "student-tests/api/test_attachments.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "e3eacfad65d93951d40fbb1b2dbe4ddccbde98d9f00c92f82ce72d2fbbc8f88b" + }, + { + "source_status": "M", + "file": "student-tests/api/test_cache.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "ed62c0084dab3087a9d221fb52e2d67f3bc2c9d12c1bb0417627e6bca105a299" + }, + { + "source_status": "A", + "file": "student-tests/api/test_nul_validation.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "f6dbd33aad5463f183ccfb295caa7d5aabd4ced0fbdf65202ef22ed540cadec0" + }, + { + "source_status": "M", + "file": "student-tests/api/test_sessions.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "bf63df875358990a8c6437797f0c56212cd608bddebb0c8fa5454f694118b059" + }, + { + "source_status": "M", + "file": "student-tests/pictures.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "fd2fe8997eaaad05082c7617aa8ece7fca0712117484f3fa3e875f701e5736b9" + }, + { + "source_status": "A", + "file": "student-tests/png_trns_fixtures.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "d8c85786dc8ac581858742cd054235cdbec59cc99b4ed4b163cd3bb73ebecb5c" + }, + { + "source_status": "M", + "file": "student-tests/stack/test_attachment_faults.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "3255caebb58c14bed5638f111eef3c55f35b3f34f9ea453f21f66d4c531d63cd" + }, + { + "source_status": "A", + "file": "student-tests/tools/forward_conditions.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "beca579aebbbf46aada67bb7a42352c23353103b940f9e19ba9080d64433a45f" + }, + { + "source_status": "A", + "file": "student-tests/tools/forward_network.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "19a80def7e5a1e79eca871ea264094f0c643e61d0cb1cfbfad67ab4196c516dd" + }, + { + "source_status": "A", + "file": "student-tests/tools/lb_errors/client.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "7759bf22bbf122b4e1f54548a0e8a55f2ac42e42d8f482c95db2dc107aca6379" + }, + { + "source_status": "A", + "file": "student-tests/tools/lb_errors/compose.yaml", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "b3ba612546cf23bb202456b2935f621d8a9cad43a556f27cfd93807273c3a7e3" + }, + { + "source_status": "A", + "file": "student-tests/tools/lb_errors/server.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "ce779c03f48f1ce671e8c65cc7b8a81d8e765d687de78433e114e5e792dbeced" + }, + { + "source_status": "M", + "file": "student-tests/unit/test_authentication.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "c03b4860cc3ad9cebf1589d0ac1adcde190f6a30f011357bdad219b1ca7cc1f0" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_haproxy_errors.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "d1b76a39608ddf9134b9f48a467c95983e4adf6556a52115c8299bdf3489dfcb" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_image_inspection.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "05e408957a46f4fbdd77b6d5401f0374f758cc8826d7b717f600c91582d40480" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_nul_inputs.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "43f0088c95440fa90c43b40b5ad19db4ffa28bf1a198b385b104495d259bcb93" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_png_memory.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "49d9fa001d82a2fd495e11da5793ec7f42dfdeb7b0929866e6a0ef94a35f440d" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_png_transparency.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "a994a4a3542c0b69a1b5191d3669a0181d216573cb9c61d09a910db73c3a2fba" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_png_upload.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "a185767a118d3a50358de0e27d125efd4a413c518bb25f4e029fbf45fb5b0aea" + }, + { + "source_status": "M", + "file": "student-tests/unit/test_renderer.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "4c70ee4fac2b7430d21682d05e5381b4867f522cec5b764c92c781d9d9e78a92" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_session_cache.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "64be3f10ef6dba6c0258eef1a5cb8b73450da7eca95bdc4d28484e96db160ef0" + }, + { + "source_status": "A", + "file": "student-tests/unit/test_worker_delivery.py", + "decision": "port", + "reason": "Apply source diff; retain lab6-specific context and adapt test fixtures/observer/ports.", + "source_sha256": "3b14dfbc40ca704c67b6f18bba37045dfeab1f45447ec89655e1f260ff33c2d1" + } + ] +} diff --git a/evidence/forward-published/student-test.txt b/evidence/forward-published/student-test.txt new file mode 100644 index 0000000..3cf845b --- /dev/null +++ b/evidence/forward-published/student-test.txt @@ -0,0 +1,78 @@ +date: 2026-11-06T23:32:01Z commit: 97feb04b3f2a6008f636e1fdbdf284b1c97282a1 +environment: {"COMPOSE_PROJECT_NAME": "mtusi2026lab6", "LB_HTTP_PORT": "18086", "LB_STATS_PORT": "26085", "BASE_URL": "http://127.0.0.1:18086", "NO_PROXY": "localhost,127.0.0.1,::1"} +$ make student-test +.venv/bin/pytest +============================= test session starts ============================== +platform darwin -- Python 3.14.5, pytest-9.1.1, pluggy-1.6.0 +rootdir: +configfile: pyproject.toml +testpaths: student-tests +plugins: asyncio-1.4.0, anyio-4.15.1 +asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function +collected 1016 items / 19 deselected / 997 selected + +student-tests/adapters/test_rabbitmq.py ..... [ 0%] +student-tests/adapters/test_s3_storage.py ... [ 0%] +student-tests/api/test_access.py ......... [ 1%] +student-tests/api/test_attachments.py .................................. [ 5%] +...... [ 5%] +student-tests/api/test_bounded_contexts.py .................... [ 7%] +student-tests/api/test_cache.py ............ [ 8%] +student-tests/api/test_concurrency.py .... [ 9%] +student-tests/api/test_consistency.py ........ [ 10%] +student-tests/api/test_cost_experiment.py ... [ 10%] +student-tests/api/test_drain.py .. [ 10%] +student-tests/api/test_events.py ...... [ 11%] +student-tests/api/test_http_telemetry.py . [ 11%] +student-tests/api/test_idempotency.py ............... [ 12%] +student-tests/api/test_instance.py .... [ 13%] +student-tests/api/test_job_returning.py . [ 13%] +student-tests/api/test_message_attachments.py ............. [ 14%] +student-tests/api/test_migrations.py ................................... [ 18%] +. [ 18%] +student-tests/api/test_negative.py ..................................... [ 21%] + [ 21%] +student-tests/api/test_nul_validation.py ................. [ 23%] +student-tests/api/test_operability.py .............. [ 25%] +student-tests/api/test_pagination.py .................. [ 26%] +student-tests/api/test_pipeline.py ............. [ 28%] +student-tests/api/test_pool.py ............ [ 29%] +student-tests/api/test_reconciler.py ........... [ 30%] +student-tests/api/test_recovery.py ............ [ 31%] +student-tests/api/test_sessions.py ...................... [ 33%] +student-tests/api/test_timeout.py ........ [ 34%] +student-tests/api/test_trace_context.py . [ 34%] +student-tests/api/test_upload_consistency.py ......... [ 35%] +student-tests/api/test_versioned_pipeline.py ........... [ 36%] +student-tests/api/test_wire_format.py .. [ 37%] +student-tests/unit/test_attachments_domain.py .......................... [ 39%] +. [ 39%] +student-tests/unit/test_authentication.py ............................. [ 42%] +student-tests/unit/test_cursor.py ........... [ 43%] +student-tests/unit/test_domain.py ...................................... [ 47%] +.. [ 47%] +student-tests/unit/test_haproxy_errors.py ............... [ 49%] +student-tests/unit/test_image_inspection.py ............................ [ 52%] +........................................................................ [ 59%] +........................................................................ [ 66%] +..................................................... [ 71%] +student-tests/unit/test_job_observer.py . [ 71%] +student-tests/unit/test_nul_inputs.py ...................... [ 74%] +student-tests/unit/test_pipeline_domain.py ....................... [ 76%] +student-tests/unit/test_png_memory.py ....s [ 76%] +student-tests/unit/test_png_transparency.py ............................ [ 79%] +........................................................................ [ 86%] +.............................................. [ 91%] +student-tests/unit/test_png_upload.py .. [ 91%] +student-tests/unit/test_probe.py .............. [ 93%] +student-tests/unit/test_reconcile_measurements.py ...... [ 93%] +student-tests/unit/test_render_pool.py .....s. [ 94%] +student-tests/unit/test_renderer.py .............................. [ 97%] +student-tests/unit/test_scaling.py ..... [ 97%] +student-tests/unit/test_session_cache.py .......... [ 98%] +student-tests/unit/test_telemetry_platform.py ..... [ 99%] +student-tests/unit/test_timeouts.py . [ 99%] +student-tests/unit/test_worker_delivery.py .... [100%] + +========== 995 passed, 2 skipped, 19 deselected in 176.45s (0:02:56) =========== +exit_code: 0 elapsed_seconds: 179.184 diff --git a/infra/haproxy/haproxy.cfg b/infra/haproxy/haproxy.cfg index 91d9a2e..9a1218c 100644 --- a/infra/haproxy/haproxy.cfg +++ b/infra/haproxy/haproxy.cfg @@ -36,9 +36,9 @@ defaults timeout http-keep-alive 5s timeout queue 3s timeout check 1s - http-error status 502 content-type application/json hdr X-Request-Id "%[var(txn.request_id)]" lf-string '{"error":{"code":"unavailable","message":"Upstream replica failed","request_id":"%[var(txn.request_id)]"}}' - http-error status 503 content-type application/json hdr X-Request-Id "%[var(txn.request_id)]" lf-string '{"error":{"code":"unavailable","message":"No ready API replica","request_id":"%[var(txn.request_id)]"}}' - http-error status 504 content-type application/json hdr X-Request-Id "%[var(txn.request_id)]" lf-string '{"error":{"code":"unavailable","message":"Upstream timeout","request_id":"%[var(txn.request_id)]"}}' + http-error status 502 content-type application/json hdr X-Request-Id "%[var(txn.request_id)]" lf-string '{"error":{"code":"unavailable","message":"Upstream replica failed","request_id":"%[var(txn.request_id),json(ascii)]"}}' + http-error status 503 content-type application/json hdr X-Request-Id "%[var(txn.request_id)]" lf-string '{"error":{"code":"unavailable","message":"No ready API replica","request_id":"%[var(txn.request_id),json(ascii)]"}}' + http-error status 504 content-type application/json hdr X-Request-Id "%[var(txn.request_id)]" lf-string '{"error":{"code":"unavailable","message":"Upstream timeout","request_id":"%[var(txn.request_id),json(ascii)]"}}' frontend public bind :8080 diff --git a/infra/rabbitmq/definitions.json b/infra/rabbitmq/definitions.json index c5f466e..b30a289 100644 --- a/infra/rabbitmq/definitions.json +++ b/infra/rabbitmq/definitions.json @@ -26,7 +26,7 @@ "dead-letter-exchange": "attachments.dlx", "dead-letter-strategy": "at-least-once", "overflow": "reject-publish", - "delivery-limit": 10 + "delivery-limit": -1 } }, { diff --git a/openspec/changes/forward-lab5-published-fixes/tasks.md b/openspec/changes/forward-lab5-published-fixes/tasks.md index 57dfdae..d4f04bf 100644 --- a/openspec/changes/forward-lab5-published-fixes/tasks.md +++ b/openspec/changes/forward-lab5-published-fixes/tasks.md @@ -1,9 +1,9 @@ ## 1. Наследуемый уровень 3 -- [ ] 1.1 Перенести identity validation/cache и regression tests; проверить cache races и logout failures. -- [ ] 1.2 Перенести messaging NUL validation и regression tests. -- [ ] 1.3 Перенести PNG validation/transparency/memory и тесты, с локальными fixtures. -- [ ] 1.4 Перенести HAProxy/RabbitMQ, сохранив OTel; адаптировать вспомогательные проверки к ЛР6. -- [ ] 1.5 Выполнить make check/validate/lint/student-test; создать коммит runtime. +- [x] 1.1 Перенести identity validation/cache и regression tests; проверить cache races и logout failures. +- [x] 1.2 Перенести messaging NUL validation и regression tests. +- [x] 1.3 Перенести PNG validation/transparency/memory и тесты, с локальными fixtures. +- [x] 1.4 Перенести HAProxy/RabbitMQ, сохранив OTel; адаптировать вспомогательные проверки к ЛР6. +- [x] 1.5 Выполнить make check/validate/lint/student-test; создать коммит runtime. ## 2. Затронутые гарантии уровня 4 - [ ] 2.1 Реальный стенд: network, HAProxy errors, cache outage, PostgreSQL requeue более 10 раз. - [ ] 2.2 PNG HTTP, 40MP и concurrent worker, forced limits/recovery; smoke/persistence/failover. diff --git a/openspec/config.yaml b/openspec/config.yaml index 90441c1..8a74aa7 100644 --- a/openspec/config.yaml +++ b/openspec/config.yaml @@ -41,7 +41,7 @@ context: | Python 3.14 (аннотации вычисляются лениво по PEP 649, `TYPE_CHECKING` и `from __future__ import annotations` не используются), FastAPI, gunicorn с несколькими `UvicornWorker` (пакет `uvicorn-worker`, `preload_app = False`), dishka (DI, интеграции FastAPI - и FastStream), pydantic v2 + pydantic-settings, structlog, SQLAlchemy 2.x async (asyncpg), Alembic, redis-py для Valkey, + и FastStream), pydantic v2 + pydantic-settings, structlog, SQLAlchemy 2.0.45 async (asyncpg), Alembic 1.16.5, redis-py для Valkey, argon2-cffi, aiobotocore, Pillow, FastStream 0.7 с `faststream[rabbit,otel]` поверх aio-pika, OpenTelemetry Python (API/SDK, OTLP/HTTP protobuf exporter без gRPC, инструментации FastAPI и asyncpg, версии в `uv.lock`), pytest + pytest-asyncio + httpx. Зависимости — uv и `uv.lock`; @@ -150,6 +150,8 @@ operations: - "Перед коммитом прогоняй `make lint`, `make student-test` и `make check`." - "Публичные `make test`, `make test-persistence ACTION_SCRIPT=scripts/restart.sh` и `make test-failover ACTION_SCRIPT=scripts/stop-one.sh` запускаются против поднятого стенда с включённой телеметрией; после failover реплика возвращается `make restore`." - "Каждый заявленный критерий рубрики подтверждай командой и наблюдаемым результатом в `REPORT.md`; PASS без команды доказательством не считается." + - "Фиксируй SHA кода API и обвязки отдельно; прежнее evidence сохраняй с исходным SHA. Числа сверяй с сырьём, неуспешные попытки сохраняй и объясняй; повторяй только затронутые или непригодные серии." + - "Проверяй документацию закреплённых SQLAlchemy/Alembic через Context7. Не приравнивай микробенчмарк к HTTP throughput, пик RPS к SLO, а no-op миграцию в rolling к проверке изменения схемы." - "Отмечай выполнение в `tasks.md`; резюме держи кратким." archive: guidance: diff --git a/src/messenger/attachments/infrastructure/images.py b/src/messenger/attachments/infrastructure/images.py index 91cb69d..5232977 100644 --- a/src/messenger/attachments/infrastructure/images.py +++ b/src/messenger/attachments/infrastructure/images.py @@ -5,10 +5,12 @@ import warnings from collections.abc import Callable from concurrent.futures import ProcessPoolExecutor from concurrent.futures.process import BrokenProcessPool +from contextlib import closing from dataclasses import dataclass from io import BytesIO -from PIL import Image, ImageOps +from PIL import Image, ImageChops, ImageOps +from PIL.PngImagePlugin import PngImageFile from messenger.attachments.application.ports import Rendition from messenger.attachments.domain.errors import ( @@ -27,6 +29,7 @@ from messenger.attachments.domain.variants import ( THUMBNAIL_BOX, fit, ) +from messenger.attachments.infrastructure.png import SIGNATURE, read_png_header, verify_png_pixels from messenger.shared.application.errors import Unavailable KINDS = {"PNG": ImageKind.PNG, "JPEG": ImageKind.JPEG} @@ -38,6 +41,8 @@ JPEG = {1: {"quality": 85, "optimize": True}, 2: {"quality": 90, "optimize": Tru WEBP = {1: {"quality": 80, "method": 4}, 2: {"quality": 85, "method": 4}} ENCODINGS = {"JPEG": (ImageKind.JPEG.value, "jpg"), "WEBP": ("image/webp", "webp")} REDUCING_GAP = 3.0 +PNG_WIDE_DEPTH = 16 +COLOR_TILE_SIDE = 256 @dataclass(frozen=True, slots=True) @@ -60,6 +65,7 @@ class PillowImageInspector: def _inspect(self, data: bytes, declared: ImageKind) -> ImageInfo: try: + header = read_png_header(data) if data.startswith(SIGNATURE) else None image = Image.open(BytesIO(data), formats=tuple(KINDS)) except BOMBS as error: raise PayloadTooLarge("изображение больше допустимого числа пикселей") from error @@ -67,28 +73,87 @@ class PillowImageInspector: raise UnsupportedImage("содержимое не является изображением PNG или JPEG") from error with image: kind = KINDS[str(image.format)] - width, height = image.size + width, height = image.size if header is None else header[:2] if kind is not declared: raise UnsupportedImage("содержимое не совпадает с заявленным Content-Type") if width * height > self._max_pixels: raise PayloadTooLarge("изображение больше допустимого числа пикселей") try: - if kind is ImageKind.JPEG: + if header is None: image.draft("RGB", (width // JPEG_SCALE or 1, height // JPEG_SCALE or 1)) image.load() else: image.verify() + verify_png_pixels(data, header) except Exception as error: raise UnsupportedImage("изображение повреждено или обрезано") from error return ImageInfo(kind, width, height) +def map_tiles( + image: Image.Image, mode: str, transform: Callable[[Image.Image], Image.Image] +) -> Image.Image: + result = Image.new(mode, image.size) + for y in range(0, image.height, COLOR_TILE_SIDE): + for x in range(0, image.width, COLOR_TILE_SIDE): + box = ( + x, + y, + min(x + COLOR_TILE_SIDE, image.width), + min(y + COLOR_TILE_SIDE, image.height), + ) + with closing(image.crop(box)) as tile, closing(transform(tile)) as transformed: + result.paste(transformed, box) + return result + + +def rgb_mask(image: Image.Image, color: tuple[int, ...]) -> Image.Image: + return map_tiles(image, "L", lambda tile: rgb_tile_mask(tile, color)) + + +def rgb_tile_mask(image: Image.Image, color: tuple[int, ...]) -> Image.Image: + mask = Image.new("L", image.size, 255) + for channel, value in zip("RGB", color, strict=True): + mask = ImageChops.multiply( + mask, image.getchannel(channel).point([255 if i == value else 0 for i in range(256)]) + ) + return mask + + +def apply_png_transparency(image: PngImageFile, data: bytes) -> None: + if (transparent := image.info.get("transparency")) is None: + return + depth = read_png_header(data)[2] + if image.mode == "L" and depth in (2, 4): + image.info["transparency"] = transparent * 255 // ((1 << depth) - 1) + elif image.mode == "RGB" and depth == PNG_WIDE_DEPTH: + with closing(PngImageFile(BytesIO(data))) as low: + low.tile = [tile._replace(args="RGB;16L") for tile in low.tile] + mask = rgb_mask(low, tuple(value & 255 for value in transparent)) + with ( + closing(mask), + closing(rgb_mask(image, tuple(value >> 8 for value in transparent))) as high, + closing(ImageChops.multiply(mask, high)) as combined, + ): + image.paste((255, 255, 255), mask=combined) + image.info.pop("transparency") + + def flatten(image: Image.Image) -> Image.Image: + if image.mode == "RGB" and "transparency" not in image.info: + return image + return map_tiles(image, "RGB", flatten_tile) + + +def flatten_tile(image: Image.Image) -> Image.Image: if image.mode in WIDE_MODES: - image = image.convert("I").point(lambda value: value / 256, "L") - if image.mode == "P": - image = image.convert("RGBA" if "transparency" in image.info else "RGB") - if image.mode in ALPHA_MODES: + image = image.convert("I") + if (transparent := image.info.pop("transparency", None)) is not None: + mask = [0] * 65536 + mask[transparent] = 255 + image.paste(65535, mask=image.point(mask, "L")) + image = image.point(lambda value: value / 256, "L") + if image.mode in ALPHA_MODES or "transparency" in image.info: image = image.convert("RGBA") if image.mode == "RGBA": background = Image.new("RGB", image.size, "white") @@ -116,12 +181,17 @@ def decoded(data: bytes, max_pixels: int) -> tuple[Image.Image, int, int]: width, height = image.size if width * height > max_pixels: raise UnreadableImage("изображение больше допустимого числа пикселей") + if isinstance(image, PngImageFile): + apply_png_transparency(image, data) image.draft(None, fit(width, height, OPTIMIZED_BOX)) stored = image.size ImageOps.exif_transpose(image, in_place=True) if image.size != stored: width, height = height, width - return flatten(image), width, height + upright = flatten(image) + if upright is not image: + image.close() + return upright, width, height except UnreadableImage, MemoryError: raise except Exception as error: diff --git a/src/messenger/attachments/infrastructure/png.py b/src/messenger/attachments/infrastructure/png.py new file mode 100644 index 0000000..1e38495 --- /dev/null +++ b/src/messenger/attachments/infrastructure/png.py @@ -0,0 +1,118 @@ +import struct +import zlib +from collections.abc import Iterator + +type PngHeader = tuple[int, int, int, int, int, int, int] + +SIGNATURE = b"\x89PNG\r\n\x1a\n" +HEADER_BYTES = 13 +CHUNK_OVERHEAD = 12 +BLOCK_BYTES = 65_536 +MAX_FILTER = 4 +PIXELS = { + 0: (1, (1, 2, 4, 8, 16)), + 2: (3, (8, 16)), + 3: (1, (1, 2, 4, 8)), + 4: (2, (8, 16)), + 6: (4, (8, 16)), +} +ADAM7 = ( + (0, 0, 8, 8), + (4, 0, 8, 8), + (0, 4, 4, 8), + (2, 0, 4, 4), + (0, 2, 2, 4), + (1, 0, 2, 2), + (0, 1, 1, 2), +) + + +def _chunks(data: bytes) -> Iterator[tuple[bytes, memoryview]]: + view = memoryview(data) + offset = len(SIGNATURE) + while offset + CHUNK_OVERHEAD <= len(data): + size = struct.unpack_from(">I", data, offset)[0] + kind = data[offset + 4 : offset + 8] + start, end = offset + 8, offset + 8 + size + if end + 4 > len(data): + raise ValueError("truncated PNG chunk") + yield kind, view[start:end] + if kind == b"IEND": + return + offset = end + 4 + raise ValueError("missing PNG end") + + +def read_png_header(data: bytes) -> PngHeader: + chunks = _chunks(data) + kind, header = next(chunks) + if kind != b"IHDR" or len(header) != HEADER_BYTES: + raise ValueError("invalid first PNG header") + if any(kind == b"IHDR" for kind, _ in chunks): + raise ValueError("duplicate PNG header") + return struct.unpack(">IIBBBBB", header) + + +def _scanlines(header: PngHeader) -> Iterator[tuple[int, int]]: + width, height, depth, color, compression, filtering, interlace = header + samples, depths = PIXELS[color] + if depth not in depths or compression or filtering or interlace not in (0, 1): + raise ValueError("invalid PNG header") + passes = ADAM7 if interlace else ((0, 0, 1, 1),) + for x, y, dx, dy in passes: + columns, rows = (width - x + dx - 1) // dx, (height - y + dy - 1) // dy + if columns > 0 and rows > 0: + stride = 1 + (columns * samples * depth + 7) // 8 + yield stride, stride * rows + + +def _idat(data: bytes) -> Iterator[memoryview]: + started = ended = False + for kind, payload in _chunks(data): + if kind == b"IDAT": + if ended: + raise ValueError("nonconsecutive PNG image data") + started = True + for position in range(0, len(payload), BLOCK_BYTES): + yield payload[position : position + BLOCK_BYTES] + elif started: + ended = True + + +def _inflate(data: bytes) -> Iterator[bytes]: + decoder = zlib.decompressobj() + for block in _idat(data): + if decoder.eof: + continue + pending = block + while True: + decoded = decoder.decompress(pending, BLOCK_BYTES) + yield decoded + pending = decoder.unconsumed_tail + if decoder.eof or (not pending and len(decoded) < BLOCK_BYTES): + break + if not decoder.eof: + raise ValueError("incomplete PNG compressed data") + + +def verify_png_pixels(data: bytes, header: PngHeader) -> None: + passes = _scanlines(header) + stride, remaining = next(passes) + offset = 0 + for decoded in _inflate(data): + cursor = 0 + while cursor < len(decoded): + if not remaining: + stride, remaining = next(passes, (0, 0)) + offset = 0 + if not remaining: + raise ValueError("extra PNG pixel data") + size = min(remaining, len(decoded) - cursor) + filters = decoded[cursor + (-offset % stride) : cursor + size : stride] + if max(filters, default=0) > MAX_FILTER: + raise ValueError("invalid PNG filter") + cursor += size + offset += size + remaining -= size + if remaining or next(passes, None) is not None: + raise ValueError("incomplete PNG pixel data") diff --git a/src/messenger/identity/application/handlers.py b/src/messenger/identity/application/handlers.py index 28b6f45..edb0adb 100644 --- a/src/messenger/identity/application/handlers.py +++ b/src/messenger/identity/application/handlers.py @@ -69,10 +69,10 @@ class CloseSessionHandler: self._revocations = revocations async def __call__(self, command: CloseSession) -> None: - await self._revocations.revoke(command.session) try: async with self._uow.transaction(): await self._uow.sessions.remove(command.session.token_hash) + await self._revocations.revoke(command.session) self._uow.record(SessionClosed(user_id=command.session.user_id)) await self._uow.commit() except BaseException: diff --git a/src/messenger/identity/domain/values.py b/src/messenger/identity/domain/values.py index 8d6170a..5ccbf1b 100644 --- a/src/messenger/identity/domain/values.py +++ b/src/messenger/identity/domain/values.py @@ -30,6 +30,8 @@ class DisplayName: def __post_init__(self) -> None: if not isinstance(self.value, str): raise InvalidUserData("поле display_name должно быть строкой") + if "\x00" in self.value: + raise InvalidUserData("поле display_name не может содержать NUL") if not self.value.strip(): raise InvalidUserData("поле display_name не может быть пустым или состоять из пробелов") if len(self.value) > DISPLAY_NAME_MAX: diff --git a/src/messenger/identity/entrypoints/authentication.py b/src/messenger/identity/entrypoints/authentication.py index 1103e3d..1976ab9 100644 --- a/src/messenger/identity/entrypoints/authentication.py +++ b/src/messenger/identity/entrypoints/authentication.py @@ -30,14 +30,14 @@ def challenge_for(path: str) -> str: def basic_credentials(value: str) -> tuple[str, str] | None: scheme, _, encoded = value.partition(" ") - if scheme.lower() != "basic": + if scheme.lower() != "basic" or not encoded.isascii(): return None try: decoded = b64decode(encoded.strip(), validate=True).decode("utf-8") except Base64Error, UnicodeDecodeError: return None username, separator, password = decoded.partition(":") - if not separator or not username.isascii(): + if not separator or not username.isascii() or "\x00" in username: return None return username, password diff --git a/src/messenger/identity/infrastructure/postgres.py b/src/messenger/identity/infrastructure/postgres.py index eecc999..31e325b 100644 --- a/src/messenger/identity/infrastructure/postgres.py +++ b/src/messenger/identity/infrastructure/postgres.py @@ -166,10 +166,12 @@ class PostgresSessionDirectory: async with self._database.session() as session: row = ( await session.execute( - select(SessionRow).where( + select(SessionRow) + .where( SessionRow.token_hash == token_hash, SessionRow.expires_at > now, ) + .with_for_update(read=True, key_share=True) ) ).scalar_one_or_none() if row is None: diff --git a/src/messenger/identity/infrastructure/valkey.py b/src/messenger/identity/infrastructure/valkey.py index 4a596d6..2540c94 100644 --- a/src/messenger/identity/infrastructure/valkey.py +++ b/src/messenger/identity/infrastructure/valkey.py @@ -1,7 +1,7 @@ import time from collections.abc import Awaitable from datetime import datetime, timedelta -from uuid import UUID +from uuid import UUID, uuid4 from redis.asyncio import Redis from redis.exceptions import RedisError @@ -13,6 +13,16 @@ from messenger.shared.application.ports import Logger REVOKED = "-" FAILURES = (RedisError, OSError) +FILL = """ +if redis.call('GET', KEYS[2]) ~= ARGV[1] then return false end +redis.call('DEL', KEYS[2]) +if ARGV[2] == '' then return false end +return redis.call('SET', KEYS[1], ARGV[2], 'PXAT', ARGV[3], 'NX') +""" +REVOKE = """ +redis.call('SET', KEYS[1], ARGV[1], 'PXAT', ARGV[2]) +return redis.call('DEL', KEYS[2]) +""" def key_of(token_hash: bytes) -> str: @@ -72,18 +82,26 @@ class CachedSessionDirectory: if cached is not None: session = decode(token_hash, cached) return session if session.expires_at > now else None + marker, nonce = f"{key}:fill", uuid4().hex + until = milliseconds(now + self._limit) + reserved = self._closed() and await self._quietly( + self._client.set(marker, nonce, pxat=until, nx=True) + ) session = await self._origin.find(token_hash, now) - if session is not None and self._closed(): - until = milliseconds(min(session.expires_at, now + self._limit)) - await self._quietly(self._client.set(key, encode(session), pxat=until, nx=True)) + if reserved and self._closed(): + value = encode(session) if session is not None else "" + if session is not None: + until = min(until, milliseconds(session.expires_at)) + await self._quietly(self._client.eval(FILL, 2, key, marker, nonce, value, until)) return session async def revoke(self, session: Session) -> None: if not self._closed(): raise Unavailable("кэш сессий недоступен") + key = key_of(session.token_hash) try: - await self._client.set( - key_of(session.token_hash), REVOKED, pxat=milliseconds(session.expires_at) + await self._client.eval( + REVOKE, 2, key, f"{key}:fill", REVOKED, milliseconds(session.expires_at) ) except FAILURES as error: self._trip(error) diff --git a/src/messenger/messaging/domain/values.py b/src/messenger/messaging/domain/values.py index 5a2f31b..193b788 100644 --- a/src/messenger/messaging/domain/values.py +++ b/src/messenger/messaging/domain/values.py @@ -15,6 +15,8 @@ class ChatTitle: def __post_init__(self) -> None: if not isinstance(self.value, str): raise InvalidChatData("поле title должно быть строкой") + if "\x00" in self.value: + raise InvalidChatData("поле title не может содержать NUL") if not self.value.strip(): raise InvalidChatData("поле title не может быть пустым или состоять из пробелов") if len(self.value) > CHAT_TITLE_MAX: @@ -31,6 +33,8 @@ class MessageText: def __post_init__(self) -> None: if not isinstance(self.value, str): raise InvalidMessageText("поле text должно быть строкой") + if "\x00" in self.value: + raise InvalidMessageText("поле text не может содержать NUL") if self.value and not self.value.strip(): raise InvalidMessageText("поле text не может состоять из пробелов") if len(self.value) > MESSAGE_TEXT_MAX: diff --git a/student-tests/adapters/test_rabbitmq.py b/student-tests/adapters/test_rabbitmq.py index 9c9d9a4..1a1acdf 100644 --- a/student-tests/adapters/test_rabbitmq.py +++ b/student-tests/adapters/test_rabbitmq.py @@ -248,14 +248,20 @@ async def test_message_off_the_schema_goes_to_the_dead_letter_queue( assert depth(rabbitmq, "attachments.process") == 0 -async def test_failed_processing_is_requeued_and_retried(rabbitmq: dict[str, Any]) -> None: +@pytest.mark.parametrize("failures", [1, 12]) +async def test_failed_processing_is_requeued_and_retried( + rabbitmq: dict[str, Any], failures: int +) -> None: recorder, sent = Recorder(), job() - recorder.failures = 1 + recorder.failures = failures + before = depth(rabbitmq, "attachments.process.dlq") async with publisher(rabbitmq) as jobs: await jobs.publish(sent.id, body(sent.payload())) async with worker(rabbitmq, recorder): - await wait_for(lambda: recorder.jobs) + await wait_for(lambda: recorder.jobs, seconds=40) + await wait_for(lambda: depth(rabbitmq, "attachments.process") == 0) assert recorder.jobs == [sent] + assert depth(rabbitmq, "attachments.process.dlq") == before async def test_worker_account_cannot_publish(rabbitmq: dict[str, Any]) -> None: diff --git a/student-tests/api/test_attachments.py b/student-tests/api/test_attachments.py index 9ac3170..c9129f0 100644 --- a/student-tests/api/test_attachments.py +++ b/student-tests/api/test_attachments.py @@ -12,7 +12,7 @@ from PIL import Image from conftest import actor, make_chat, register, resolve, running_app, scalar from fakes import MemoryObjectStorage from messenger.attachments.application.ports import ObjectStorage -from pictures import GIF, JPEG, SAMPLE, WEBP, png +from pictures import BROKEN_PNG, DUPLICATE_IHDR_PNG, GIF, JPEG, SAMPLE, WEBP, png from pipeline import settle LIMIT = 10_485_760 @@ -197,6 +197,8 @@ async def test_pixel_limit_is_read_from_header( @pytest.mark.parametrize( ("content", "header"), [ + (BROKEN_PNG, "image/png"), + (DUPLICATE_IHDR_PNG, "image/png"), (JPEG, "image/png"), (GIF, "image/png"), (WEBP, "image/png"), @@ -209,6 +211,8 @@ async def test_pixel_limit_is_read_from_header( (SAMPLE, "image/gif"), ], ids=[ + "invalid-zlib", + "duplicate-ihdr", "jpeg-as-png", "gif-as-png", "webp-as-png", diff --git a/student-tests/api/test_cache.py b/student-tests/api/test_cache.py index 01bf599..f0c37c4 100644 --- a/student-tests/api/test_cache.py +++ b/student-tests/api/test_cache.py @@ -11,7 +11,12 @@ from sqlalchemy import select from conftest import actor, bearer, keyed, make_chat, register, resolve, running_app, scalar from messenger.identity.application.ports import SessionDirectory from messenger.identity.domain.models import Session -from messenger.identity.infrastructure.postgres import PostgresSessionRepository, SessionRow +from messenger.identity.infrastructure.postgres import ( + PostgresIdentityUnitOfWork, + PostgresSessionDirectory, + PostgresSessionRepository, + SessionRow, +) from messenger.identity.infrastructure.valkey import CachedSessionDirectory from messenger.shared.application.errors import Unavailable @@ -44,7 +49,7 @@ async def test_second_check_is_served_from_cache(valkey: dict[str, str]) -> None await cache.aclose() -async def test_logout_writes_tombstone_before_database(valkey: dict[str, str]) -> None: +async def test_logout_leaves_tombstone_after_commit(valkey: dict[str, str]) -> None: cache = Redis.from_url(valkey["url"]) async with running_app(cache_url=valkey["url"]) as http: alice = await register(http, "alice") @@ -59,19 +64,26 @@ async def test_logout_writes_tombstone_before_database(valkey: dict[str, str]) - await cache.aclose() +@pytest.mark.parametrize("failure", ["remove", "commit"]) async def test_logout_rejected_by_database_changes_nothing( - valkey: dict[str, str], monkeypatch: pytest.MonkeyPatch + valkey: dict[str, str], monkeypatch: pytest.MonkeyPatch, failure: str ) -> None: async def broken(self: PostgresSessionRepository, token_hash: bytes) -> None: raise Unavailable("PostgreSQL недоступен") + async def broken_commit(self: PostgresIdentityUnitOfWork) -> None: + raise Unavailable("PostgreSQL недоступен") + cache = Redis.from_url(valkey["url"]) logout = "/api/v1/auth/sessions/current" async with running_app(cache_url=valkey["url"]) as http: alice = await register(http, "alice") assert (await http.get("/api/v1/users/me", headers=actor(alice))).status_code == 200 with monkeypatch.context() as patch: - patch.setattr(PostgresSessionRepository, "remove", broken) + if failure == "remove": + patch.setattr(PostgresSessionRepository, "remove", broken) + else: + patch.setattr(PostgresIdentityUnitOfWork, "commit", broken_commit) failed = await http.delete(logout, headers=actor(alice)) assert failed.status_code == 503 assert failed.json()["error"]["code"] == "unavailable" @@ -82,8 +94,14 @@ async def test_logout_rejected_by_database_changes_nothing( await cache.aclose() -async def test_fill_racing_with_logout_does_not_revive_token(valkey: dict[str, str]) -> None: - async with running_app(cache_url=valkey["url"]) as http: +@pytest.mark.parametrize("loss", ["none", "flushall", "evict", "replacement"]) +async def test_fill_racing_with_logout_does_not_revive_token( + valkey: dict[str, str], loss: str +) -> None: + async with ( + Redis.from_url(valkey["url"]) as cache, + running_app(cache_url=valkey["url"]) as http, + ): alice = await register(http, "alice") directory = await resolve(http, SessionDirectory) assert isinstance(directory, CachedSessionDirectory) @@ -99,14 +117,73 @@ async def test_fill_racing_with_logout_does_not_revive_token(valkey: dict[str, s return stale[-1] directory._origin = SlowOrigin() - reader = asyncio.create_task(http.get("/api/v1/users/me", headers=actor(alice))) - await entered.wait() - directory._origin = origin - assert ( - await http.delete("/api/v1/auth/sessions/current", headers=actor(alice)) - ).status_code == 204 - released.set() - assert (await reader).status_code == 200 + async with asyncio.TaskGroup() as group: + reader = group.create_task(http.get("/api/v1/users/me", headers=actor(alice))) + try: + await asyncio.wait_for(entered.wait(), 5) + directory._origin = origin + assert ( + await http.delete("/api/v1/auth/sessions/current", headers=actor(alice)) + ).status_code == 204 + key = key_of(token_of(alice)) + assert await cache.get(f"{key}:fill") is None + if loss == "flushall": + await cache.flushall() + elif loss in {"evict", "replacement"}: + await cache.delete(key) + if loss == "replacement": + await cache.set(f"{key}:fill", "another-reader", px=1000) + finally: + released.set() + assert reader.result().status_code == 200 + assert (await http.get("/api/v1/users/me", headers=actor(alice))).status_code == 401 + + +@pytest.mark.parametrize("loss", ["flushall", "evict"]) +async def test_cache_loss_before_logout_commit_cannot_refill_deleted_session( + valkey: dict[str, str], monkeypatch: pytest.MonkeyPatch, loss: str +) -> None: + revoked, release_commit, reading = asyncio.Event(), asyncio.Event(), asyncio.Event() + revoke = CachedSessionDirectory.revoke + find = PostgresSessionDirectory.find + + async def paused_revoke(self: CachedSessionDirectory, session: Session) -> None: + await revoke(self, session) + revoked.set() + await release_commit.wait() + + async def observed_find( + self: PostgresSessionDirectory, token_hash: bytes, now: datetime + ) -> Session | None: + reading.set() + return await find(self, token_hash, now) + + async with ( + Redis.from_url(valkey["url"]) as cache, + running_app(cache_url=valkey["url"]) as http, + ): + alice = await register(http, "alice") + assert (await http.get("/api/v1/users/me", headers=actor(alice))).status_code == 200 + monkeypatch.setattr(CachedSessionDirectory, "revoke", paused_revoke) + async with asyncio.TaskGroup() as group: + logout = group.create_task( + http.delete("/api/v1/auth/sessions/current", headers=actor(alice)) + ) + try: + await asyncio.wait_for(revoked.wait(), 5) + if loss == "flushall": + await cache.flushall() + else: + await cache.delete(key_of(token_of(alice))) + monkeypatch.setattr(PostgresSessionDirectory, "find", observed_find) + reader = group.create_task(http.get("/api/v1/users/me", headers=actor(alice))) + await asyncio.wait_for(reading.wait(), 5) + done, _ = await asyncio.wait({reader}, timeout=0.1) + assert not done + finally: + release_commit.set() + assert logout.result().status_code == 204 + assert reader.result().status_code == 401 assert (await http.get("/api/v1/users/me", headers=actor(alice))).status_code == 401 diff --git a/student-tests/api/test_nul_validation.py b/student-tests/api/test_nul_validation.py new file mode 100644 index 0000000..ca77d09 --- /dev/null +++ b/student-tests/api/test_nul_validation.py @@ -0,0 +1,95 @@ +from uuid import uuid4 + +import pytest +from httpx import AsyncClient, Response + +from conftest import PASSWORD, actor, basic, keyed, make_chat, new_user, register + +NUL_TEXTS = ["\x00", "\x00abc", "abc\x00def", "abc\x00"] + + +def rejected(response: Response, status: int, code: str) -> None: + assert response.status_code == status, response.text + assert response.headers["content-type"].startswith("application/json") + assert response.headers["X-Instance-Id"] + assert response.headers["X-Request-Id"] + assert set(response.json()) == {"error"} + error = response.json()["error"] + assert set(error) == {"code", "message", "request_id"} + assert error["code"] == code + assert error["message"] + assert error["request_id"] == response.headers["X-Request-Id"] + + +@pytest.mark.parametrize("username", NUL_TEXTS) +async def test_nul_basic_matches_wrong_password(client: AsyncClient, username: str) -> None: + user = await register(client, "nul_login") + responses = [] + for name, password in [(user["username"], "wrong-password"), (username, PASSWORD)]: + response = await client.post( + "/api/v1/auth/sessions", + headers={**basic(name, password), "X-Request-Id": "nul-login"}, + ) + rejected(response, 401, "unauthorized") + assert response.headers["WWW-Authenticate"] == 'Basic realm="messenger", charset="UTF-8"' + responses.append(response.json()) + assert responses[0] == responses[1] + + +@pytest.mark.parametrize("raw", NUL_TEXTS) +async def test_nul_display_name_does_not_create_user(client: AsyncClient, raw: str) -> None: + body = {**new_user("nul_display"), "display_name": raw} + rejected(await client.post("/api/v1/users", json=body), 400, "invalid_request") + response = await client.post("/api/v1/users", json={**body, "display_name": "Алиса 👋"}) + assert response.status_code == 201 + assert response.json()["display_name"] == "Алиса 👋" + + +@pytest.mark.parametrize("raw", NUL_TEXTS) +async def test_nul_title_does_not_create_chat(client: AsyncClient, raw: str) -> None: + user = await register(client, "nul_title") + body = {"title": raw, "member_ids": [user["id"]]} + rejected( + await client.post("/api/v1/chats", json=body, headers=actor(user)), 400, "invalid_request" + ) + chats = await client.get("/api/v1/chats", headers=actor(user)) + assert chats.status_code == 200 + assert chats.json()["items"] == [] + + +@pytest.mark.parametrize("raw", NUL_TEXTS) +async def test_nul_message_does_not_take_key(client: AsyncClient, raw: str) -> None: + user = await register(client, "nul_message") + chat = await make_chat(client, user) + path = f"/api/v1/chats/{chat['id']}/messages" + headers = keyed(user) + rejected(await client.post(path, json={"text": raw}, headers=headers), 400, "invalid_request") + history = await client.get(path, headers=actor(user)) + assert history.status_code == 200 + assert history.json()["items"] == [] + text = "Исправлено\tбез потерь\n👋" + first = await client.post(path, json={"text": text}, headers=headers) + again = await client.post(path, json={"text": text}, headers=headers) + assert first.status_code == again.status_code == 201 + assert first.json()["text"] == text + assert first.json() == again.json() + assert (await client.get(path, headers=actor(user))).json()["items"] == [first.json()] + + +async def test_nul_message_does_not_disclose_chat(client: AsyncClient) -> None: + owner = await register(client, "nul_owner") + outsider = await register(client, "nul_outsider") + chat = await make_chat(client, owner) + responses = [] + for chat_id in [chat["id"], str(uuid4())]: + response = await client.post( + f"/api/v1/chats/{chat_id}/messages", + json={"text": "abc\x00def"}, + headers={**keyed(outsider), "X-Request-Id": "nul-access"}, + ) + rejected(response, 404, "not_found") + responses.append(response.json()) + assert responses[0] == responses[1] + history = await client.get(f"/api/v1/chats/{chat['id']}/messages", headers=actor(owner)) + assert history.status_code == 200 + assert history.json()["items"] == [] diff --git a/student-tests/api/test_sessions.py b/student-tests/api/test_sessions.py index 8b9334d..ab4836a 100644 --- a/student-tests/api/test_sessions.py +++ b/student-tests/api/test_sessions.py @@ -86,6 +86,34 @@ async def test_login_without_valid_basic(client: AsyncClient, headers: dict) -> challenged(await client.post("/api/v1/auth/sessions", headers=headers), BASIC) +@pytest.mark.parametrize( + "raw", [b"Basic \x80", b"Basic \xff", b"Basic \xc3\xa9", b"Basic YWxpY2U6c2VjcmV0\xff"] +) +async def test_non_ascii_basic_matches_wrong_password(client: AsyncClient, raw: bytes) -> None: + alice = await register(client, "non_ascii_basic") + count = ( + select(func.count()).select_from(SessionRow).where(SessionRow.user_id == UUID(alice["id"])) + ) + before = await scalar(count) + wrong = await client.post( + "/api/v1/auth/sessions", + headers={**basic(alice["username"], "wrong-password"), "X-Request-Id": "non-ascii-basic"}, + ) + invalid = await client.post( + "/api/v1/auth/sessions", + headers={b"Authorization": raw, b"X-Request-Id": b"non-ascii-basic"}, + ) + for response in [wrong, invalid]: + challenged(response, BASIC) + assert response.headers["X-Instance-Id"] + assert response.headers["content-type"].startswith("application/json") + assert set(response.json()) == {"error"} + assert set(response.json()["error"]) == {"code", "message", "request_id"} + assert response.json()["error"]["message"] + assert wrong.json() == invalid.json() + assert await scalar(count) == before + + async def test_password_with_colon_logs_in(client: AsyncClient) -> None: body = new_user("colon", password="пароль:с:двоеточием") assert (await client.post("/api/v1/users", json=body)).status_code == 201 diff --git a/student-tests/pictures.py b/student-tests/pictures.py index f53a529..4cd6a9e 100644 --- a/student-tests/pictures.py +++ b/student-tests/pictures.py @@ -14,6 +14,33 @@ def chunk(kind: bytes, data: bytes) -> bytes: return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", crc) +def png_from_idat( + data: bytes, + width: int = 1, + height: int = 1, + *, + depth: int = 8, + color: int = 2, + interlace: int = 0, + chunk_size: int = 65_536, +) -> bytes: + header = struct.pack(">IIBBBBB", width, height, depth, color, 0, 0, interlace) + palette = chunk(b"PLTE", bytes(range(256)) * 3) if color == 3 else b"" + blocks = [ + chunk(b"IDAT", data[start : start + chunk_size]) + for start in range(0, len(data), chunk_size) + ] + return SIGNATURE + chunk(b"IHDR", header) + palette + b"".join(blocks) + chunk(b"IEND", b"") + + +BROKEN_PNG = png_from_idat(b"not a zlib stream") +DUPLICATE_IHDR_PNG = ( + SIGNATURE + + chunk(b"IHDR", struct.pack(">IIBBBBB", 1, 1, 8, 2, 0, 0, 0)) + + png_from_idat(zlib.compress(bytes(4)), 2, 2)[len(SIGNATURE) :] +) + + def png(width: int, height: int, *, size: int | None = None, rows: bool = True) -> bytes: header = struct.pack(">IIBBBBB", width, height, 1, 0, 0, 0, 0) raw = (b"\x00" * (1 + (width + 7) // 8)) * height if rows else b"\x00" diff --git a/student-tests/png_trns_fixtures.py b/student-tests/png_trns_fixtures.py new file mode 100644 index 0000000..ce859bb --- /dev/null +++ b/student-tests/png_trns_fixtures.py @@ -0,0 +1,122 @@ +import struct +import zlib +from io import BytesIO + +from PIL import Image + +from pictures import SIGNATURE, chunk + +PASSES = ( + (0, 0, 8, 8), + (4, 0, 8, 8), + (0, 4, 4, 8), + (2, 0, 4, 4), + (0, 2, 2, 4), + (1, 0, 2, 2), + (0, 1, 1, 2), +) + + +def boundary_png(depth: int, transparent: tuple[int, ...]) -> bytes: + width, height = 8000, 5000 + neighbor = (transparent[0] ^ 1, *transparent[1:]) + row = b"\x00" + packed(list(transparent) * (width // 2) + list(neighbor) * (width // 2), depth) + compressor = zlib.compressobj() + payload = b"".join(compressor.compress(row) for _ in range(height)) + compressor.flush() + header = struct.pack( + ">IIBBBBB", width, height, depth, 0 if len(transparent) == 1 else 2, 0, 0, 0 + ) + return ( + SIGNATURE + + chunk(b"IHDR", header) + + chunk(b"tRNS", b"".join(value.to_bytes(2, "big") for value in transparent)) + + chunk(b"IDAT", payload) + + chunk(b"IEND", b"") + ) + + +def packed(samples: list[int], depth: int) -> bytes: + if depth >= 8: + return b"".join(value.to_bytes(depth // 8, "big") for value in samples) + per_byte = 8 // depth + padded = samples + [0] * (-len(samples) % per_byte) + return bytes( + sum(value << (8 - depth * (i + 1)) for i, value in enumerate(padded[j : j + per_byte])) + for j in range(0, len(padded), per_byte) + ) + + +def filtered(row: bytes, previous: bytes, bpp: int, method: int) -> bytes: + result = bytearray([method]) + for i, value in enumerate(row): + left = row[i - bpp] if i >= bpp else 0 + above = previous[i] + corner = previous[i - bpp] if i >= bpp else 0 + estimate = left + above - corner + paeth = min((left, above, corner), key=lambda candidate: abs(estimate - candidate)) + predictor = (0, left, above, (left + above) // 2, paeth)[method] + result.append((value - predictor) % 256) + return bytes(result) + + +def png_with_trns( + depth: int, + transparent: tuple[int, ...], + *, + size: tuple[int, int] = (64, 64), + filtering: int = 0, + interlace: int = 0, + orientation: int = 1, +) -> tuple[bytes, bytes]: + width, height = size + neighbors = [ + tuple(value ^ (1 << bit) if i == channel else value for i, value in enumerate(transparent)) + for bit in ([0, 8] if depth == 16 else [0]) + for channel in range(len(transparent)) + ] + neighbors.insert(0, ((transparent[0] + 1) % (1 << depth), *transparent[1:])) + pixels = [ + [ + transparent if x < (width + 1) // 2 else neighbors[(y // 8) % len(neighbors)] + for x in range(width) + ] + for y in range(height) + ] + raw = bytearray() + for x0, y0, dx, dy in PASSES if interlace else ((0, 0, 1, 1),): + columns = range(x0, width, dx) + if not columns: + continue + previous = bytes((len(columns) * len(transparent) * depth + 7) // 8) + for y in range(y0, height, dy): + row = packed([value for x in columns for value in pixels[y][x]], depth) + raw.extend(filtered(row, previous, max(1, len(transparent) * depth // 8), filtering)) + previous = row + header = struct.pack( + ">IIBBBBB", width, height, depth, 0 if len(transparent) == 1 else 2, 0, 0, interlace + ) + exif = Image.Exif() + exif[0x0112] = orientation + compressed = zlib.compress(raw) + data = ( + SIGNATURE + + chunk(b"IHDR", header) + + chunk(b"tRNS", b"".join(value.to_bytes(2, "big") for value in transparent)) + + chunk(b"eXIf", exif.tobytes()[6:]) + + b"".join(chunk(b"IDAT", compressed[i : i + 7]) for i in range(0, len(compressed), 7)) + + chunk(b"IEND", b"") + ) + expected = bytearray() + for row in pixels: + for pixel in row: + channels = tuple( + v >> 8 if depth == 16 else v * 255 // ((1 << depth) - 1) for v in pixel + ) + expected.extend( + (255, 255, 255) + if pixel == transparent + else channels * (3 if len(channels) == 1 else 1) + ) + buffer = BytesIO() + Image.frombytes("RGB", size, expected).save(buffer, "PNG", exif=exif) + return data, buffer.getvalue() diff --git a/student-tests/stack/test_attachment_faults.py b/student-tests/stack/test_attachment_faults.py index d32c798..42bd18b 100644 --- a/student-tests/stack/test_attachment_faults.py +++ b/student-tests/stack/test_attachment_faults.py @@ -15,7 +15,7 @@ import httpx import pytest from httpx import AsyncClient, Response -from pictures import GIF, JPEG, SAMPLE, WEBP, png +from pictures import BROKEN_PNG, DUPLICATE_IHDR_PNG, GIF, JPEG, SAMPLE, WEBP, png from stand import BASE_URL, bearer, compose, enroll, lb_up, psql, waited pytestmark = pytest.mark.stack @@ -313,6 +313,8 @@ async def test_user_errors_never_become_500(http: AsyncClient) -> None: ) expect("PNG 8001×5000", await upload(http, alice, chat, png(8001, 5000, rows=False)), 413) for label, content, kind in ( + ("PNG с корректными CRC и битым IDAT", BROKEN_PNG, "image/png"), + ("PNG с повторным IHDR", DUPLICATE_IHDR_PNG, "image/png"), ("обрезанный PNG", SAMPLE[: len(SAMPLE) // 2], "image/png"), ("обрезанный JPEG", JPEG[: len(JPEG) // 2], "image/jpeg"), ("JPEG как image/png", JPEG, "image/png"), diff --git a/student-tests/tools/forward_conditions.py b/student-tests/tools/forward_conditions.py new file mode 100644 index 0000000..1de6829 --- /dev/null +++ b/student-tests/tools/forward_conditions.py @@ -0,0 +1,59 @@ +import json +import os +import platform +import subprocess +from collections import Counter +from datetime import UTC, datetime + + +def command(*args: str) -> str: + return subprocess.check_output(args, text=True).strip() + + +project = os.environ.get("COMPOSE_PROJECT_NAME", "mtusi2026lab6") +containers = [ + json.loads(line) + for line in command( + "docker", + "ps", + "--format", + '{"name":"{{.Names}}","project":"{{.Label "com.docker.compose.project"}}"}', + ).splitlines() +] +own = {row["name"] for row in containers if row["project"] == project} +stats = [ + json.loads(line) + for line in command("docker", "stats", "--no-stream", "--format", "{{json .}}").splitlines() +] +print( + json.dumps( + { + "at": datetime.now(UTC).isoformat(), + "runtime_sha": command("git", "rev-parse", "HEAD"), + "platform": platform.system(), + "architecture": platform.machine(), + "host_cpus": os.cpu_count(), + "host_load": os.getloadavg(), + "docker": command( + "docker", + "info", + "--format", + "{{.NCPU}} CPUs; {{.MemTotal}} bytes; {{.ServerVersion}}", + ), + "own_project": project, + "own": [ + {key: row[key] for key in ("Name", "CPUPerc", "MemUsage", "PIDs")} + for row in stats + if row["Name"] in own + ], + "other_projects": dict( + Counter( + row["project"] or "unlabelled" for row in containers if row["name"] not in own + ) + ), + "sampling": "Shared Docker snapshot; no throughput claim", + }, + ensure_ascii=False, + indent=2, + ) +) diff --git a/student-tests/tools/forward_network.py b/student-tests/tools/forward_network.py new file mode 100644 index 0000000..3b180d8 --- /dev/null +++ b/student-tests/tools/forward_network.py @@ -0,0 +1,130 @@ +import base64 +import http.client +import json +import os +import uuid +from urllib.parse import urlsplit + +base = urlsplit(os.environ.get("BASE_URL", "http://127.0.0.1:18086")) +seen = set() +checks = [] +password = "Пароль-проверки-01" + + +def call(method, path, body=None, headers=None, status=200): + request_id = "validation-wire" + assert base.hostname + conn = http.client.HTTPConnection(base.hostname, base.port, timeout=12) + head = {"X-Request-Id": request_id, "Content-Type": "application/json", **(headers or {})} + conn.request(method, path, None if body is None else json.dumps(body).encode(), head) + response = conn.getresponse() + data = response.read() + instance = response.getheader("X-Instance-Id") + assert response.status == status, (method, path, response.status, status) + assert instance + assert response.getheader("X-Request-Id") == request_id + seen.add(instance) + result = json.loads(data) if data else None + if status >= 400: + assert result is not None + assert result["error"]["request_id"] == request_id + if status == 401: + assert response.getheader("WWW-Authenticate") == ( + 'Basic realm="messenger", charset="UTF-8"' + if path == "/api/v1/auth/sessions" + else 'Bearer realm="messenger"' + ) + conn.close() + return result, instance + + +def basic(name, secret=password): + return {"Authorization": "Basic " + base64.b64encode(f"{name}:{secret}".encode()).decode()} + + +def enroll(): + name = "wire_" + uuid.uuid4().hex[:15] + user, _ = call( + "POST", + "/api/v1/users", + {"username": name, "password": password, "display_name": "Алиса 👋"}, + status=201, + ) + login, _ = call("POST", "/api/v1/auth/sessions", headers=basic(name), status=201) + return user, {"Authorization": "Bearer " + login["token"]} + + +user, auth = enroll() +wrong, _ = call( + "POST", "/api/v1/auth/sessions", headers=basic(user["username"], "wrong-password"), status=401 +) +for raw in [b"Basic \x80", b"Basic \xff", b"Basic \xc3\xa9", b"Basic YWxpY2U6c2VjcmV0\xff"]: + result, instance = call( + "POST", "/api/v1/auth/sessions", headers={"Authorization": raw}, status=401 + ) + assert result == wrong + checks.append( + {"case": "non_ascii_basic", "raw_hex": raw.hex(), "status": 401, "instance": instance} + ) +for text in ["\x00", "\x00abc", "abc\x00def", "abc\x00"]: + result, instance = call("POST", "/api/v1/auth/sessions", headers=basic(text), status=401) + assert result == wrong + body = {"username": "wire_" + uuid.uuid4().hex[:15], "password": password, "display_name": text} + call("POST", "/api/v1/users", body, status=400) + call("POST", "/api/v1/users", {**body, "display_name": "Алиса 👋"}, status=201) + call("POST", "/api/v1/chats", {"title": text, "member_ids": [user["id"]]}, auth, status=400) + chats, _ = call("GET", "/api/v1/chats", headers=auth) + assert not chats["items"] + checks.append( + { + "case": "nul_basic_display_title", + "position": repr(text), + "status": [401, 400, 201, 400], + "instance": instance, + } + ) +chat, _ = call( + "POST", "/api/v1/chats", {"title": "Проверка 👋", "member_ids": [user["id"]]}, auth, status=201 +) +path = f"/api/v1/chats/{chat['id']}/messages" +messages = [] +for text in ["\x00", "\x00abc", "abc\x00def", "abc\x00"]: + headers = {**auth, "Idempotency-Key": uuid.uuid4().hex} + call("POST", path, {"text": text}, headers, status=400) + page, _ = call("GET", path, headers=auth) + assert page["items"] == messages + first, one = call("POST", path, {"text": "Исправлено\tбез потерь\n👋"}, headers, status=201) + again, two = call("POST", path, {"text": first["text"]}, headers, status=201) + assert first == again and one != two + messages.append(first) + page, _ = call("GET", path, headers=auth) + assert page["items"] == messages + checks.append( + { + "case": "nul_message_corrected_retry", + "position": repr(text), + "instances": [one, two], + "status": [400, 201, 201], + "copies": 1, + } + ) +_, outsider = enroll() +for target in [chat["id"], str(uuid.uuid4())]: + call( + "POST", + f"/api/v1/chats/{target}/messages", + {"text": "abc\x00def"}, + {**outsider, "Idempotency-Key": uuid.uuid4().hex}, + status=404, + ) +checks.append({"case": "nul_access", "status": [404, 404]}) +call("DELETE", "/api/v1/auth/sessions/current", headers=auth, status=204) +for _ in range(4): + call("GET", "/api/v1/users/me", headers=auth, status=401) +checks.append({"case": "logout_across_replicas", "status": [204, 401, 401, 401, 401]}) +assert len(seen) >= 2 +print( + json.dumps( + {"checks": checks, "instances": sorted(seen), "pass": True}, ensure_ascii=False, indent=2 + ) +) diff --git a/student-tests/tools/forward_runtime.py b/student-tests/tools/forward_runtime.py new file mode 100644 index 0000000..f99b588 --- /dev/null +++ b/student-tests/tools/forward_runtime.py @@ -0,0 +1,386 @@ +import hashlib +import json +import os +import struct +import sys +import time +from io import BytesIO +from pathlib import Path +from typing import Any + +from PIL import Image +from scripts import pipeline_suite as ps + +from messenger.attachments.infrastructure.images import RenderLimits, render_variants +from png_trns_fixtures import boundary_png, png_with_trns + +ROOT = Path(__file__).resolve().parents[2] + +MODE = sys.argv.pop(1) +OUT = Path(os.environ.get("FORWARD_EVIDENCE_DIR", "evidence/forward-published")) / (MODE + ".json") +if OUT.exists(): + raise SystemExit("Result exists; do not repeat completed evidence") +SUITE = ps.Suite(ps.arguments()) +STACK = SUITE.stack +REPORT: dict[str, Any] = { + "mode": MODE, + "source_sha": ps.run(["git", "rev-parse", "HEAD"]).strip(), + "started_at": ps.now(), + "cases": [], +} +LIMITS = RenderLimits(10485760, 40000000) + + +def save(): + REPORT["accepted_ids"] = SUITE.api.accepted if SUITE.api else [] + OUT.write_text(json.dumps(REPORT, ensure_ascii=False, indent=2) + "\n") + + +def case(name, function): + row = {"name": name, "started_at": ps.now()} + REPORT["cases"].append(row) + save() + began = time.monotonic() + try: + row["observed"] = function() + row["result"] = "PASS" + except Exception as error: + row.update(result="FAIL", error=str(error)) + row["elapsed_seconds"] = round(time.monotonic() - began, 3) + save() + print(name, row["result"], row.get("error", ""), flush=True) + + +def containers(): + return STACK.dc("ps", "-a", "--format", "{{.Name}} {{.ID}} {{.State}} {{.Status}}").splitlines() + + +def outage(): + assert SUITE.api is not None + SUITE.drained() + before_dlq = STACK.queues()[ps.DLQ] + STACK.stop("worker") + att = SUITE.api.fixture() + ident = att["id"] + ps.poll( + lambda: all(r["published"] for r in STACK.sql("outbox", id=ident)), 30, "published outbox" + ) + jobs = STACK.sql("jobs", id=ident) + REPORT["outage_checkpoint"] = { + "attachment_id": ident, + "jobs_before": jobs, + "dlq_before": before_dlq, + } + save() + STACK.stop("postgres") + REPORT["outage_checkpoint"]["stopped_containers"] = containers() + save() + since = ps.now() + worker_id = STACK.dc("ps", "-aq", "worker").strip() + assert worker_id + ps.run(["docker", "start", worker_id]) + + def requeues(): + logs = STACK.dc("logs", "--no-color", "--since", since, "worker") + rows = [ + line + for line in logs.splitlines() + if "job.requeued" in line and jobs[0]["job_id"] in line + ] + return rows if len(rows) >= 12 else None + + try: + lines = ps.poll(requeues, 90, "12 real database failures", 1) + OUT.with_name(OUT.stem + "-worker.txt").write_text("\n".join(lines) + "\n") + during = STACK.queues() + finally: + STACK.up("postgres") + ps.poll(lambda: ps.http_ready(SUITE.args.base_url), 30, "API after PostgreSQL") + ready = SUITE.api.wait(ident) + SUITE.verify(ready) + SUITE.drained() + after = STACK.sql("jobs", id=ident) + assert ( + after[0]["job_id"] == jobs[0]["job_id"] and after[0]["attempt"] == jobs[0]["attempt"] == 1 + ) + assert after[0]["status"] == "done" + assert STACK.queues()[ps.DLQ] == before_dlq + assert len(STACK.sql("variants", id=ident)) == 3 + return { + "attachment_id": ident, + "jobs_before": jobs, + "jobs_after": after, + "requeues": len(lines), + "queues_during": during, + "queues_after": STACK.queues(), + "replay": False, + "stopped_containers": REPORT["outage_checkpoint"]["stopped_containers"], + } + + +def png(name, data, reference): + assert SUITE.api is not None + att = SUITE.api.upload(data, name=name + ".png") + ident = att["id"] + results = [] + for version in (1, 2): + if version == 2: + STACK.admin("reprocess", "--attachment-id", ident, "--pipeline-version", "2") + ps.poll(lambda: SUITE.record(ident)["published_version"] == 2, 90, "published v2") + ready = SUITE.api.wait(ident) + SUITE.verify(ready) + assert SUITE.api.content(ident)["bytes"] == data + expected = {r.name: r for r in render_variants(reference, LIMITS, version)} + variants = [] + for variant in ready["variants"]: + content = SUITE.api.content(ident, variant["name"])["bytes"] + assert content == expected[variant["name"]].data, ( + variant["name"] + " differs from independent white reference" + ) + with Image.open(BytesIO(content)) as image: + assert not image.getexif() + assert not any(key in image.info for key in ("icc_profile", "xmp", "transparency")) + variants.append( + { + "name": variant["name"], + "sha256": hashlib.sha256(content).hexdigest(), + "bytes": len(content), + "dimensions": [variant["width"], variant["height"]], + } + ) + results.append({"version": version, "variants": variants}) + before = SUITE.snapshot(ident) + STACK.publish(SUITE.payload(ident, 1)) + STACK.publish(SUITE.payload(ident, 2)) + SUITE.drained() + assert SUITE.snapshot(ident) == before + assert len(STACK.sql("variants", id=ident)) == 6 + return { + "attachment_id": ident, + "input_sha256": hashlib.sha256(data).hexdigest(), + "input_bytes": len(data), + "versions": results, + "stale_and_duplicate_noop": True, + } + + +FIXTURES = ROOT / "build/forward-png" +FIXTURES.mkdir(parents=True, exist_ok=True) +for fixture_name, fixture_depth, fixture_key in ( + ("gray2", 2, (1,)), + ("gray4", 4, (5,)), + ("gray16", 16, (12345,)), + ("rgb16", 16, (12345, 23456, 34567)), +): + (FIXTURES / (fixture_name + "-40mp.png")).write_bytes(boundary_png(fixture_depth, fixture_key)) +ps.SQL["timed_events"] = ( + "SELECT attachment_id,job_id,kind,at FROM job_events " + "WHERE attachment_id = ANY(:'ids'::uuid[]) AND kind IN ('claimed','done') ORDER BY id" +) + + +def without_trns(data): + result, offset = data[:8], 8 + while offset < len(data): + size = struct.unpack(">I", data[offset : offset + 4])[0] + 12 + if data[offset + 4 : offset + 8] != b"tRNS": + result += data[offset : offset + size] + offset += size + return result + + +def verify_large(ident, data, transparent): + assert SUITE.api is not None + ready = SUITE.api.wait(ident) + SUITE.verify(ready) + assert SUITE.api.content(ident)["bytes"] == data + variants = [] + for variant in ready["variants"]: + content = SUITE.api.content(ident, variant["name"])["bytes"] + with Image.open(BytesIO(content)) as image: + left = image.getpixel((5, image.height // 2)) + right = image.getpixel((image.width - 6, image.height // 2)) + assert (left == (255, 255, 255)) == transparent + assert right != (255, 255, 255) + assert not image.getexif() + variants.append({**variant, "left_pixel": left, "right_pixel": right}) + return variants + + +def duplicate_check(ident): + before = SUITE.snapshot(ident) + STACK.publish(SUITE.payload(ident, 1)) + STACK.publish(SUITE.payload(ident, 2)) + SUITE.drained() + assert SUITE.snapshot(ident) == before + assert len(STACK.sql("variants", id=ident)) == 6 + + +def large(name, data, transparent=True): + assert SUITE.api is not None + att = SUITE.api.upload(data, name=name + ".png") + ident = att["id"] + versions = [{"version": 1, "variants": verify_large(ident, data, transparent)}] + STACK.admin("reprocess", "--attachment-id", ident, "--pipeline-version", "2") + ps.poll(lambda: SUITE.record(ident)["published_version"] == 2, 90, "v2 publication") + versions.append({"version": 2, "variants": verify_large(ident, data, transparent)}) + duplicate_check(ident) + return { + "attachment_id": ident, + "input_sha256": hashlib.sha256(data).hexdigest(), + "bytes": len(data), + "versions": versions, + "memory_peak": int(STACK.cgroup("worker", "memory.peak")), + "memory_max": int(STACK.cgroup("worker", "memory.max")), + } + + +def concurrent(): + assert SUITE.api is not None + data = (FIXTURES / "rgb16-40mp.png").read_bytes() + SUITE.drained() + STACK.stop("worker") + try: + ids = [SUITE.api.upload(data, name="concurrent-rgb16.png")["id"] for _ in range(2)] + SUITE.queued(2) + finally: + ps.run(["docker", "start", STACK.dc("ps", "-aq", "worker").strip()]) + versions = [] + for version in (1, 2): + if version == 2: + STACK.stop("worker") + try: + for ident in ids: + STACK.admin("reprocess", "--attachment-id", ident, "--pipeline-version", "2") + SUITE.queued(2) + finally: + ps.run(["docker", "start", STACK.dc("ps", "-aq", "worker").strip()]) + for ident in ids: + ps.poll( + lambda ident=ident, version=version: ( + SUITE.record(ident)["published_version"] == version + ), + 90, + "concurrent publication", + ) + variants = {ident: verify_large(ident, data, True) for ident in ids} + events = STACK.sql("timed_events", ids="{" + ",".join(ids) + "}") + job_ids = { + row["job_id"] + for ident in ids + for row in STACK.sql("jobs", id=ident) + if row["pipeline_version"] == version + } + selected = [e for e in events if e["job_id"] in job_ids] + claims = [e["at"] for e in selected if e["kind"] == "claimed"] + done = [e["at"] for e in selected if e["kind"] == "done"] + assert len(claims) == len(done) == 2 + assert max(claims) < min(done), selected + versions.append( + { + "version": version, + "events": selected, + "processing_overlapped": True, + "variants": variants, + } + ) + for ident in ids: + duplicate_check(ident) + peak, limit = (int(STACK.cgroup("worker", name)) for name in ("memory.peak", "memory.max")) + assert peak < limit + return { + "attachment_ids": ids, + "versions": versions, + "memory_peak": peak, + "memory_max": limit, + "memory_events": STACK.cgroup("worker", "memory.events"), + } + + +def forced(**overrides): + data = (FIXTURES / "rgb16-40mp.png").read_bytes() + result = SUITE.limited(data, **overrides) + STACK.restore() + result["next_normal"] = SUITE.smoke_pipeline() + return result + + +try: + SUITE.detect_api() + SUITE.api = ps.Api(SUITE.args) + dead_before = STACK.queues()[ps.DLQ][0] + REPORT["conditions"] = { + "host_load": os.getloadavg(), + "containers": containers(), + "running": ps.run(["docker", "ps", "--format", "{{.Names}} {{.Status}}"]), + "worker_limits": STACK.dc( + "exec", + "-T", + "worker", + "printenv", + "RENDER_MEMORY_MB", + "RENDER_TIMEOUT_SECONDS", + "WORKER_CONCURRENCY", + ), + } + save() + if MODE == "postgres-outage": + case("published_outbox_database_outage", outage) + elif MODE == "png-http": + for name, depth, color in [ + ("gray1", 1, (0,)), + ("gray2", 2, (1,)), + ("gray4", 4, (5,)), + ("gray8", 8, (85,)), + ("gray16", 16, (12345,)), + ("rgb8", 8, (255, 0, 0)), + ("rgb16", 16, (12345, 23456, 34567)), + ]: + case( + name, + lambda name=name, depth=depth, color=color: png(name, *png_with_trns(depth, color)), + ) + case( + "rgb16-adam7-filter4-exif6", + lambda: png( + "adam7", + *png_with_trns( + 16, + (12345, 23456, 34567), + size=(65, 63), + interlace=1, + filtering=4, + orientation=6, + ), + ), + ) + elif MODE == "png-boundary": + for name in ("gray2", "gray4", "gray16", "rgb16"): + case( + name, lambda name=name: large(name, (FIXTURES / (name + "-40mp.png")).read_bytes()) + ) + case( + "gray16-without-trns", + lambda: large( + "gray16-opaque", without_trns((FIXTURES / "gray16-40mp.png").read_bytes()), False + ), + ) + case("concurrent-rgb16", concurrent) + case("forced-timeout", lambda: forced(FAULT_RENDER_TIMEOUT_SECONDS="0.01")) + case("forced-memory", lambda: forced(FAULT_RENDER_MEMORY_MB="200")) + ids = "{" + ",".join(SUITE.api.accepted) + "}" + ps.poll(lambda: not STACK.sql("staging_left", ids=ids), 45, "staging sweep") + SUITE.drained() + REPORT["invariants"] = SUITE.invariants(dead_before) +finally: + STACK.up("postgres") + STACK.restore() + REPORT["finished_at"] = ps.now() + REPORT["result"] = ( + "PASS" + if REPORT["cases"] + and all(x.get("result") == "PASS" for x in REPORT["cases"] + REPORT.get("invariants", [])) + else "FAIL" + ) + save() +raise SystemExit(0 if REPORT["result"] == "PASS" else 1) diff --git a/student-tests/tools/lb_errors/client.py b/student-tests/tools/lb_errors/client.py new file mode 100644 index 0000000..583c560 --- /dev/null +++ b/student-tests/tools/lb_errors/client.py @@ -0,0 +1,43 @@ +import http.client +import json +import sys +import time + +status = int(sys.argv[1]) +path = {502: "/bad", 503: "/none", 504: "/slow"}[status] +if status != 503: + for _ in range(60): + conn = http.client.HTTPConnection("lb", 8080, timeout=2) + conn.request("GET", "/health/ready") + response = conn.getresponse() + response.read() + conn.close() + if response.status == 200: + break + time.sleep(1) + else: + raise RuntimeError("Backend never became ready") +else: + time.sleep(5) +for value in ['a"b', "a\\b", "a\tb", "x" * 200]: + conn = http.client.HTTPConnection("lb", 8080, timeout=20) + start = time.monotonic() + conn.request("GET", path, headers={"X-Request-Id": value}) + response = conn.getresponse() + payload = json.loads(response.read()) + assert response.status == status, response.status + assert response.getheader("X-Request-Id") == value + assert payload["error"]["request_id"] == value + print( + json.dumps( + { + "status": status, + "request_id": value, + "json_valid": True, + "echo_matches": True, + "seconds": round(time.monotonic() - start, 3), + } + ), + flush=True, + ) + conn.close() diff --git a/student-tests/tools/lb_errors/compose.yaml b/student-tests/tools/lb_errors/compose.yaml new file mode 100644 index 0000000..8838145 --- /dev/null +++ b/student-tests/tools/lb_errors/compose.yaml @@ -0,0 +1,25 @@ +services: + lb: + image: haproxy:3.2.26-alpine@sha256:5893840576071e6217cd52ebdcc14f454c6f7a631056fa6f4e0f40d3cac4215b + volumes: [../../../infra/haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro] + init: true + deploy: + resources: + limits: {cpus: "0.5", memory: 128m} + api: + image: ${API_IMAGE:?Set the image built by the lab6 stack} + entrypoint: [python, /fixture/server.py] + volumes: [./:/fixture:ro] + init: true + deploy: + resources: + limits: {cpus: "0.5", memory: 128m} + probe: + image: ${API_IMAGE:?Set the image built by the lab6 stack} + entrypoint: [python, /fixture/client.py] + volumes: [./:/fixture:ro] + profiles: [probe] + init: true + deploy: + resources: + limits: {cpus: "0.5", memory: 128m} diff --git a/student-tests/tools/lb_errors/server.py b/student-tests/tools/lb_errors/server.py new file mode 100644 index 0000000..dc16094 --- /dev/null +++ b/student-tests/tools/lb_errors/server.py @@ -0,0 +1,20 @@ +import socketserver +import time + + +class Handler(socketserver.StreamRequestHandler): + def handle(self) -> None: + request = self.rfile.readline(8192) + while self.rfile.readline(8192) not in {b"\r\n", b""}: + pass + path = request.split(b" ")[1] + if path == b"/bad": + self.wfile.write(b"NOT-HTTP\r\n\r\n") + elif path == b"/slow": + time.sleep(12) + else: + self.wfile.write(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK") + + +with socketserver.ThreadingTCPServer(("0.0.0.0", 8080), Handler) as server: + server.serve_forever() diff --git a/student-tests/unit/test_authentication.py b/student-tests/unit/test_authentication.py index 6837b43..cded5cc 100644 --- a/student-tests/unit/test_authentication.py +++ b/student-tests/unit/test_authentication.py @@ -1,12 +1,24 @@ +import json from base64 import b64encode +from types import SimpleNamespace +from unittest.mock import AsyncMock, Mock import pytest +from starlette.types import Scope +from messenger.identity.application.queries import VerifyCredentials from messenger.identity.entrypoints.authentication import ( + BASIC_CHALLENGE, + LOGIN_PATH, basic_credentials, bearer_token, challenge_for, + guard, ) +from messenger.shared.application.ports import Logger +from messenger.shared.entrypoints.pipeline import RequestPipeline + +NON_ASCII_BASIC = [b"Basic \x80", b"Basic \xff", b"Basic \xc3\xa9", b"Basic YWxpY2U6c2VjcmV0\xff"] def encoded(raw: bytes) -> str: @@ -43,6 +55,46 @@ def test_basic_rejects_malformed(raw: str) -> None: assert basic_credentials(raw) is None +@pytest.mark.parametrize("raw", NON_ASCII_BASIC) +def test_basic_rejects_non_ascii(raw: bytes) -> None: + assert basic_credentials(raw.decode("latin-1")) is None + + +@pytest.mark.parametrize("raw", NON_ASCII_BASIC) +async def test_non_ascii_basic_returns_401_without_credential_lookup(raw: bytes) -> None: + verify = AsyncMock(return_value=None) + container = SimpleNamespace(get=AsyncMock(return_value=verify)) + scope: Scope = { + "type": "http", + "method": "POST", + "path": LOGIN_PATH, + "headers": [(b"authorization", raw), (b"x-request-id", b"non-ascii-basic")], + "app": SimpleNamespace(state=SimpleNamespace(dishka_container=container)), + } + endpoint, send = AsyncMock(), AsyncMock() + pipeline = RequestPipeline(endpoint, Mock(spec=Logger), 1024, 1, guard, "test-instance") + await pipeline(scope, AsyncMock(), send) + start, body = [call.args[0] for call in send.await_args_list] + assert start["status"] == 401 + headers = dict(start["headers"]) + assert headers[b"www-authenticate"] == BASIC_CHALLENGE.encode() + assert headers[b"x-instance-id"] == b"test-instance" + assert headers[b"x-request-id"] == b"non-ascii-basic" + assert headers[b"content-type"] == b"application/json" + assert json.loads(body["body"]) == { + "error": { + "code": "unauthorized", + "message": "Аутентификация не предоставлена или недействительна", + "request_id": "non-ascii-basic", + } + } + container.get.assert_awaited_once_with(VerifyCredentials) + verify.assert_not_awaited() + endpoint.assert_not_awaited() + assert "user" not in scope["state"] + assert scope["state"]["actor"] is None + + def test_bearer_accepts_token68() -> None: assert bearer_token("Bearer abc-DEF_123.~+/==") == "abc-DEF_123.~+/==" assert bearer_token("bearer token") == "token" diff --git a/student-tests/unit/test_haproxy_errors.py b/student-tests/unit/test_haproxy_errors.py new file mode 100644 index 0000000..b15a916 --- /dev/null +++ b/student-tests/unit/test_haproxy_errors.py @@ -0,0 +1,26 @@ +import json +import shlex +from pathlib import Path + +import pytest + +CONFIG = Path(__file__).resolve().parents[2] / "infra/haproxy/haproxy.cfg" + + +@pytest.mark.parametrize("status", [502, 503, 504]) +@pytest.mark.parametrize("request_id", ['a"b', "a\\b", "a\tb", "aÿb", "x" * 200]) +def test_error_templates_escape_json_without_changing_header(status: int, request_id: str) -> None: + line = next( + line.strip() + for line in CONFIG.read_text().splitlines() + if line.strip().startswith(f"http-error status {status} ") + ) + tokens = shlex.split(line) + header = tokens[tokens.index("hdr") + 1 : tokens.index("lf-string")] + assert header == ["X-Request-Id", "%[var(txn.request_id)]"] + template = tokens[tokens.index("lf-string") + 1] + escaped = json.dumps(request_id, ensure_ascii=True)[1:-1] + rendered = template.replace("%[var(txn.request_id),json(ascii)]", escaped) + body = json.loads(rendered) + assert body["error"]["request_id"] == request_id + assert body["error"]["code"] == "unavailable" diff --git a/student-tests/unit/test_image_inspection.py b/student-tests/unit/test_image_inspection.py new file mode 100644 index 0000000..dfacb27 --- /dev/null +++ b/student-tests/unit/test_image_inspection.py @@ -0,0 +1,279 @@ +import struct +import tracemalloc +import zlib +from io import BytesIO + +import pytest +from PIL import Image, ImageFile + +from messenger.attachments.domain.errors import PayloadTooLarge, UnsupportedImage +from messenger.attachments.domain.values import ImageInfo, ImageKind +from messenger.attachments.infrastructure import png as png_decoder +from messenger.attachments.infrastructure.images import PillowImageInspector +from pictures import BROKEN_PNG, DUPLICATE_IHDR_PNG, JPEG, SAMPLE, chunk, png, png_from_idat + +FORMATS = [(0, d, 1) for d in (1, 2, 4, 8, 16)] + [ + (color, depth, samples) + for color, depths, samples in ( + (2, (8, 16), 3), + (3, (1, 2, 4, 8), 1), + (4, (8, 16), 2), + (6, (8, 16), 4), + ) + for depth in depths +] +ADAM7_GRID = ( + "16462646", + "77777777", + "56565656", + "77777777", + "36463646", + "77777777", + "56565656", + "77777777", +) +PIXEL = zlib.compress(b"\x00\x11\x22\x33") +BAD_STREAMS = [ + pytest.param(b"not a zlib stream", id="invalid-zlib"), + pytest.param(PIXEL[:-1], id="truncated-zlib-footer"), + pytest.param(PIXEL[:-1] + bytes([PIXEL[-1] ^ 1]), id="bad-adler32"), + pytest.param(zlib.compress(b"\x00\x11\x22"), id="short-row"), + pytest.param(zlib.compress(b"\x00\x11\x22\x33\x44"), id="long-row"), + pytest.param(zlib.compress(b"\x05\x11\x22\x33"), id="invalid-filter"), +] + + +def scanlines(width: int, height: int, bits: int, interlace: int, filtering: int = 0) -> bytes: + rows = [] + for number in range(1, 8) if interlace else (0,): + for y in range(height): + columns = ( + sum(int(ADAM7_GRID[y % 8][x % 8]) == number for x in range(width)) + if interlace + else width + ) + if columns: + rows.append(bytes([filtering]) + b"\x00" * ((columns * bits + 7) // 8)) + return b"".join(rows) + + +async def test_png_with_valid_crc_and_invalid_zlib_is_rejected() -> None: + assert len(BROKEN_PNG) == 74 + with Image.open(BytesIO(BROKEN_PNG)) as image: + image.verify() + with Image.open(BytesIO(BROKEN_PNG)) as image, pytest.raises(OSError): + image.load() + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(BROKEN_PNG, ImageKind.PNG) + + +async def test_duplicate_ihdr_cannot_disagree_with_pixel_validation() -> None: + assert len(DUPLICATE_IHDR_PNG) == 94 + with Image.open(BytesIO(DUPLICATE_IHDR_PNG)) as image: + assert image.size == (2, 2) + image.verify() + with Image.open(BytesIO(DUPLICATE_IHDR_PNG)) as image, pytest.raises(OSError): + image.load() + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(DUPLICATE_IHDR_PNG, ImageKind.PNG) + + +@pytest.mark.parametrize( + "header", + [ + (1, 1, 8, 2, 0, 0, 0), + (2, 2, 8, 2, 0, 0, 0), + (1, 1, 16, 2, 0, 0, 0), + (1, 1, 8, 6, 0, 0, 0), + (1, 1, 8, 2, 0, 0, 1), + (8001, 5000, 8, 2, 0, 0, 0), + ], + ids=["identical", "dimensions", "depth", "color", "interlace", "over-pixel-limit"], +) +@pytest.mark.parametrize("position", ["before-idat", "between-idat", "after-idat"]) +async def test_duplicate_headers_are_rejected_before_inflating( + header: tuple[int, ...], position: str, monkeypatch: pytest.MonkeyPatch +) -> None: + data = png_from_idat(PIXEL) + duplicate = chunk(b"IHDR", struct.pack(">IIBBBBB", *header)) + if position == "before-idat": + data = data[:33] + duplicate + data[33:] + elif position == "after-idat": + data = data[:-12] + duplicate + data[-12:] + else: + data = ( + data[:33] + + chunk(b"IDAT", PIXEL[:3]) + + duplicate + + chunk(b"IDAT", PIXEL[3:]) + + data[-12:] + ) + + def forbidden_inflate(*args: object) -> None: + pytest.fail("ambiguous PNG header must be rejected before decompression") + + monkeypatch.setattr(png_decoder.zlib, "decompressobj", forbidden_inflate) + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) + + +@pytest.mark.parametrize("damage", ["not-first", "missing", "short", "long"]) +async def test_ihdr_must_be_first_and_have_exact_length(damage: str) -> None: + data = png_from_idat(PIXEL) + if damage == "not-first": + data = data[:8] + chunk(b"tEXt", b"name\x00value") + data[8:] + elif damage == "missing": + data = data[:8] + data[33:] + else: + header = data[16:29] + header = header[:-1] if damage == "short" else header + b"\x00" + data = data[:8] + chunk(b"IHDR", header) + data[33:] + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) + + +@pytest.mark.parametrize("stream", BAD_STREAMS) +async def test_corrupt_pixels_are_rejected_even_with_valid_chunk_crc(stream: bytes) -> None: + data = png_from_idat(stream, chunk_size=1) + with Image.open(BytesIO(data)) as image: + image.verify() + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) + + +async def test_idat_chunks_must_be_consecutive() -> None: + data = png_from_idat(PIXEL) + data = ( + data[:33] + + chunk(b"IDAT", PIXEL[:3]) + + chunk(b"tEXt", b"name\x00value") + + chunk(b"IDAT", PIXEL[3:]) + + data[-12:] + ) + with Image.open(BytesIO(data)) as image: + image.verify() + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) + + +@pytest.mark.parametrize("padding", [b"\x00" * 131_072, b"unused buffer", zlib.compress(b"")]) +async def test_unused_idat_trailing_bytes_are_ignored(padding: bytes) -> None: + data = png_from_idat(PIXEL + padding, chunk_size=1_000_000) + with Image.open(BytesIO(data)) as image: + image.load() + assert await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) == ImageInfo( + ImageKind.PNG, 1, 1 + ) + + +@pytest.mark.parametrize(("color", "depth", "samples"), FORMATS) +@pytest.mark.parametrize(("width", "height"), [(1, 1), (1, 9), (9, 1), (5, 5), (17, 13)]) +@pytest.mark.parametrize("interlace", [0, 1]) +async def test_supported_png_formats_match_pillow_decoding( + *, color: int, depth: int, samples: int, width: int, height: int, interlace: int +) -> None: + raw = scanlines(width, height, depth * samples, interlace) + data = png_from_idat( + zlib.compress(raw), + width, + height, + depth=depth, + color=color, + interlace=interlace, + chunk_size=3, + ) + with Image.open(BytesIO(data)) as image: + image.load() + assert image.size == (width, height) + assert await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) == ImageInfo( + ImageKind.PNG, width, height + ) + + +@pytest.mark.parametrize("filtering", range(5)) +@pytest.mark.parametrize("interlace", [0, 1]) +@pytest.mark.parametrize("block_size", [3, 7, 31]) +async def test_filters_and_passes_cross_decompression_blocks( + filtering: int, interlace: int, block_size: int, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(png_decoder, "BLOCK_BYTES", block_size) + raw = scanlines(17, 13, 32, interlace, filtering) + data = png_from_idat(zlib.compress(raw), 17, 13, color=6, interlace=interlace) + with Image.open(BytesIO(data)) as image: + image.load() + assert (await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG)).width == 17 + + +@pytest.mark.parametrize("interlace", [0, 1]) +@pytest.mark.parametrize("damage", ["filter", "short", "long"]) +async def test_corruption_in_later_rows_or_passes( + interlace: int, damage: str, monkeypatch: pytest.MonkeyPatch +) -> None: + monkeypatch.setattr(png_decoder, "BLOCK_BYTES", 7) + raw = bytearray(scanlines(17, 13, 32, interlace)) + if damage == "filter": + raw[-69] = 255 + elif damage == "short": + raw.pop() + else: + raw.append(0) + data = png_from_idat(zlib.compress(raw), 17, 13, color=6, interlace=interlace, chunk_size=5) + with pytest.raises(UnsupportedImage): + await PillowImageInspector(40_000_000, 1).inspect(data, ImageKind.PNG) + + +@pytest.mark.parametrize(("width", "height"), [(1_000_000, 1), (1000, 1000)]) +def test_png_validation_does_not_allocate_pixels_or_whole_rows( + width: int, height: int, monkeypatch: pytest.MonkeyPatch +) -> None: + data = png_from_idat( + zlib.compress(b"\x00" * ((width * 8 + 1) * height)), width, height, depth=16, color=6 + ) + + def forbidden_load(*args: object, **kwargs: object) -> None: + pytest.fail("PNG validation must not allocate a Pillow pixel buffer") + + monkeypatch.setattr(ImageFile.ImageFile, "load", forbidden_load) + inspector = PillowImageInspector(40_000_000, 1) + tracemalloc.start() + try: + assert inspector._inspect(data, ImageKind.PNG) == ImageInfo(ImageKind.PNG, width, height) + _, peak = tracemalloc.get_traced_memory() + finally: + tracemalloc.stop() + assert peak < 2_000_000 + + +def test_excess_inflated_data_is_rejected_with_bounded_memory() -> None: + data = png_from_idat(zlib.compress(b"\x00" * 8_000_000)) + inspector = PillowImageInspector(40_000_000, 1) + tracemalloc.start() + try: + with pytest.raises(UnsupportedImage): + inspector._inspect(data, ImageKind.PNG) + _, peak = tracemalloc.get_traced_memory() + finally: + tracemalloc.stop() + assert peak < 2_000_000 + + +async def test_pixel_limit_precedes_pixel_validation(monkeypatch: pytest.MonkeyPatch) -> None: + def forbidden_validation(data: bytes) -> None: + pytest.fail("oversized PNG must be rejected before decompression") + + monkeypatch.setattr( + "messenger.attachments.infrastructure.images.verify_png_pixels", forbidden_validation + ) + with pytest.raises(PayloadTooLarge): + await PillowImageInspector(40_000_000, 1).inspect( + png(8001, 5000, rows=False), ImageKind.PNG + ) + + +async def test_exact_pixel_limit_and_existing_fixtures_still_work() -> None: + inspector = PillowImageInspector(40_000_000, 1) + assert await inspector.inspect(png(8000, 5000), ImageKind.PNG) == ImageInfo( + ImageKind.PNG, 8000, 5000 + ) + assert (await inspector.inspect(SAMPLE, ImageKind.PNG)).kind is ImageKind.PNG + assert (await inspector.inspect(JPEG, ImageKind.JPEG)).kind is ImageKind.JPEG diff --git a/student-tests/unit/test_nul_inputs.py b/student-tests/unit/test_nul_inputs.py new file mode 100644 index 0000000..822f285 --- /dev/null +++ b/student-tests/unit/test_nul_inputs.py @@ -0,0 +1,95 @@ +from base64 import b64encode +from datetime import UTC, datetime, timedelta +from types import SimpleNamespace +from unittest.mock import AsyncMock, Mock +from uuid import uuid4 + +import pytest +from starlette.types import Scope + +from messenger.identity.application.queries import VerifyCredentials +from messenger.identity.domain.errors import InvalidUserData +from messenger.identity.domain.values import DisplayName +from messenger.identity.entrypoints.authentication import ( + BASIC_CHALLENGE, + LOGIN_PATH, + basic_credentials, + guard, +) +from messenger.messaging.application.commands import PostMessage +from messenger.messaging.application.handlers import PostMessageHandler +from messenger.messaging.application.ports import ChatDirectory, MessageLog, MessagingUnitOfWork +from messenger.messaging.domain.errors import ChatNotFound, InvalidChatData, InvalidMessageText +from messenger.messaging.domain.values import ChatTitle, MessageText +from messenger.shared.application.ports import Clock, IdGenerator +from messenger.shared.domain.errors import DomainError +from messenger.shared.entrypoints.pipeline import Rejection + +NUL_TEXTS = ["\x00", "\x00abc", "abc\x00def", "abc\x00"] + + +@pytest.mark.parametrize("username", NUL_TEXTS) +def test_basic_rejects_nul_username(username: str) -> None: + raw = b64encode(f"{username}:synthetic-password".encode()).decode() + assert basic_credentials(f"Basic {raw}") is None + + +async def test_nul_username_is_rejected_before_credential_lookup() -> None: + verify = AsyncMock(return_value=None) + container = SimpleNamespace(get=AsyncMock(return_value=verify)) + scope: Scope = { + "method": "POST", + "path": LOGIN_PATH, + "headers": [(b"authorization", b"Basic " + b64encode(b"abc\x00def:synthetic-password"))], + "app": SimpleNamespace(state=SimpleNamespace(dishka_container=container)), + } + assert await guard(scope) == Rejection( + 401, "unauthorized", (("www-authenticate", BASIC_CHALLENGE),) + ) + container.get.assert_awaited_once_with(VerifyCredentials) + verify.assert_not_awaited() + assert "user" not in scope["state"] + + +@pytest.mark.parametrize("raw", NUL_TEXTS) +@pytest.mark.parametrize( + ("kind", "error"), + [ + (DisplayName, InvalidUserData), + (ChatTitle, InvalidChatData), + (MessageText, InvalidMessageText), + ], +) +def test_text_values_reject_nul( + kind: type[DisplayName | ChatTitle | MessageText], error: type[DomainError], raw: str +) -> None: + with pytest.raises(error): + kind(raw) + + +@pytest.mark.parametrize("kind", [DisplayName, ChatTitle, MessageText]) +def test_text_values_preserve_unicode_and_whitespace( + kind: type[DisplayName | ChatTitle | MessageText], +) -> None: + raw = " Привет\tмир\n👋 " + assert kind(raw).value == raw + + +@pytest.mark.parametrize("member", [False, True]) +async def test_nul_message_checks_access_without_writing(member: bool) -> None: + chats = AsyncMock(spec=ChatDirectory) + chats.chat_for_member.return_value = Mock() if member else None + log = AsyncMock(spec=MessageLog) + log.post.return_value = None + uow = Mock(spec=MessagingUnitOfWork) + clock = Mock(spec=Clock) + clock.now.return_value = datetime(2026, 1, 1, tzinfo=UTC) + handler = PostMessageHandler( + uow, log, chats, clock, Mock(spec=IdGenerator), ttl=timedelta(days=1) + ) + command = PostMessage(uuid4(), uuid4(), "abc\x00def", "same-key", b"fingerprint") + with pytest.raises(InvalidMessageText if member else ChatNotFound): + await handler(command) + chats.chat_for_member.assert_awaited_once_with(command.chat_id, command.sender_id) + log.post.assert_not_awaited() + uow.record.assert_not_called() diff --git a/student-tests/unit/test_png_memory.py b/student-tests/unit/test_png_memory.py new file mode 100644 index 0000000..31d756d --- /dev/null +++ b/student-tests/unit/test_png_memory.py @@ -0,0 +1,110 @@ +import json +import subprocess +import sys +import weakref +from pathlib import Path + +import pytest +from PIL import Image, ImageFile +from PIL._util import DeferredError + +from messenger.attachments.infrastructure.images import RenderLimits, render_variants +from png_trns_fixtures import boundary_png, png_with_trns + +CASES = [(2, (1,)), (4, (5,)), (16, (12345,)), (16, (12345, 23456, 34567))] +LIMITS = RenderLimits(10_485_760, 40_000_000) +SAMPLE = Path(__file__).parents[2] / "tests/fixtures/sample.png" + + +@pytest.mark.parametrize("depth,key", CASES) +def test_live_pixel_buffers_are_bounded( + monkeypatch: pytest.MonkeyPatch, depth: int, key: tuple[int, ...] +) -> None: + size = (1025, 769) + data, reference = png_with_trns(depth, key, size=size) + expected = render_variants(reference, LIMITS) + references: dict[int, weakref.ReferenceType[Image.Image]] = {} + peak = 0 + original_new = Image.Image._new + original_load = ImageFile.ImageFile.load_prepare + + def record(image: Image.Image) -> None: + nonlocal peak + references[id(image)] = weakref.ref(image) + buffers = {} + for ref in references.values(): + current = ref() + if current is None or current._im is None or isinstance(current._im, DeferredError): + continue + stride = 1 if current.mode in {"1", "L", "P"} else 4 + if current.mode.startswith("I;16"): + stride = 2 + buffers[id(current.im)] = current.width * current.height * stride + peak = max(peak, sum(buffers.values())) + + def allocated(image: Image.Image, core: Image.core.ImagingCore) -> Image.Image: + result = original_new(image, core) + record(result) + return result + + def loaded(image: ImageFile.ImageFile) -> None: + original_load(image) + record(image) + + monkeypatch.setattr(Image.Image, "_new", allocated) + monkeypatch.setattr(ImageFile.ImageFile, "load_prepare", loaded) + assert render_variants(data, LIMITS) == expected + assert peak < size[0] * size[1] * 8 + 2**20, peak + print(json.dumps({"depth": depth, "key": key, "pixel_buffer_peak_bytes": peak})) + + +@pytest.mark.skipif(sys.platform != "linux", reason="RLIMIT_AS проверяется в Linux") +def test_boundary_pngs_fit_worker_address_space(tmp_path: Path) -> None: + script = """ +import json +from io import BytesIO +from pathlib import Path +import resource +import signal +import sys + +import messenger.worker +from PIL import Image +from messenger.attachments.infrastructure.images import RenderLimits, render_variants + +resource.setrlimit(resource.RLIMIT_AS, (448 << 20, 448 << 20)) +limits = RenderLimits(10_485_760, 40_000_000) +for version in (1, 2): + signal.alarm(30) + variants = render_variants(Path(sys.argv[1]).read_bytes(), limits, version) + signal.alarm(0) + assert [(v.name, v.width, v.height) for v in variants] == [ + ("thumbnail", 256, 160), ("crop", 128, 128), ("optimized", 1280, 800) + ] + for variant in variants: + with Image.open(BytesIO(variant.data)) as image: + assert image.getpixel((5, image.height // 2)) == (255, 255, 255) + assert image.getpixel((image.width - 6, image.height // 2)) != (255, 255, 255) +assert len(render_variants(Path(sys.argv[2]).read_bytes(), limits)) == 3 +print(json.dumps({ + "versions": [1, 2], "max_rss_kib": resource.getrusage(resource.RUSAGE_SELF).ru_maxrss +})) +""" + for name, (depth, key) in zip(("gray2", "gray4", "gray16", "rgb16"), CASES, strict=True): + fixture = tmp_path / f"{name}-40mp.png" + fixture.write_bytes(boundary_png(depth, key)) + result = subprocess.run( + [ + sys.executable, + "-c", + script, + str(fixture), + str(SAMPLE), + ], + capture_output=True, + text=True, + timeout=65, + check=True, + ) + assert json.loads(result.stdout)["versions"] == [1, 2] + print(name, result.stdout.strip()) diff --git a/student-tests/unit/test_png_transparency.py b/student-tests/unit/test_png_transparency.py new file mode 100644 index 0000000..b72185d --- /dev/null +++ b/student-tests/unit/test_png_transparency.py @@ -0,0 +1,67 @@ +from io import BytesIO + +import pytest +from PIL import Image + +from messenger.attachments.domain.values import ImageKind +from messenger.attachments.infrastructure.images import ( + PillowImageInspector, + RenderLimits, + render_variants, +) +from png_trns_fixtures import png_with_trns + +LIMITS = RenderLimits(10_485_760, 40_000_000) + + +@pytest.mark.parametrize("version", [1, 2]) +@pytest.mark.parametrize("depth,transparent", [(2, (1,)), (4, (5,)), (16, (12345, 23456, 34567))]) +async def test_review_samples_have_white_transparency( + version: int, depth: int, transparent: tuple[int, ...] +) -> None: + data, reference = png_with_trns(depth, transparent) + info = await PillowImageInspector(LIMITS.max_pixels, 1).inspect(data, ImageKind.PNG) + assert (info.width, info.height) == (64, 64) + variants = render_variants(data, LIMITS, version) + for variant in variants: + with Image.open(BytesIO(variant.data)) as image: + assert image.getpixel((5, image.height // 2)) == (255, 255, 255), variant.name + assert variants == render_variants(reference, LIMITS, version) + + +@pytest.mark.parametrize("version", [1, 2]) +@pytest.mark.parametrize( + "depth,key", + [(depth, key) for depth in (1, 2, 4) for key in range(1 << depth)] + + [(8, 0), (8, 85), (8, 255), (16, 0), (16, 12345), (16, 65535)], +) +def test_grayscale_keys_preserve_opaque_neighbors(version: int, depth: int, key: int) -> None: + data, reference = png_with_trns(depth, (key,)) + assert render_variants(data, LIMITS, version) == render_variants(reference, LIMITS, version) + + +@pytest.mark.parametrize("version", [1, 2]) +@pytest.mark.parametrize("interlace", [0, 1]) +@pytest.mark.parametrize("filtering", range(5)) +@pytest.mark.parametrize("depth,transparent", [(2, (1,)), (4, (5,)), (16, (12345, 23456, 34567))]) +async def test_png_filters_and_adam7_preserve_exact_samples( + version: int, interlace: int, filtering: int, depth: int, transparent: tuple[int, ...] +) -> None: + data, reference = png_with_trns( + depth, transparent, size=(65, 63), interlace=interlace, filtering=filtering + ) + info = await PillowImageInspector(LIMITS.max_pixels, 1).inspect(data, ImageKind.PNG) + assert (info.width, info.height) == (65, 63) + assert render_variants(data, LIMITS, version) == render_variants(reference, LIMITS, version) + + +@pytest.mark.parametrize("version", [1, 2]) +@pytest.mark.parametrize("size", [(1, 1), (1, 9), (9, 1), (65, 63)]) +@pytest.mark.parametrize("transparent", [(0, 0, 0), (123, 234, 45), (65535, 65535, 65535)]) +def test_rgb16_small_passes_orientation_and_key_extremes( + version: int, size: tuple[int, int], transparent: tuple[int, ...] +) -> None: + data, reference = png_with_trns( + 16, transparent, size=size, interlace=1, filtering=4, orientation=6 + ) + assert render_variants(data, LIMITS, version) == render_variants(reference, LIMITS, version) diff --git a/student-tests/unit/test_png_upload.py b/student-tests/unit/test_png_upload.py new file mode 100644 index 0000000..bf02676 --- /dev/null +++ b/student-tests/unit/test_png_upload.py @@ -0,0 +1,83 @@ +from datetime import UTC, datetime +from types import SimpleNamespace +from unittest.mock import AsyncMock, Mock +from uuid import uuid4 + +import pytest +from fastapi import FastAPI +from httpx import ASGITransport, AsyncClient +from starlette.types import Scope + +from fakes import NullLogger, RecordingPublisher +from messenger.attachments.application.bus import AttachmentsCommandBus +from messenger.attachments.application.commands import UploadAttachment +from messenger.attachments.application.handlers import UploadAttachmentHandler, UploadSlots +from messenger.attachments.application.ports import ( + AttachmentRepository, + AttachmentsUnitOfWork, + ChatMembership, + ObjectStorage, +) +from messenger.attachments.entrypoints.errors import ERROR_CODES +from messenger.attachments.entrypoints.http import uploads_router +from messenger.attachments.infrastructure.images import PillowImageInspector +from messenger.shared.application.ports import Clock, IdGenerator +from messenger.shared.entrypoints.errors import install +from messenger.shared.entrypoints.pipeline import RequestPipeline +from pictures import BROKEN_PNG, DUPLICATE_IHDR_PNG + + +@pytest.mark.parametrize( + "data", [BROKEN_PNG, DUPLICATE_IHDR_PNG], ids=["bad-zlib", "duplicate-ihdr"] +) +async def test_broken_png_returns_415_before_any_storage_write(data: bytes) -> None: + uow = Mock(spec=AttachmentsUnitOfWork) + uow.attachments = AsyncMock(spec=AttachmentRepository) + uow.transaction.return_value = AsyncMock() + uow.collect_new_events.return_value = [] + storage = AsyncMock(spec=ObjectStorage) + membership = AsyncMock(spec=ChatMembership) + membership.is_member.return_value = True + logger = NullLogger() + publisher = RecordingPublisher() + handler = UploadAttachmentHandler( + uow, + membership, + PillowImageInspector(40_000_000, 1), + storage, + clock=Mock(spec=Clock, now=Mock(return_value=datetime(2026, 11, 6, tzinfo=UTC))), + ids=Mock(spec=IdGenerator, new_id=Mock(side_effect=uuid4)), + limit=10_485_760, + slots=UploadSlots(1), + logger=logger, + ) + bus = AttachmentsCommandBus({UploadAttachment: handler}, uow, publisher) + container = SimpleNamespace(get=AsyncMock(return_value=bus)) + owner, chat = uuid4(), uuid4() + + async def guard(scope: Scope) -> None: + scope["state"].update(actor=owner, dishka_container=container) + + app = FastAPI() + app.include_router(uploads_router) + install(app, logger, ERROR_CODES, lambda _: "Bearer", "offline-test") + transport = ASGITransport( + app=RequestPipeline(app, logger, 10_485_760, 5, guard, "offline-test") + ) + async with AsyncClient(transport=transport, base_url="http://testserver") as http: + response = await http.post( + f"/api/v1/chats/{chat}/attachments?filename=broken.png", + headers={"Content-Type": "image/png", "X-Request-Id": "png-regression"}, + content=data, + ) + assert response.status_code == 415, response.text + assert response.json()["error"]["code"] == "unsupported_media_type" + assert response.json()["error"]["request_id"] == "png-regression" + assert response.headers["X-Request-Id"] == "png-regression" + assert response.headers["X-Instance-Id"] == "offline-test" + membership.is_member.assert_awaited_once_with(chat, owner) + uow.transaction.assert_not_called() + uow.commit.assert_not_called() + assert uow.attachments.mock_calls == [] + assert storage.mock_calls == [] + assert publisher.events == [] diff --git a/student-tests/unit/test_renderer.py b/student-tests/unit/test_renderer.py index c7367ae..cfb4190 100644 --- a/student-tests/unit/test_renderer.py +++ b/student-tests/unit/test_renderer.py @@ -5,7 +5,12 @@ from PIL import Image from messenger.attachments.application.ports import Rendition from messenger.attachments.domain.errors import ImageTooDemanding, UnreadableImage -from messenger.attachments.infrastructure.images import RenderLimits, render_variants +from messenger.attachments.domain.values import ImageKind +from messenger.attachments.infrastructure.images import ( + PillowImageInspector, + RenderLimits, + render_variants, +) from pictures import SAMPLE LIMITS = RenderLimits(max_bytes=10_485_760, max_pixels=40_000_000) @@ -22,8 +27,8 @@ def encoded(image: Image.Image, kind: str = "PNG", **options: object) -> bytes: return buffer.getvalue() -def rendered(data: bytes) -> dict[str, Image.Image]: - renditions: list[Rendition] = render_variants(data, LIMITS) +def rendered(data: bytes, version: int = 1) -> dict[str, Image.Image]: + renditions: list[Rendition] = render_variants(data, LIMITS, version) assert [rendition.name for rendition in renditions] == ["thumbnail", "crop", "optimized"] images = {} for rendition in renditions: @@ -87,6 +92,37 @@ def test_palette_transparency_is_composed_on_white() -> None: assert image.convert("RGB").getpixel((5, 5)) == (255, 255, 255) +@pytest.mark.parametrize("version", [1, 2]) +@pytest.mark.parametrize( + ("mode", "transparent", "opaque", "expected"), + [ + ("RGB", (255, 0, 0), (32, 96, 160), (32, 96, 160)), + ("L", 0, 96, (96, 96, 96)), + ("1", 0, 255, (255, 255, 255)), + ("1", 255, 0, (0, 0, 0)), + ("I;16", 12345, 12346, (48, 48, 48)), + ], +) +async def test_png_trns_is_white_without_changing_opaque_pixels( + version: int, + mode: str, + transparent: int | tuple[int, int, int], + opaque: int | tuple[int, int, int], + expected: tuple[int, int, int], +) -> None: + source = Image.new(mode, (64, 64), transparent) + source.paste(Image.new(mode, (32, 64), opaque), (32, 0)) + assert source.getpixel((58, 32)) == opaque + data = encoded(source, transparency=transparent) + info = await PillowImageInspector(LIMITS.max_pixels, 1).inspect(data, ImageKind.PNG) + assert (info.width, info.height) == (64, 64) + for image in rendered(data, version).values(): + assert image.getpixel((5, image.height // 2)) == (255, 255, 255) + pixel = image.getpixel((image.width - 6, image.height // 2)) + assert isinstance(pixel, tuple) + assert all(abs(a - b) <= 3 for a, b in zip(pixel, expected, strict=True)) + + @pytest.mark.parametrize( ("orientation", "thumbnail", "optimized"), [(6, (128, 256), (200, 400)), (3, (256, 128), (400, 200))], diff --git a/student-tests/unit/test_session_cache.py b/student-tests/unit/test_session_cache.py new file mode 100644 index 0000000..cb79ef6 --- /dev/null +++ b/student-tests/unit/test_session_cache.py @@ -0,0 +1,161 @@ +import asyncio +from datetime import UTC, datetime, timedelta +from typing import cast +from unittest.mock import AsyncMock +from uuid import uuid4 + +import pytest +from redis.asyncio import Redis +from redis.exceptions import ConnectionError as CacheConnectionError + +from fakes import NullLogger +from messenger.identity.domain.models import Session +from messenger.identity.infrastructure.valkey import ( + FILL, + REVOKE, + REVOKED, + CachedSessionDirectory, + key_of, + milliseconds, +) + +NOW = datetime(2030, 1, 1, tzinfo=UTC) + + +class CacheModel: + def __init__(self) -> None: + self.values: dict[str, str] = {} + self.expires: dict[str, int] = {} + + async def get(self, key: str) -> str | None: + return self.values.get(key) + + async def set(self, key: str, value: str, *, pxat: int, nx: bool = False) -> bool: + if nx and key in self.values: + return False + self.values[key], self.expires[key] = value, pxat + return True + + async def delete(self, key: str) -> None: + self.values.pop(key, None) + self.expires.pop(key, None) + + async def eval(self, script: str, count: int, key: str, marker: str, *args: str | int) -> bool: + assert count == 2 + if script == REVOKE: + value, until = args + assert isinstance(value, str) and isinstance(until, int) + await self.set(key, value, pxat=until) + await self.delete(marker) + return True + assert script == FILL + nonce, value, until = args + assert isinstance(value, str) and isinstance(until, int) + if await self.get(marker) != nonce: + return False + await self.delete(marker) + return bool(value) and await self.set(key, value, pxat=until, nx=True) + + +def directory(origin: AsyncMock, cache: CacheModel, ttl: int = 300) -> CachedSessionDirectory: + return CachedSessionDirectory( + origin, cast(Redis, cache), NullLogger(), limit=timedelta(seconds=ttl), cooldown=1 + ) + + +@pytest.fixture +def session() -> Session: + return Session.issue(user_id=uuid4(), issued_at=NOW, ttl=timedelta(seconds=30))[1] + + +@pytest.mark.parametrize("ttl", [10, 300]) +async def test_cache_hit_keeps_absolute_ttl_without_reading_origin( + session: Session, ttl: int +) -> None: + origin, cache = AsyncMock(), CacheModel() + origin.find.return_value = session + cached = directory(origin, cache, ttl) + assert await cached.find(session.token_hash, NOW) == session + assert await directory(origin, cache, ttl).find(session.token_hash, NOW) == session + origin.find.assert_awaited_once() + assert cache.expires == { + key_of(session.token_hash): milliseconds( + min(session.expires_at, NOW + timedelta(seconds=ttl)) + ) + } + + +@pytest.mark.parametrize("loss", ["none", "flushall", "evict", "replacement"]) +async def test_delayed_fill_cannot_revive_logged_out_session(session: Session, loss: str) -> None: + origin, cache = AsyncMock(), CacheModel() + origin.find.return_value = session + entered, released = asyncio.Event(), asyncio.Event() + + async def stale_find(token_hash: bytes, now: datetime) -> Session: + entered.set() + await released.wait() + return session + + slow = AsyncMock() + slow.find.side_effect = stale_find + async with asyncio.TaskGroup() as group: + reader = group.create_task(directory(slow, cache).find(session.token_hash, NOW)) + await asyncio.wait_for(entered.wait(), 1) + try: + await directory(origin, cache).revoke(session) + origin.find.return_value = None + key = key_of(session.token_hash) + if loss == "flushall": + cache.values.clear() + elif loss in {"evict", "replacement"}: + await cache.delete(key) + if loss == "replacement": + await cache.set(f"{key}:fill", uuid4().hex, pxat=milliseconds(session.expires_at)) + finally: + released.set() + assert reader.result() == session + assert await directory(origin, cache).find(session.token_hash, NOW) is None + assert await cache.get(key) in {None, REVOKED} + + +async def test_failed_reservation_never_fills_from_stale_database_result(session: Session) -> None: + cache = CacheModel() + origin = AsyncMock() + key = key_of(session.token_hash) + await cache.set(f"{key}:fill", "another-reader", pxat=milliseconds(session.expires_at)) + + async def find(token_hash: bytes, now: datetime) -> Session: + cache.values.clear() + return session + + origin.find.side_effect = find + assert await directory(origin, cache).find(session.token_hash, NOW) == session + assert await cache.get(key) is None + + +async def test_missing_session_releases_only_its_own_reservation(session: Session) -> None: + origin, cache = AsyncMock(), CacheModel() + origin.find.return_value = None + assert await directory(origin, cache).find(session.token_hash, NOW) is None + assert cache.values == {} + + +@pytest.mark.parametrize("failed_operation", ["get", "set"]) +async def test_cache_recovery_during_database_read_does_not_allow_unreserved_fill( + session: Session, failed_operation: str +) -> None: + origin, cache = AsyncMock(), AsyncMock() + cache.get.return_value = None + getattr(cache, failed_operation).side_effect = CacheConnectionError("offline") + cached = CachedSessionDirectory( + origin, cache, NullLogger(), limit=timedelta(seconds=300), cooldown=1 + ) + + async def find(token_hash: bytes, now: datetime) -> Session: + cached._resume_at = 0.0 + return session + + origin.find.side_effect = find + assert await cached.find(session.token_hash, NOW) == session + assert cache.set.await_count == (failed_operation == "set") + cache.eval.assert_not_awaited() diff --git a/student-tests/unit/test_worker_delivery.py b/student-tests/unit/test_worker_delivery.py new file mode 100644 index 0000000..2496b08 --- /dev/null +++ b/student-tests/unit/test_worker_delivery.py @@ -0,0 +1,63 @@ +import asyncio +import json +from datetime import UTC, datetime +from pathlib import Path +from unittest.mock import AsyncMock, Mock, call +from uuid import uuid4 + +import pytest + +from messenger.attachments.application.commands import ProcessJob +from messenger.attachments.domain.jobs import Job, Outcome +from messenger.attachments.entrypoints.worker import REQUEUE_DELAY_SECONDS, handle_job +from messenger.shared.application.errors import Unavailable + + +def test_infrastructure_requeues_preserve_the_message_and_dead_letter_rejections() -> None: + path = Path(__file__).resolve().parents[2] / "infra/rabbitmq/definitions.json" + definitions = json.loads(path.read_text()) + policy = next(p for p in definitions["policies"] if p["name"] == "attachments-process") + queue = next(q for q in definitions["queues"] if q["name"] == "attachments.process") + assert policy["definition"]["delivery-limit"] == -1 + assert "x-delivery-limit" not in queue["arguments"] + assert policy["definition"]["dead-letter-exchange"] == "attachments.dlx" + assert policy["definition"]["dead-letter-strategy"] == "at-least-once" + + +async def test_database_outage_never_acks_and_recovery_keeps_job_and_attempt( + monkeypatch: pytest.MonkeyPatch, +) -> None: + job = Job(uuid4(), uuid4(), 1, 1, datetime.now(UTC)) + message = AsyncMock(body=json.dumps(job.payload()).encode()) + bus, logger, sleep = AsyncMock(), Mock(), AsyncMock() + monkeypatch.setattr("messenger.attachments.entrypoints.worker.asyncio.sleep", sleep) + bus.execute.side_effect = [Unavailable("database unavailable")] * 12 + [Outcome.DONE] + for _ in range(12): + await handle_job(message, bus, logger, Mock()) + message.ack.assert_not_awaited() + message.reject.assert_not_awaited() + assert message.nack.await_args_list == [call(requeue=True)] * 12 + assert sleep.await_args_list == [call(REQUEUE_DELAY_SECONDS)] * 12 + await handle_job(message, bus, logger, Mock()) + message.ack.assert_awaited_once_with() + assert bus.execute.await_args_list == [call(ProcessJob(job))] * 13 + + +async def test_invalid_message_is_dead_lettered_without_calling_the_bus() -> None: + message, bus = AsyncMock(body=b"{}"), AsyncMock() + await handle_job(message, bus, Mock(), Mock()) + message.reject.assert_awaited_once_with(requeue=False) + message.ack.assert_not_awaited() + message.nack.assert_not_awaited() + bus.execute.assert_not_awaited() + + +async def test_cancelled_handler_leaves_delivery_unacknowledged() -> None: + job = Job(uuid4(), uuid4(), 1, 1, datetime.now(UTC)) + message, bus = AsyncMock(body=json.dumps(job.payload()).encode()), AsyncMock() + bus.execute.side_effect = asyncio.CancelledError + with pytest.raises(asyncio.CancelledError): + await handle_job(message, bus, Mock(), Mock()) + message.ack.assert_not_awaited() + message.nack.assert_not_awaited() + message.reject.assert_not_awaited() diff --git a/tools/plot_observability.py b/tools/plot_observability.py index 255b8fa..11e8534 100644 --- a/tools/plot_observability.py +++ b/tools/plot_observability.py @@ -1,3 +1,4 @@ +import argparse import json import statistics from pathlib import Path @@ -27,7 +28,10 @@ def values(rows, mode, key): def main(): - rows = json.loads((DIRECTORY / "comparison.json").read_text())["runs"] + parser = argparse.ArgumentParser() + parser.add_argument("directory", type=Path, nargs="?", default=DIRECTORY) + directory = parser.parse_args().directory + rows = json.loads((directory / "comparison.json").read_text())["runs"] figure, axes = plt.subplots(2, 2, figsize=(11, 7), constrained_layout=True) panels = ( ("latency", "Normal request p95", "milliseconds"), @@ -55,8 +59,8 @@ def main(): "Dots: actual runs; bars: median; whiskers: observed range", fontsize=13, ) - figure.savefig(DIRECTORY / "comparison.png", dpi=180) - figure.savefig(DIRECTORY / "comparison.svg") + figure.savefig(directory / "comparison.png", dpi=180) + figure.savefig(directory / "comparison.svg") if __name__ == "__main__":