#!/bin/sh set -u cd "$(dirname "$0")/.." R="python3 scripts/run_and_save.py" DC="docker compose --env-file .env" PGUSER=$(sed -n 's/^POSTGRES_USER=//p' .env) PGDB=$(sed -n 's/^POSTGRES_DB=//p' .env) PSQL="$DC exec -T db psql -U ${PGUSER:-messenger} -d ${PGDB:-messenger}" VOLUME=mtusi-messenger_pgdata VOLFMT='{{.Name}} created={{.CreatedAt}}' STEPS=${*:-"01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16"} wait_ready() { for _ in $(seq 1 90); do curl -sf http://localhost:8080/health/ready >/dev/null && return 0 sleep 1 done echo "API не готов" >&2 return 1 } for step in $STEPS; do echo "=== $step" case $step in 01) $R evidence/01_check_contract.txt -- python3 scripts/check_contract.py ;; 02) $R evidence/02_smoke.txt -- make test ;; 03) $R evidence/03_ps_before.txt -- $DC ps $R evidence/03_volume_before.txt -- docker volume inspect $VOLUME --format "$VOLFMT" ;; 04) $R evidence/04_persistence.txt -- make test-persistence ACTION_SCRIPT=scripts/restart.sh ;; 05) $R evidence/05_ps_after.txt -- $DC ps $R evidence/05_volume_after.txt -- docker volume inspect $VOLUME --format "$VOLFMT" ;; 06) $R evidence/06_schema.txt -- $PSQL -c '\d users' -c '\d chats' -c '\d chat_members' \ -c '\d messages' -c '\d sessions' ;; 07) $R evidence/07_migrations.txt -- $DC exec -T api python -m app.migrate $R evidence/07_migrations_table.txt -- $PSQL -c 'SELECT * FROM schema_migrations' ;; 08) $R evidence/08_hashes.txt -- $PSQL \ -c "SELECT username, left(password_hash, 7) AS password_prefix, length(password_hash) AS len FROM users WHERE password_hash LIKE 'scrypt\$%' LIMIT 3" \ -c 'SELECT length(token_hash) AS token_hash_len, expires_at FROM sessions LIMIT 3' ;; 09) $R evidence/09_auth_tests.txt -- $DC --profile test run --rm tests python -m pytest -v --no-header -p no:cacheprovider \ student-tests/test_auth.py student-tests/test_session_expiry.py ;; 10) $R evidence/10_database_tests.txt -- $DC --profile test run --rm tests python -m pytest -v --no-header -p no:cacheprovider \ student-tests/test_database.py student-tests/test_db_failure.py student-tests/test_transactions.py \ student-tests/test_duplicate_username.py ;; 11) $R evidence/11_all_tests.txt -- $DC --profile test run --rm tests ;; 12) $R evidence/12_git_secrets.txt -- git check-ignore -v .env $R evidence/12_git_files.txt -- git ls-files --cached --others --exclude-standard $R evidence/12_compose_no_secrets.txt -- grep -n -i 'password\|secret' compose.yaml ;; 13) python3 scripts/storage_demo.py --output evidence/13_storage.txt wait_ready ;; 14) python3 scripts/dependency_demo.py --output evidence/14_dependencies.txt wait_ready ;; 15) $R evidence/15_explain.txt -- $DC exec -T api python -m app.explain $R evidence/15_explain_tests.txt -- $DC --profile test run --rm tests python -m pytest -v --no-header -p no:cacheprovider \ student-tests/test_explain.py ;; 16) $DC --profile expiry up -d api-ttl for _ in $(seq 1 60); do curl -sf http://localhost:8081/health/ready >/dev/null && break; sleep 1; done $R evidence/16_expiry_live.txt -- python3 scripts/check_expiry.py --base-url http://localhost:8081 --ttl 3 $DC --profile expiry stop api-ttl $DC --profile expiry rm -f api-ttl ;; *) echo "неизвестный пункт $step" >&2 ;; esac done