|
| 1 | +#!/bin/bash |
| 2 | +# -*- indent-tabs-mode: nil; tab-width: 2; sh-indentation: 2; -*- |
| 3 | + |
| 4 | +# Test --test-mode: build failure without prebuilt fallback |
| 5 | +# |
| 6 | +# Verifies that when a package fails to build and no prebuilt wheel is available |
| 7 | +# (because the package is not on PyPI), test-mode records the failure. |
| 8 | +# Uses a local git repo fixture with a broken build backend. |
| 9 | +# |
| 10 | +# See: https://github.com/python-wheel-build/fromager/issues/895 |
| 11 | + |
| 12 | +SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 13 | +source "$SCRIPTDIR/common.sh" |
| 14 | + |
| 15 | +# Use the test_build_failure fixture (local git repo) |
| 16 | +# Initialize git repo at runtime (fixture files are committed without .git) |
| 17 | +FIXTURE_DIR="$SCRIPTDIR/test_build_failure" |
| 18 | +CREATED_FIXTURE_GIT=false |
| 19 | +if [ ! -d "$FIXTURE_DIR/.git" ]; then |
| 20 | + CREATED_FIXTURE_GIT=true |
| 21 | + (cd "$FIXTURE_DIR" && git init -q && \ |
| 22 | + git config user.email "test@example.com" && \ |
| 23 | + git config user.name "Test User" && \ |
| 24 | + git add -A && git commit -q -m "init") |
| 25 | +fi |
| 26 | +FIXTURE_URL="git+file://${FIXTURE_DIR}" |
| 27 | + |
| 28 | +# Cleanup .git on exit if we created it (prevents flaky reruns) |
| 29 | +cleanup_fixture_git() { |
| 30 | + if [ "$CREATED_FIXTURE_GIT" = true ] && [ -d "$FIXTURE_DIR/.git" ]; then |
| 31 | + rm -rf "$FIXTURE_DIR/.git" |
| 32 | + fi |
| 33 | +} |
| 34 | +trap cleanup_fixture_git EXIT |
| 35 | + |
| 36 | +# Create a requirements file pointing to the local fixture |
| 37 | +REQUIREMENTS_FILE="$OUTDIR/test-requirements.txt" |
| 38 | +echo "test_build_failure @ ${FIXTURE_URL}" > "$REQUIREMENTS_FILE" |
| 39 | + |
| 40 | +# Run bootstrap in test mode |
| 41 | +# - Package resolves from local git repo |
| 42 | +# - Build fails (broken build backend) |
| 43 | +# - Prebuilt fallback fails (package not on PyPI) |
| 44 | +# - Failure should be recorded |
| 45 | +set +e |
| 46 | +fromager \ |
| 47 | + --log-file="$OUTDIR/bootstrap.log" \ |
| 48 | + --error-log-file="$OUTDIR/fromager-errors.log" \ |
| 49 | + --sdists-repo="$OUTDIR/sdists-repo" \ |
| 50 | + --wheels-repo="$OUTDIR/wheels-repo" \ |
| 51 | + --work-dir="$OUTDIR/work-dir" \ |
| 52 | + bootstrap --test-mode -r "$REQUIREMENTS_FILE" |
| 53 | +EXIT_CODE=$? |
| 54 | +set -e |
| 55 | + |
| 56 | +pass=true |
| 57 | + |
| 58 | +# Check 1: Exit code should be 1 (failures recorded) |
| 59 | +if [ "$EXIT_CODE" -ne 1 ]; then |
| 60 | + echo "FAIL: Expected exit code 1, got $EXIT_CODE" 1>&2 |
| 61 | + pass=false |
| 62 | +fi |
| 63 | + |
| 64 | +# Check 2: The test-mode-failures JSON file should exist |
| 65 | +FAILURES_FILE=$(find "$OUTDIR/work-dir" -name "test-mode-failures-*.json" 2>/dev/null | head -1) |
| 66 | +if [ -z "$FAILURES_FILE" ] || [ ! -f "$FAILURES_FILE" ]; then |
| 67 | + echo "FAIL: test-mode-failures-*.json file not found" 1>&2 |
| 68 | + pass=false |
| 69 | +else |
| 70 | + echo "Found failures file: $FAILURES_FILE" |
| 71 | + |
| 72 | + # Check 3: test_build_failure should be in failed packages |
| 73 | + # Note: package name uses underscore as recorded by fromager |
| 74 | + if ! jq -e '.failures[] | select(.package == "test_build_failure")' "$FAILURES_FILE" > /dev/null 2>&1; then |
| 75 | + echo "FAIL: Expected 'test_build_failure' in failed packages" 1>&2 |
| 76 | + jq '.' "$FAILURES_FILE" 1>&2 |
| 77 | + pass=false |
| 78 | + fi |
| 79 | + |
| 80 | + # Check 4: failure_type should be "bootstrap" or "resolution" (both are valid build failures) |
| 81 | + FAILURE_TYPE=$(jq -r '[.failures[] | select(.package == "test_build_failure")][0].failure_type' "$FAILURES_FILE") |
| 82 | + if [ "$FAILURE_TYPE" != "bootstrap" ] && [ "$FAILURE_TYPE" != "resolution" ]; then |
| 83 | + echo "FAIL: Expected failure_type 'bootstrap' or 'resolution', got '$FAILURE_TYPE'" 1>&2 |
| 84 | + pass=false |
| 85 | + fi |
| 86 | + |
| 87 | + # Check 5: exception_message should mention the intentional failure or a build-related error |
| 88 | + EXCEPTION_MSG=$(jq -r '[.failures[] | select(.package == "test_build_failure")][0].exception_message' "$FAILURES_FILE") |
| 89 | + if [[ "$EXCEPTION_MSG" != *"Intentional build failure"* ]] && [[ "$EXCEPTION_MSG" != *"RuntimeError"* ]] && [[ "$EXCEPTION_MSG" != *"build"* ]]; then |
| 90 | + echo "FAIL: Expected exception message about build failure, got: $EXCEPTION_MSG" 1>&2 |
| 91 | + pass=false |
| 92 | + fi |
| 93 | +fi |
| 94 | + |
| 95 | +# Check 6: Log should show test mode enabled |
| 96 | +if ! grep -q "test mode enabled" "$OUTDIR/bootstrap.log"; then |
| 97 | + echo "FAIL: Log should contain 'test mode enabled'" 1>&2 |
| 98 | + pass=false |
| 99 | +fi |
| 100 | + |
| 101 | +# Check 7: Log should show fallback was attempted and failed |
| 102 | +if grep -q "pre-built fallback" "$OUTDIR/bootstrap.log"; then |
| 103 | + echo "INFO: Fallback was attempted (expected since package not on PyPI)" |
| 104 | +else |
| 105 | + echo "INFO: No fallback mention in log (may vary by code path)" |
| 106 | +fi |
| 107 | + |
| 108 | +$pass |
0 commit comments