Skip to content

fix: do not show flashing instructions when build failed#294

Merged
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:fix-flash-instruction
May 28, 2026
Merged

fix: do not show flashing instructions when build failed#294
bennyz merged 1 commit into
centos-automotive-suite:mainfrom
bennyz:fix-flash-instruction

Conversation

@bennyz

@bennyz bennyz commented May 28, 2026

Copy link
Copy Markdown
Contributor

If build failed we do not have a usable image to flash

Summary

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • CI/CD improvement
  • Refactoring

Testing

  • Unit tests pass (make test)
  • Linter passes (make lint)
  • Manifests are up to date (make manifests generate)
  • Tested on OpenShift cluster (if applicable)

Summary by CodeRabbit

  • Bug Fixes

    • Artifact URLs (container and disk) are now shown only when builds reach appropriate completion/flash states, preventing premature exposure.
    • Flash failure handling and result display have been tightened to apply only when an image artifact exists and the failure is a flash-specific error.
  • Tests

    • Added table-driven tests covering artifact visibility across build phases and failure scenarios.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@bennyz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 19 minutes and 44 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e0c448bb-bb64-44c4-99f3-6ea7f8cb877d

📥 Commits

Reviewing files that changed from the base of the PR and between f4fca3d and a698323.

📒 Files selected for processing (4)
  • cmd/caib/buildcmd/logs.go
  • cmd/caib/buildcmd/logs_test.go
  • internal/buildapi/server.go
  • internal/buildapi/server_test.go
📝 Walkthrough

Walkthrough

Adds a helper to decide when build artifact URLs should be considered produced (based on phase and task-run names), applies that gating in listBuilds and getBuild, and aligns the CLI failure handling to only show flash/push results when artifacts exist and the failure is a flash failure.

Changes

Build Artifact Availability

Layer / File(s) Summary
Artifact production gating logic
internal/buildapi/server.go, internal/buildapi/server_test.go
Adds buildProducedArtifacts that returns true for Completed/Flashing phases and for Failed when FlashTaskRunName is present; includes a table-driven test covering phase and task-run name combinations.
API endpoint artifact filtering
internal/buildapi/server.go
listBuilds and getBuild now populate containerImage/diskImage only when buildProducedArtifacts is true, leaving them empty otherwise.
CLI error handling alignment
cmd/caib/buildcmd/logs.go
waitForBuildCompletion phase-failed branch now calls displayBuildResults and handleFlashError only if an image artifact exists and isFlashFailure is true (removes flag-only fallback).

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant APIServer
  participant buildProducedArtifacts
  Client->>APIServer: listBuilds/getBuild request
  APIServer->>buildProducedArtifacts: evaluate build.Status.Phase and task-run names
  buildProducedArtifacts-->>APIServer: true/false
  APIServer-->>Client: response (include artifact URLs only if true)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • bkhizgiy

Poem

🐰 I hopped through code to check each phase and name,
No phantom images now call out their claim.
API and CLI both heed the gate,
Only real artifacts make the final state.
Cheers from a rabbit—builds behave the same!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: preventing flashing instructions from being shown when a build fails, which directly addresses the core issue across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bennyz bennyz requested a review from maboras-rh May 28, 2026 08:39
Comment thread internal/buildapi/server.go Outdated
// push completed (e.g. during flash).
func buildProducedArtifacts(build *automotivev1alpha1.ImageBuild) bool {
switch build.Status.Phase {
case phaseCompleted, phaseFlashing, phasePushing:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the function returns true for phasePushing but if a build is currently in the pushing phase(the push hasn't completed yet) so the artifact url may not point to real object.
Should it only return true once pushing is done (i.e., phaseFlashing or phaseCompleted)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@bennyz bennyz force-pushed the fix-flash-instruction branch from 96a2640 to f4fca3d Compare May 28, 2026 10:36

@maboras-rh maboras-rh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, overall is clean, well-scoped fix
left one minor comment related to phasePushing

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/caib/buildcmd/logs.go`:
- Line 169: Add unit tests that exercise the flash-specific branch in
waitForBuildCompletion by constructing build status states where hasImage (set
DiskImage or ContainerImage on the status) and isFlashFailure (simulate a
phaseFailed flash error) are true; invoke waitForBuildCompletion (or the minimal
exported function that calls it) and assert that displayBuildResults and
handleFlashError behaviors occur (capture/log output or use test doubles/mocks
for displayBuildResults and handleFlashError) and verify the flash error
message/output is produced; focus tests on the phaseFailed scenario to ensure
coverage for the hasImage && isFlashFailure path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 05c187e2-4e03-48fb-ba22-2a3c96cbb3be

📥 Commits

Reviewing files that changed from the base of the PR and between 96a2640 and f4fca3d.

📒 Files selected for processing (3)
  • cmd/caib/buildcmd/logs.go
  • internal/buildapi/server.go
  • internal/buildapi/server_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/buildapi/server_test.go
  • internal/buildapi/server.go

Comment thread cmd/caib/buildcmd/logs.go
// Only show push/flash results when an image was actually produced.
hasImage := st.DiskImage != "" || st.ContainerImage != ""
if hasImage && (isFlashFailure || *h.opts.FlashAfterBuild) {
if hasImage && isFlashFailure {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Search for tests covering the waitForBuildCompletion failure path

# Find test files for buildcmd package
fd -e go -t f 'test' cmd/caib/buildcmd

# Search for tests that cover the phaseFailed or failure scenarios
rg -n -A5 -B5 'phaseFailed|TestWaitForBuildCompletion.*[Ff]ail' --type=go --glob 'cmd/caib/buildcmd/*test*.go'

# Look for tests covering hasImage and isFlashFailure conditions
rg -n 'hasImage|isFlashFailure' --type=go --glob 'cmd/caib/buildcmd/*test*.go'

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 205


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== waitForBuildCompletion in logs.go =="
rg -n "func waitForBuildCompletion" -S cmd/caib/buildcmd/logs.go
rg -n "hasImage|isFlashFailure|phaseFailed|FlashAfterBuild|flash" -S cmd/caib/buildcmd/logs.go

echo
echo "== Test files in cmd/caib/buildcmd =="
fd -e go -t f 'test' cmd/caib/buildcmd | sort

echo
echo "== Search for relevant test coverage =="
# Search for waitForBuildCompletion / phaseFailed / flash-related messaging in tests
rg -n -S "waitForBuildCompletion|phaseFailed|FlashAfterBuild|isFlashFailure|hasImage|flash" --type=go cmd/caib/buildcmd/*test*.go || true

echo
echo "== Show any tests mentioning 'flash' in buildcmd tests =="
rg -n -S "flash" --type=go cmd/caib/buildcmd/*test*.go || true

echo
echo "== Show any tests that mention 'DiskImage' or 'ContainerImage' =="
rg -n -S "DiskImage|ContainerImage" --type=go cmd/caib/buildcmd/*test*.go || true

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 131


🏁 Script executed:

#!/bin/bash
set -uo pipefail

echo "== Locate relevant code in logs.go =="
# Show the relevant area around where phaseFailed handling likely lives
rg -n "phaseFailed|FlashAfterBuild|flash" -S cmd/caib/buildcmd/logs.go || true

# Try to find the function by looking for nearby identifiers (safer than exact func name)
rg -n "waitFor|Completion|BuildCompletion|phaseFailed" -S cmd/caib/buildcmd/logs.go || true

# Print the exact section around the line numbers mentioned in the review comment
# (169 was the changed line; include a wider window)
sed -n '130,210p' cmd/caib/buildcmd/logs.go

echo
echo "== Test files in cmd/caib/buildcmd =="
fd -e go -t f 'test' cmd/caib/buildcmd | sort

echo
echo "== Search for flash/phaseFailed coverage in tests =="
rg -n -S "phaseFailed|FlashAfterBuild|isFlashFailure|hasImage|flash" --type=go cmd/caib/buildcmd/*test*.go || true

echo
echo "== Search for any tests calling the logs/wait logic =="
rg -n -S "waitFor|logs.go|buildcmd/logs" --type=go cmd/caib/buildcmd/*test*.go || true

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 4353


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Inspect build_disk_test.go for phaseFailed/flash assertions =="
sed -n '1,220p' cmd/caib/buildcmd/build_disk_test.go

echo
echo "== Search within tests for flash-related output/assertions =="
rg -n -S "phaseFailed|flash was not executed|Warning: --flash|Build and flash completed successfully|lease has been acquired|displayBuildResults|handleFlashError|displayFlashInstructions|JumpstarterTargetMappings|errPrefixFlash|failed" cmd/caib/buildcmd/*test*.go

echo
echo "== Search within tests for DiskImage/ContainerImage population on failure stubs =="
rg -n -S "DiskImage|ContainerImage|Message:|Phase:|ImageBuildPhase|phaseFlashing|phaseFailed|errPrefixFlash" cmd/caib/buildcmd/*test*.go

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 6974


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== File sizes =="
wc -l cmd/caib/buildcmd/logs.go cmd/caib/buildcmd/build_disk_test.go cmd/caib/buildcmd/build_define_test.go cmd/caib/buildcmd/build_creds_test.go

echo
echo "== Remainder of build_disk_test.go =="
sed -n '220,500p' cmd/caib/buildcmd/build_disk_test.go

echo
echo "== Search all buildcmd tests for flash/error handling assertions =="
rg -n -S "handleFlashError|displayFlashInstructions|errPrefixFlash|flashWasExecuted|flash failure|Build and flash|Warning: --flash|To release the lease|Check OperatorConfig|phaseFlashing|phaseFailed" cmd/caib/buildcmd/*test*.go || true

echo
echo "== Search all buildcmd tests for st.Phase == phaseFailed or errPrefixFlash usage =="
rg -n -S "st\.Phase\s*==\s*phaseFailed|errPrefixFlash|phaseFlashing|flashAfterBuild" cmd/caib/buildcmd/*test*.go || true

echo
echo "== Search for any mock build API returning phases/images =="
rg -n -S "buildapiclient|Stream|Get.*Build|Phase|DiskImage|ContainerImage|phasePending|phaseCancelled" cmd/caib/buildcmd/*test*.go || true

echo
echo "== Quick peek: build_define_test.go =="
sed -n '1,240p' cmd/caib/buildcmd/build_define_test.go

echo
echo "== Quick peek: build_creds_test.go =="
sed -n '1,260p' cmd/caib/buildcmd/build_creds_test.go

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 4990


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== cat -n build_disk_test.go =="
cat -n cmd/caib/buildcmd/build_disk_test.go

echo
echo "== rg for phaseFailed / handleFlashError / displayBuildResults in tests =="
rg -n -S "phaseFailed|handleFlashError|displayBuildResults|displayFlashInstructions|errPrefixFlash|FlashAfterBuild" cmd/caib/buildcmd/*test*.go || true

echo
echo "== rg for hasImage / isFlashFailure in tests =="
rg -n -S "hasImage|isFlashFailure" cmd/caib/buildcmd/*test*.go || true

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 8112


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Repo-wide searches in *_test.go for flash failure path identifiers =="
rg -n -S "waitForBuildCompletion" --type=go --glob '**/*_test.go' . || true
rg -n -S "handleFlashError|displayBuildResults|displayFlashInstructions|errPrefixFlash|phaseFlashing|isFlashFailure|hasImage && isFlashFailure|hasImage.*isFlashFailure" --type=go --glob '**/*_test.go' . || true

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 254


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== Search for CLI flash error handlers in tests =="
rg -n -S "handleFlashError|displayBuildResults|displayFlashInstructions|errPrefixFlash" --type=go --glob '**/*_test.go' . || true

echo
echo "== Search for the specific tightened condition components in tests =="
rg -n -S "hasImage\s*&&\s*isFlashFailure|isFlashFailure|errPrefixFlash|phaseFailed.*(flash|Flash)|phaseFlashing" --type=go --glob '**/*_test.go' . || true

echo
echo "== Search for waitForBuildCompletion usage in tests =="
rg -n -S "waitForBuildCompletion" --type=go --glob '**/*_test.go' . || true

echo
echo "== Any tests under cmd/caib/buildcmd besides *_test.go already found? =="
fd -e go -t f '*_test.go' cmd/caib/buildcmd | sort

Repository: centos-automotive-suite/automotive-dev-operator

Length of output: 864


Add tests covering flash-specific phaseFailed handling (hasImage && isFlashFailure)
cmd/caib/buildcmd/logs.go gates the flash-error path in waitForBuildCompletion with hasImage := st.DiskImage != "" || st.ContainerImage != "" and isFlashFailure := ..., then calls displayBuildResults + handleFlashError only when hasImage && isFlashFailure. Current tests under cmd/caib/buildcmd/*_test.go don’t exercise the phaseFailed branch or assert any flash error/results output (no coverage of waitForBuildCompletion, handleFlashError, or displayBuildResults).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/caib/buildcmd/logs.go` at line 169, Add unit tests that exercise the
flash-specific branch in waitForBuildCompletion by constructing build status
states where hasImage (set DiskImage or ContainerImage on the status) and
isFlashFailure (simulate a phaseFailed flash error) are true; invoke
waitForBuildCompletion (or the minimal exported function that calls it) and
assert that displayBuildResults and handleFlashError behaviors occur
(capture/log output or use test doubles/mocks for displayBuildResults and
handleFlashError) and verify the flash error message/output is produced; focus
tests on the phaseFailed scenario to ensure coverage for the hasImage &&
isFlashFailure path.

If build failed we do not have a usable image to flash

Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
Assisted-by: claude-opus-4.6
@bennyz bennyz force-pushed the fix-flash-instruction branch from f4fca3d to a698323 Compare May 28, 2026 11:16
@bennyz bennyz merged commit 1b04735 into centos-automotive-suite:main May 28, 2026
4 checks passed
@bennyz bennyz deleted the fix-flash-instruction branch June 1, 2026 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants