Unverified Commit 9922c2ee authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

test: explain why deploy build-log markers are missing (#100069)

## Summary

This makes the deploy harness's failure say *why* the build-ID markers
were missing. It is the second of three stacked PRs and builds on the
bounded polling in the PR below it.

When polling hits its deadline, the error still starts with `Failed to
get buildId from logs`, so existing triage keeps matching. It now also
includes:
- the deployment URL, the attempt count and the elapsed time;
- whether the transcript had **no build-log lines at all**, meaning
`vercel inspect --logs` printed only its own header and status lines,
which suggests the logs weren't available from Vercel. This is the
signature of the canary.7 incident.
- otherwise, **which** of `BUILD_ID`, `DEPLOYMENT_ID` and
`NEXT_SUPPORTS_IMMUTABLE_ASSETS` are missing;
- why the last `vercel inspect` call failed, if it timed out, exited
non-zero or rejected.

The kept transcript is also stored in `cliOutput` for callers that catch
`start()`.

The "no build-log lines" check is a heuristic that only feeds this
message. Successful ID parsing doesn't depend on it.

This PR also removes a duplicated word in a comment in
`test/e2e/app-dir/segment-cache/search-params/segment-cache-search-params.test.ts`.
That change is there so `Test new and changed tests when deployed` runs
a deploy-mode suite against this layer of the harness.

## Verification

- `pnpm jest test/unit/next-deploy-failure`: 33/33 pass. The new cases
cover a header-only transcript, logs with no markers, only
`NEXT_SUPPORTS_IMMUTABLE_ASSETS` missing, and a timed-out last call.
They fail on the PR below.
- prettier, eslint and `pnpm typescript` are clean.

<!-- NEXT_JS_LLM -->


<!-- fleet b78d4bc5-dee1-4d80-b647-54229882f21f -->

---------
Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent 573e0f6b
......@@ -118,7 +118,7 @@ describe('segment cache (search params)', () => {
await revealC.click()
},
// This should not issue a new request for the page segment, because
// search params are not included in the the PPR shell. So we can reuse
// search params are not included in the PPR shell. So we can reuse
// the shell we fetched for `searchParam=a`.
{ includes: 'target-page-with-search-param', block: 'reject' }
)
......
......@@ -322,15 +322,18 @@ export class NextDeployInstance extends NextInstance {
// attempt that times out or comes back empty must not discard it.
let transcript = ''
let lastOutput = ''
let failure: string | undefined
let attempt = 0
for (let attempt = 1; ; attempt++) {
for (;;) {
attempt++
const remainingMs = deadline - Date.now()
const timeout =
remainingMs > 0
? Math.min(BUILD_LOGS_INSPECT_TIMEOUT_MS, remainingMs)
: BUILD_LOGS_INSPECT_TIMEOUT_MS
let failure: string | undefined
failure = undefined
try {
const buildLogs = await execa(
'vercel',
......@@ -374,9 +377,23 @@ export class NextDeployInstance extends NextInstance {
}
}
// The markers never appeared within the deadline; return the best
// transcript so `parseIdsFromCliOutput` throws a descriptive error with it.
return transcript || lastOutput
// The markers never appeared within the deadline. Keep the best transcript
// for callers that catch start(), and say why it can't be parsed.
const output = transcript || lastOutput
this._cliOutput = output
const missingMarkers = BUILD_LOG_MARKERS.filter(
(marker) => !hasBuildLogMarker(output, marker)
)
const reason = !hasBuildLogLines(output)
? '`vercel inspect --logs` returned no build-log lines, only its own output; the build logs are likely not available from Vercel yet'
: missingMarkers.length > 0
? `the build logs are missing the ${missingMarkers.join(', ')} marker(s)`
: 'the vercel inspect call that printed the markers did not succeed'
throw new Error(
`Failed to get buildId from logs of ${url} after ${attempt} attempt(s) in ${Date.now() - pollStartedAt}ms: ${reason}.` +
(failure ? `\nThe last vercel inspect call ${failure}` : '') +
`\n${output}`
)
}
public async setup(parentSpan: Span) {
......
......@@ -549,5 +549,46 @@ describe('deployment lifecycle', () => {
expect(inspectCalls.length).toBeGreaterThan(1)
expect(next.cliOutput).toContain('Compiled successfully')
})
it('reports when inspect returned no build-log lines at all', async () => {
installClock()
logs = ok(cliHeader)
const next = await instance()
const error = await next.start().catch((err: Error) => err)
expect(error).toBeInstanceOf(Error)
expect((error as Error).message).toMatch(
/^Failed to get buildId from logs of https:\/\/fixture\.vercel\.app\/? after \d+ attempt\(s\) in \d+ms: `vercel inspect --logs` returned no build-log lines/
)
})
it('names every marker missing from the build logs', async () => {
installClock()
logs = ok(`${cliHeader}${buildOutput}`)
const next = await instance()
await expect(next.start()).rejects.toThrow(
/^Failed to get buildId from logs .*: the build logs are missing the BUILD_ID, DEPLOYMENT_ID, NEXT_SUPPORTS_IMMUTABLE_ASSETS marker\(s\)/
)
})
it('names only the markers that are missing', async () => {
installClock()
logs = ok(
`${cliHeader}${buildOutput}BUILD_ID: build-id\nDEPLOYMENT_ID: deployment-id\n`
)
const next = await instance()
await expect(next.start()).rejects.toThrow(
'the build logs are missing the NEXT_SUPPORTS_IMMUTABLE_ASSETS marker(s)'
)
})
it('includes why the last inspect call failed', async () => {
process.env.NEXT_E2E_TEST_TIMEOUT = '60000'
const clock = installClock()
inspectResults = Array.from({ length: 10 }, () => hungInspect(clock))
const next = await instance()
await expect(next.start()).rejects.toThrow(
/The last vercel inspect call timed out after \d+ms/
)
})
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment