Skip to content

Fix: give build_setup integration hooks an explicit timeout to stop CI flakiness - #549

Merged
AmaadMartin merged 2 commits into
google:mainfrom
AmaadMartin:fix/build-setup-test-hook-timeout
Jul 31, 2026
Merged

AmaadMartin merged 2 commits into
google:mainfrom
AmaadMartin:fix/build-setup-test-hook-timeout

Conversation

@AmaadMartin

Copy link
Copy Markdown
Collaborator

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

  • Closes: #issue_number
  • Related: #issue_number

2. Or, if no issue exists, describe the change:

Problem:
The Build setup integration test (tests/integration/build_setup/build_setup_test.ts) intermittently fails the GitHub Actions validation workflow on ubuntu-latest. Its beforeAll hook runs npm install (plus npm run build for the ts_* setups) with no explicit timeout, so it inherits vitest's default hookTimeout of 10000ms. On slow/cold CI runners this heavy setup routinely exceeds 10s, producing spurious Error: Hook timed out in 10000ms "beforeAll" failures. Because the hook is registered inside a describe.each([...]) block, the failure surfaces in whichever of the six parameterized sub-suites (js_commonjs, js_esm, ts_commonjs, ts_esm, ts_commonjs_native_addon, ts_esm_native_addon) crosses the 10s line first — i.e. it is timing flakiness, not a deterministic bug. The I/O-heavy afterAll teardown (recursive node_modules/dist removal) is susceptible to the same flake.

Solution:
Introduce a dedicated, clearly named HOOK_TIMEOUT = 120000 constant and pass it as the explicit second argument to both beforeAll and afterAll (vitest signature: beforeAll(fn, timeout?)). This grants the setup/teardown hooks a generous, explicit budget sufficient to install dependencies and build the fixture projects on a slow runner. It matches the idiomatic pattern already used by the other install-heavy integration tests in this repo (app_loader, agent_loader, skills/script_js). The per-it TEST_EXECUTION_TIMEOUT stays 20000ms and is not overloaded for the hook. This is a test-harness-only change: no product/source code, public API, or build output is touched, so there are no breaking changes.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

This is a CI test-infrastructure fix with no new src/ code, so vitest coverage (scoped to */src/**/*.ts) is unaffected and no new unit tests are applicable. Verification focused on the modified integration suite itself (see below).

Manual End-to-End (E2E) Tests:

  1. Install and build the workspace: npm install && npm run build.
  2. (Optional cold-cache stress) Remove any fixture node_modules/package-lock.json under tests/integration/build_setup/* to force a slow install.
  3. Run only the affected suite (per the repo's "only run targeted tests" guideline):
    npx vitest run --project integration tests/integration/build_setup/build_setup_test.ts
  4. Expected: all six sub-suites pass with no Hook timed out in 10000ms error, even though the beforeAll npm install (+ build) takes well over 10s per setup.

Result observed locally: Test Files 1 passed (1), Tests 20 passed | 4 skipped (24); the file ran ~529s of hook-heavy setup with no hook-timeout failure. Fast gates also verified on the edited file: eslint clean, prettier --check clean, and tsc --noEmit introduces no new errors (pre-existing fixture module-resolution errors are unchanged and unrelated).

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

The change is limited to the two hook registrations in tests/integration/build_setup/build_setup_test.ts; no fixture projects, workspace configuration, or lockfiles are modified.

Amaad Martin added 2 commits July 28, 2026 13:55
The beforeAll hook in build_setup_test.ts runs `npm install` (plus
`npm run build` for ts_* setups) with no explicit timeout, so it inherits
vitest's default 10s hookTimeout. On slow CI runners (e.g. ubuntu-latest)
this heavy setup routinely exceeds 10s, producing flaky
"Hook timed out in 10000ms" failures in whichever of the six parameterized
sub-suites crosses the line first.

Add a dedicated HOOK_TIMEOUT (120000ms) constant and pass it to both the
beforeAll and afterAll hooks, matching the pattern used by the other
install-heavy integration tests (app_loader, agent_loader, skills/script_js).
The per-it TEST_EXECUTION_TIMEOUT stays 20000ms. Test-only change; no
product code is touched.
Address review feedback on the HOOK_TIMEOUT comment.

The previous comment claimed the value matched the pattern used by
app_loader/agent_loader/skills-script_js. That is inaccurate: each of those
declares a single TEST_EXECUTION_TIMEOUT (40000/40000/60000) shared by its
hooks and tests, so neither the second constant nor 120000 came from them.
Replace the claim with the measurement that actually picks the number: all
twelve hook runs cost ~16s combined on ubuntu-latest, while a cold,
network-bound install has been measured at ~70s.

Also fix an accuracy bug: the comment described only beforeAll, but
HOOK_TIMEOUT governs afterAll too, whose work is the recursive node_modules
teardown. It now covers both hooks, states why the per-test budget stays at
20000, and records the trade-off that a stuck hook takes this long to surface.

Comment-only change; no behavior change.
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