next.js
40966a87 - test: poll failed deploy build logs until the build failure is reported (#102718)

Commit
2 hours ago
test: poll failed deploy build logs until the build failure is reported (#102718) ### What? When a deploy-mode test's build fails because the build command exited non-zero, the harness now re-reads the build log until the end of the build appears in it, instead of reading it once. This affects tests that expect a failed build, such as `use-cache-without-experimental-flag`, which assert on `next.cliOutput`. The tests' assertions are unchanged. ### Why? After a failed deploy, the harness filled `next.cliOutput` from a single `vercel inspect --logs` call, made right after `vercel deploy` exited. Sometimes that call returns the build log without its end. The transcript then lacks the diagnostic the test looks for, and also the `[ELIFECYCLE]` and `[BUILD_UTILS_SPAWN_1]` lines that normally follow it. The assertion fails because the expected diagnostic isn't in the captured transcript. In one release deploy run this happened on all 3 attempts of `use-cache-without-experimental-flag`. Other build-failure suites failed the same way and passed on retry. `vercel inspect --logs` without `--wait` makes one non-follow request for the build events. The success path already polls (`fetchBuildLogsUntilComplete`) because a deployment can report `Ready` before its last log lines are available. This PR adds the same kind of polling to the failure path. ### How? - When `vercel deploy` reports a failed build script (`Error: Command "…" exited with N`), the harness re-runs `vercel inspect --logs` on the same deployment. It stops when the remote build's own failure line `Error: [BUILD_UTILS_SPAWN_<n>] Command "…" exited with N` appears as a whole line. - Polling uses the existing backoff (2s → 10s), a per-call timeout of at most 30s, and the setup-hook deadline, with a 60s polling budget. As on the success path, the first call always runs. If the deploy has already used up the setup budget, that call still gets the full 30s timeout. - The result is always a single transcript, never a merge, so tests that count diagnostics still work. - If the end of the log never shows up, the harness keeps the latest successful transcript and logs that it was incomplete. Output from failed `inspect` calls is never returned as a transcript. - Other failures (auth, canceled, anything unrecognized) still fetch once, now with a 30s timeout. - The success-path polling loop is factored out into `pollBuildLogs` and its behavior is unchanged. The end-of-build marker is a heuristic. It was seen as a build-log event in deploy CLI output but hasn't been checked against a complete `inspect` transcript of a failed build. If the marker never appears, the harness polls until the budget runs out. It then keeps the latest successful transcript and logs why it's incomplete. ### Verification - `pnpm exec jest --runInBand --runTestsByPath test/unit/next-deploy-failure/next-deploy-failure.test.ts`: 59/59 pass. 15 tests are new and cover backoff, look-alike lines that must not count as the marker, keeping the transcript after a failed call, budget and cap bounds, and the timed-out single fetch. - `pnpm typescript`, Prettier and ESLint on the changed files pass. - Deploy mode: PR CI runs deploy tests only for changed `test/e2e` files, so this PR also fixes comment typos in two deploy-active suites: - `test/e2e/app-dir/app-edge/app-edge-invalid-reexport.test.ts`: with Turbopack, its build is expected to fail, and it asserts on the build diagnostics in `next.cliOutput`. - `test/e2e/app-dir/concurrent-navigations/mismatching-prefetch.test.ts` - Both suites passed in all 3 deploy variants (adapter, non-adapter, cache components) in [run 47064918768](https://github.com/vercel/next.js/actions/runs/47064918768), across attempts 1 and 2. One non-adapter job in attempt 1 stalled in `npm i -g vercel@latest`, before deploying, and passed when rerun. - This shows the failed-build assertions pass with the new harness on real deployments. It doesn't show whether the end-of-build marker matched or the incomplete-log fallback was used, because `run-tests.js` hides the output of passing suites. It also doesn't show that the original flake is gone. <!-- NEXT_JS_LLM --> <!-- fleet 0d4f5cbc-0b58-4b3f-aae4-a94e61b4ff08 --> --------- Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Author
Parents
Loading