Skip to content

integration/build: check build errors - #53880

Merged
vvoland merged 2 commits into
moby:masterfrom
kolyshkin:integration-build-check-errors
Oct 8, 2026
Merged

vvoland merged 2 commits into
moby:masterfrom
kolyshkin:integration-build-check-errors

Conversation

@kolyshkin

@kolyshkin kolyshkin commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Build errors are reported in the build response stream, and io.Copy does
not check for those, so a test that only reads the build response with
io.Copy passes even if the build fails. This was found in #53859, where
TestBuildPreserveOwnership was silently passing in the userns CI mode
while the build was failing (that test is fixed in #53859, and so it is
not touched here).

This adds a readBuildResponse helper, which copies the stream as is (so
the tests parsing the raw JSON stream, like getImageIDsFromBuild and
readBuildImageIDs users, keep working), and returns an error if the
stream contains one. All the other io.Copy calls in integration/build
are replaced with it, except for TestBuildWCOWSandboxSize, which
tolerates a specific build failure (and is skipped anyway).

Many of the affected tests also inspect the resulting image afterwards,
so they would catch a failed build anyway, but not all of them do (for
example, TestBuildWithEmptyLayers or TestBuildUncleanTarFilenames).

The second commit (suggested by @vvoland) switches the tests that only
need the build to succeed to the build.Do helper, which also checks
for build errors. The rest still use readBuildResponse, as they need
the build output, use a hand-crafted build context, or expect a build
error to be returned rather than failing the test.

AI disclosure: this change was done with Claude Code, and reviewed by me.

Release notes (optional)

@kolyshkin kolyshkin added this to the 29.9.0 milestone Oct 7, 2026
@kolyshkin kolyshkin added area/testing kind/bugfix PR's that fix bugs labels Oct 7, 2026
@kolyshkin
kolyshkin requested review from thaJeztah and vvoland and removed request for vvoland October 7, 2026 18:50

@vvoland vvoland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM.

These could probably also be refactored to use the build.Do helper:

// Do builds an image from the given context with the supplied options
// and returns the image ID.
func Do(ctx context.Context, t *testing.T, apiClient client.APIClient, buildCtx *fakecontext.Fake, options client.ImageBuildOptions) string {
resp, err := apiClient.ImageBuild(ctx, buildCtx.AsTarReader(t), options)
assert.NilError(t, err)
if resp.Body != nil {
defer resp.Body.Close()
}
img := GetImageIDFromBody(t, resp.Body)
t.Cleanup(func() {
_, _ = apiClient.ImageRemove(ctx, img, client.ImageRemoveOptions{Force: true})
})
return img
}

@vvoland

vvoland commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Needs linter fixes

The build errors are reported in the response stream, and io.Copy does
not check for those, so a test that only reads the build response with
io.Copy passes even if the build fails.

Add readBuildResponse helper, which copies the stream as is (so that
the tests parsing the raw stream keep working), and returns an error
if the stream contains one. Use it instead of io.Copy.

TestBuildWCOWSandboxSize is left as is, since it tolerates a specific
build failure.

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin
kolyshkin force-pushed the integration-build-check-errors branch from b22897b to 058c26f Compare October 8, 2026 04:50
@kolyshkin

Copy link
Copy Markdown
Contributor Author

Needs linter fixes

Same, this was caused by a bad base/master. Rebased.

Use build.Do helper in tests which only need the build to succeed,
instead of open-coding it. The helper checks for build errors, and
also removes the built image on cleanup.

While at it, use buildtypes alias for api/types/build, as is done
elsewhere, since the build name is now taken.

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin

Copy link
Copy Markdown
Contributor Author

These could probably also be refactored to use the build.Do helper:

@vvoland some of them, yes. Added a second commit, PTAL

@vvoland

vvoland commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

integration-flaky failures can be ignored - this PR changes a lot of build related tests and running them all multiple times drains the runner disk space.

@vvoland vvoland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@vvoland
vvoland merged commit f313c02 into moby:master Oct 8, 2026
236 of 243 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/testing kind/bugfix PR's that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants