Skip to content

feat: skip visual tests when Gemini stays unavailable - #42

Open
kikoso wants to merge 3 commits into
mainfrom
fix/skip-when-gemini-unavailable
Open

kikoso wants to merge 3 commits into
mainfrom
fix/skip-when-gemini-unavailable

Conversation

@kikoso

@kikoso kikoso commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Since #40, GeminiVisualTestHelper retries timeouts, 429 and 5xx three times with backoff. That fixed the timeouts, but on Dec 2 Gemini answered 503 UNAVAILABLE ("This model is currently experiencing high demand") on all three attempts, twice in a row, so the emulator job on #39 still failed for a reason that has nothing to do with the code under test.

This PR lets a visual test be reported as skipped instead of failed when Gemini is still unavailable after the last retry. It is opt-in, and the sample test opts in.

Changes

  • New GeminiUnavailableException, thrown when the last attempt still times out or fails with a network error, 429 or 5xx. It extends IllegalStateException, so callers catching that keep working.
  • BaseVisualTest.skipWhenGeminiUnavailable (default false): when true, verifyScreenshotWithGoldenFallback turns GeminiUnavailableException into an AssumptionViolatedException, the same mechanism already used when GEMINI_API_KEY is missing. Gemini rejecting the screenshot, 400, an invalid key and every other error still fail the test.
  • VisualMapSampleTest sets it to true, so a Gemini outage no longer breaks CI.
  • README: synced the two embedded snippets and added a troubleshooting entry for the flag.

Behaviour change

When every attempt times out, the helper now throws GeminiUnavailableException with the HttpRequestTimeoutException as its cause, instead of rethrowing the IOException itself. Code catching IOException around analyzeImage would need to catch GeminiUnavailableException instead. Worth to mention in the next rc release notes.

Verification

  • ./gradlew :visual-testing:testDebugUnitTest --rerun-tasks passes (39 tests, 3 new: skip when opted in, fail by default, still fail on a rejected screenshot with skipping enabled; GeminiRetryTest updated for the new exception type).
  • apiCheck (api dump updated), spotlessCheck, :visual-testing:lintDebug, :app:lintDebug and :app:compileDebugAndroidTestKotlin pass.
  • The emulator job on this PR exercises the live Gemini path.

GeminiVisualTestHelper now throws GeminiUnavailableException (an
IllegalStateException) when the last attempt still times out or gets a
429 or 5xx. BaseVisualTest gains an opt-in skipWhenGeminiUnavailable
flag that reports the test as skipped instead of failed in that case.
VisualMapSampleTest opts in, so a Gemini outage no longer fails CI.
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Coverage (unit tests)

No unit baseline recorded in coverage/history.csv yet, so this run only reports absolute numbers.

Module Line % Change Branch % Change
golden-testing 90.42% new 58.00% new
maps3d-robolectric-testing 71.65% new 50.94% new
robolectric-testing 84.25% new 51.87% new
visual-testing 67.48% new 39.72% new
TOTAL 80.82% new 48.71% new

Line and branch coverage from unit test reports. History is recorded in coverage/history.csv after each merge to main.

assertThat(error).hasMessageThat().contains("Gemini visual verification failed")
}

private fun unavailableGeminiHarness(skip: Boolean) = object : BaseVisualTest() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if BaseVisualTest.skipWhenGeminiUnavailable's default value were accidentally flipped to true, this test would still pass. is it ok ??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

if BaseVisualTest.skipWhenGeminiUnavailable's default value were accidentally flipped to true, this test would still pass. is it ok ??

Good point, the test was setting explicitly the flag to false, so it never covered the default. Now unavailableGeminiHarness() leaves skipWhenGeminiUnavailable untouched, and I checked that flipping the default to true makes this test fail. Done in 52e04ae.

The fails-by-default test set the flag to false explicitly, so it would
still pass if the default flipped to true. Its harness now leaves the
flag at its default.
if (isLastAttempt) {
Log.e(TAG, "Gemini API request failed after $attempt attempts", e)
throw e
throw GeminiUnavailableException("Gemini API request failed after $attempt attempts: $e", e)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All four public entry points calling executeWithRetry—analyzeImage, analyzeImageBlocking, performActionFromPrompt, and performActionFromPromptBlocking—now throw GeminiUnavailableException and should document it in KDoc.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in fab3d57.

This branch has not been deployed

No deployments
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.

3 participants