freeze the current backend contract for frontend integration document the stabilized backend surface and handoff expectations mark the current state as the baseline for further frontend work
69 lines
3.3 KiB
Bash
69 lines
3.3 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "${TMP_DIR}"' EXIT
|
|
|
|
# shellcheck source=backend/scripts/smoke_common.sh
|
|
source "${SCRIPT_DIR}/smoke_common.sh"
|
|
|
|
set -a
|
|
source "${REPO_ROOT}/.env"
|
|
set +a
|
|
|
|
wait_for_health
|
|
|
|
create_fresh_scheme_from_upload "smoke-lifecycle-negative"
|
|
|
|
request "scheme_current" "GET" "${API_URL}/api/v1/schemes/${SCHEME_ID}/current" "200"
|
|
CURRENT_VERSION_ID="$(json_get "${TMP_DIR}/scheme_current.body" "scheme_version_id")"
|
|
echo "CURRENT_VERSION_ID=${CURRENT_VERSION_ID}"
|
|
|
|
request "rollback_nonexistent_version" "POST" \
|
|
"${API_URL}/api/v1/schemes/${SCHEME_ID}/rollback" \
|
|
"404" \
|
|
"{\"target_version_number\":999}"
|
|
assert_file_contains "${TMP_DIR}/rollback_nonexistent_version.body" "Target scheme version not found"
|
|
|
|
request "ensure_draft_stale_current_version" "POST" \
|
|
"${API_URL}/api/v1/schemes/${SCHEME_ID}/draft/ensure?expected_current_scheme_version_id=deadbeefdeadbeefdeadbeefdeadbeef" \
|
|
"409"
|
|
assert_json_eq "${TMP_DIR}/ensure_draft_stale_current_version.body" "detail.code" "stale_current_version"
|
|
|
|
request "publish_stale_expected_version" "POST" \
|
|
"${API_URL}/api/v1/schemes/${SCHEME_ID}/publish?expected_scheme_version_id=deadbeefdeadbeefdeadbeefdeadbeef" \
|
|
"409"
|
|
assert_json_eq "${TMP_DIR}/publish_stale_expected_version.body" "detail.code" "publish_not_ready"
|
|
assert_file_contains "${TMP_DIR}/publish_stale_expected_version.body" "\"actual_scheme_version_id\":\"${CURRENT_VERSION_ID}\""
|
|
|
|
INCONSISTENT_VERSION_NUMBER="999"
|
|
UPDATED_VERSION_NUMBER="$(docker compose exec -T postgres psql -U "${POSTGRES_USER}" -d "${POSTGRES_DB}" -Atc "update schemes set current_version_number=${INCONSISTENT_VERSION_NUMBER} where scheme_id='${SCHEME_ID}' and current_version_number=1 returning current_version_number;" | python3 -c 'import sys; lines=[line.strip() for line in sys.stdin.read().splitlines() if line.strip()]; print(lines[0] if lines else "")')"
|
|
if [[ "${UPDATED_VERSION_NUMBER}" != "${INCONSISTENT_VERSION_NUMBER}" ]]; then
|
|
fail "Failed to introduce temporary current_version_inconsistent state for ${SCHEME_ID}"
|
|
fi
|
|
echo "[OK] introduced temporary current_version_inconsistent state for ${SCHEME_ID}"
|
|
|
|
restore_current_version_pointer() {
|
|
docker compose exec -T postgres psql -U "${POSTGRES_USER}" -d "${POSTGRES_DB}" -Atc "update schemes set current_version_number=1 where scheme_id='${SCHEME_ID}' and current_version_number=${INCONSISTENT_VERSION_NUMBER};" >/dev/null
|
|
}
|
|
|
|
trap 'restore_current_version_pointer; rm -rf "${TMP_DIR}"' EXIT
|
|
|
|
request "current_version_inconsistent" "GET" \
|
|
"${API_URL}/api/v1/schemes/${SCHEME_ID}/current" \
|
|
"409"
|
|
assert_json_eq "${TMP_DIR}/current_version_inconsistent.body" "detail.code" "current_version_inconsistent"
|
|
assert_file_contains "${TMP_DIR}/current_version_inconsistent.body" "\"current_version_number\":${INCONSISTENT_VERSION_NUMBER}"
|
|
|
|
restore_current_version_pointer
|
|
|
|
request "scheme_current_restored" "GET" "${API_URL}/api/v1/schemes/${SCHEME_ID}/current" "200"
|
|
assert_json_eq "${TMP_DIR}/scheme_current_restored.body" "scheme_version_id" "${CURRENT_VERSION_ID}"
|
|
assert_json_int_eq "${TMP_DIR}/scheme_current_restored.body" "version_number" "1"
|
|
|
|
echo
|
|
echo "===== done ====="
|
|
echo "[OK] smoke lifecycle negative completed successfully"
|
|
echo "FRESH_SCHEME_ID=${SCHEME_ID}"
|