Skip to content

test(api): fix flaky build-tag tests by waiting for terminal build status#1200

Open
l2ysho wants to merge 2 commits into
masterfrom
fix-build-wait-flakiness
Open

test(api): fix flaky build-tag tests by waiting for terminal build status#1200
l2ysho wants to merge 2 commits into
masterfrom
fix-build-wait-flakiness

Conversation

@l2ysho

@l2ysho l2ysho commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What

Replace the hand-rolled poll loop in waitForBuildToFinish (test setup helper) with the apify-client's built-in waitForFinish().

Why

The build-tag API tests (test/api/commands/builds/tags.test.ts) flake intermittently — e.g. run #27580124989:

AssertionError: expected 'error: build with id "6lrfl52..." has status "running". only successful builds can be tagged.' to contain 'tag "beta" added'

Root cause

waitForBuildToFinish returned as soon as the status was anything other than RUNNING:

if (build!.status !== ACTOR_JOB_STATUSES.RUNNING) return build;

A freshly-created build starts in READY (queued) and only then transitions RUNNINGSUCCEEDED. Since READY !== RUNNING, the helper returned immediately with a build that hadn't started yet. By the time the add-tag assertions ran, the build had moved to RUNNING, so tagging failed with "only successful builds can be tagged" — and the dependent "already tagged" assertion cascaded from the same broken setup.

How

client.build(buildId).waitForFinish() waits for a terminal status and polls server-side, removing the magic 2.5s interval and the early-return bug. The existing ! assertions and waitForFinishWithTimeout wrapper are unaffected.

Testing

  • pnpm run lint (type-aware)
  • pnpm run format
  • pnpm run build
  • CI API Tests will validate the live behavior.

🤖 Generated with Claude Code

…atus

waitForBuildToFinish returned as soon as the build status was anything
other than RUNNING. A freshly-created build starts in READY (queued)
before transitioning to RUNNING, so the helper returned immediately with
a not-yet-finished build. By the time the build-tag assertions ran, the
build was RUNNING and tagging failed with "only successful builds can be
tagged".

Replace the hand-rolled poll loop with the client's built-in
waitForFinish(), which waits for a terminal status and polls server-side.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@l2ysho l2ysho requested a review from vladfrangu as a code owner June 15, 2026 22:43
@github-actions github-actions Bot added this to the 143rd sprint - Tooling team milestone Jun 15, 2026
@github-actions github-actions Bot added t-tooling Issues with this label are in the ownership of the tooling team. tested Temporary label used only programatically for some analytics. labels Jun 15, 2026
@l2ysho l2ysho added t-dx Issues owned by the DX team. and removed t-tooling Issues with this label are in the ownership of the tooling team. labels Jun 15, 2026
waitForFinish() returns Promise<Build>, so waitForBuildToFinish no longer
needs the async keyword and its call sites no longer need ! assertions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@l2ysho l2ysho added the adhoc Ad-hoc unplanned task added during the sprint. label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-dx Issues owned by the DX team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants