#!/usr/bin/env bash # tests/unit/11_build.sh -- feedback while an image is being built. # # The bug this file exists for: a build is the slow part of a first run and the thing # --install triggers, and every byte of podman's transcript used to go to a log file. # Minutes of silence reads as a hang. So these tests ask the running script what a user # would see, with a stub for podman rather than a container. # # The stub stands in for the two behaviours of the real thing that this file is about: # 'image exists' answers no, so a build is needed, and 'build' writes its transcript to # *stdout* (measured on podman 5: that is where podman build writes) -- which is the one # thing the script must never let reach its own stdout, because ensure_image()'s stdout # is read back as the image ref. source "$TESTS/lib.sh" PROJ="$WORK/proj"; mkdir -p "$PROJ"; cd "$PROJ" || exit 1 BIN="$WORK/bin"; mkdir -p "$BIN" cat > "$BIN/podman" <<'EOS' #!/usr/bin/env bash case "${1:-} ${2:-}" in "image exists") exit 1 ;; "build -t") # what the build was invoked with, so a credential smuggled into a --build-arg # shows up in the transcript and the canary test below fails printf 'STUB-BUILD-ARGS: %s\n' "$*" # the packages the build was actually handed, read back out of --build-arg, so this # transcript names what the policy under test asked for instead of a fixed guess pkgs="" for a in "$@"; do case "$a" in AISB_EXTRA_PACKAGES=*) pkgs="${a#*=}" ;; esac done printf 'Trying to pull docker.io/library/ubuntu:24.04...\n' printf 'Getting image source signatures\n' printf 'STEP 1/3: FROM docker.io/library/ubuntu:24.04\n' printf 'STEP 2/3: RUN apt-get update && apt-get install -y%s\n' "${pkgs:+ $pkgs}" for ((i = 0; i < "${AISB_STUB_NOISE:-20}"; i++)); do printf 'Get:%d http://archive.ubuntu.com/ubuntu noble/main amd64 curl amd64 8.5.0-1 [11 MB]\n' "$i" sleep "${AISB_STUB_NOISE_DELAY:-0}" done sleep "${AISB_STUB_SLEEP:-0}" if [[ "${AISB_STUB_RC:-0}" != 0 ]]; then printf 'Reading package lists...\n' for p in $pkgs; do printf 'E: Unable to locate package %s\n' "$p"; done printf 'Error: building at STEP "RUN apt-get install": while running runtime: exit status 100\n' exit "${AISB_STUB_RC}" fi printf '%s\n' '--> 1234567890ab' printf 'STEP 3/3: CMD ["bash", "-li"]\n' printf 'COMMIT localhost/ai-sandbox:stub\n' printf 'Successfully tagged localhost/ai-sandbox:stub\n' printf 'abc123def\n' ;; *) exit 0 ;; esac EOS chmod +x "$BIN/podman" export PATH="$BIN:$PATH" # node_sha256() fetches from nodejs.org; a unit test never touches a registry. export AISB_NODE_SHA256=0000000000000000000000000000000000000000000000000000000000000000 # The transcript path the last run announced, which is the only way a test is supposed # to find it -- and naming it is itself part of the feedback under test. last_transcript() { printf '%s' "$OUT" | sed -n 's/^ai-sandbox: build: [^ ]* (transcript: \(.*\))$/\1/p' | head -1; } log_says() { # log_says