diff --git a/system_files/bluefin/usr/libexec/bonedigger-report b/system_files/bluefin/usr/libexec/bonedigger-report index 5b566d2a..0c14c899 100755 --- a/system_files/bluefin/usr/libexec/bonedigger-report +++ b/system_files/bluefin/usr/libexec/bonedigger-report @@ -77,6 +77,24 @@ read_image_info() { IMAGE_REF="$(read_image_field image-ref)" IMAGE_TAG="$(read_image_field image-tag)" IMAGE_FLAVOR="$(read_image_field image-flavor)" + + local booted_ref="" + if command -v jq &>/dev/null; then + booted_ref="$(printf '%s' "$BOOTC_JSON" | \ + jq -r '.status.booted.image.image.image // empty' 2>/dev/null || true)" + fi + if [[ -n "$booted_ref" ]]; then + local ref_without_digest="${booted_ref%@*}" + local image_component="${ref_without_digest##*/}" + IMAGE_REF="$booted_ref" + if [[ "$image_component" == *:* ]]; then + IMAGE_NAME="${image_component%:*}" + IMAGE_TAG="${image_component##*:}" + else + IMAGE_NAME="$image_component" + IMAGE_TAG="unknown" + fi + fi } read_boot_status() { @@ -662,6 +680,7 @@ start_bug_report() { local description local reproduction + read_boot_status read_image_info # read_boot_status must run before routing: it corrects IMAGE_TAG # from the booted bootc image, and lts routing keys off the tag. @@ -704,8 +723,8 @@ main() { parse_args "$@" if [[ -n "$CONFIRM_TARGET" ]]; then - read_image_info read_boot_status + read_image_info route_issue_repo parse_confirm_target "$CONFIRM_TARGET" "$BUG_REPO" confirm_report "$CONFIRM_ISSUE" "$CONFIRM_REPO" diff --git a/tests/test_bonedigger_report.bats b/tests/test_bonedigger_report.bats index b7de0d7f..7f500d3e 100755 --- a/tests/test_bonedigger_report.bats +++ b/tests/test_bonedigger_report.bats @@ -62,6 +62,40 @@ teardown() { [ "$output" = "projectbluefin/common" ] } +@test "image info prefers booted image reference over stale build metadata" { + printf '%s\n' '{"image-name":"bluefin","image-tag":"latest","image-ref":"ghcr.io/projectbluefin/bluefin:latest","image-flavor":"main"}' \ + > "$WORKDIR/stale-image-info.json" + + run bash -c ' + source "$1" + IMAGE_INFO_FILE="$2" + BOOTC_JSON="$3" + read_image_info + printf "%s|%s|%s" "$IMAGE_NAME" "$IMAGE_TAG" "$IMAGE_REF" + ' _ "$BONEDIGGER_SCRIPT" "$WORKDIR/stale-image-info.json" \ + '{"status":{"booted":{"image":{"image":{"image":"ghcr.io/projectbluefin/dakota:stable"}}}}}' + + [ "$status" -eq 0 ] + [ "$output" = "dakota|stable|ghcr.io/projectbluefin/dakota:stable" ] +} + +@test "image info falls back when no booted image is reported" { + printf '%s\n' '{"image-name":"bluefin","image-tag":"latest","image-ref":"ghcr.io/projectbluefin/bluefin:latest","image-flavor":"main"}' \ + > "$WORKDIR/stale-image-info.json" + + run bash -c ' + source "$1" + IMAGE_INFO_FILE="$2" + BOOTC_JSON="$3" + read_image_info + printf "%s|%s" "$IMAGE_NAME" "$IMAGE_TAG" + ' _ "$BONEDIGGER_SCRIPT" "$WORKDIR/stale-image-info.json" \ + '{"status":{"booted":null}}' + + [ "$status" -eq 0 ] + [ "$output" = "bluefin|latest" ] +} + @test "queue choices map to at most one supported queue label" { run bash -c 'source "$1"; queue_label_for_choice "$2"' _ \ "$BONEDIGGER_SCRIPT" "Submit to the clanker queue for machine analysis"