Make three unit tests independent of host arch, timezone and temp path
What does this MR do?
Fixes three unit tests that pass only on hosts like CI's: amd64, UTC, and a short temp directory path. Only test files change.
TestPrepare, case "autoset helper arch and os on non windows does not need windows kernel version" (executors/kubernetes)
-
What it assumed: an amd64 host. With
helper_image_autoset_arch_and_osset,retrieveHelperImageConfigtakes the architecture fromcommon.AppVersion.Architecture, which isruntime.GOARCH. The case expected thex86_64helper image. -
How it failed off CI: on an arm64 host (Apple Silicon, or a linux/arm64 container) the executor picks the arm64 helper image:
- Architecture: (string) (len=6) "x86_64", + Architecture: (string) (len=5) "arm64", -
The fix: the case pins
common.AppVersion.Architecturetoamd64in itsSetuphook and restores it int.Cleanup. It still checks what it checked on CI: with autoset on a non-Windows runner, the Windows kernel version is not read and the Linux x86_64 helper image is chosen. The other two autoset cases compute their expectation from the host, or run only on Windows, so they are unchanged.
TestGenerateMetadataToFile (commands/helpers)
-
What it assumed: a host set to UTC. The test formats the start and end times with
time.Now().Format(time.RFC3339), which uses the host's zone, passes them to the generator, and asserts that the output contains those strings. The generator writesstartedOnandfinishedOnthroughprotojson, which renders Timestamps in UTC, so the strings only match when the host's zone is UTC. -
How it failed off CI, with
TZ=Australia/Sydney: the output has"startedOn": "2026-10-19T22:12:02Z", and the assertion fails with:... does not contain "2026-10-20T09:12:02+11:00" -
The fix: the two
Containsassertions look forstartedAt.UTC().Format(time.RFC3339)andendedAt.UTC().Format(time.RFC3339). The input stays in the host's zone, the same form the shell passes to--started-at(shells/abstract.goformatsBuild.StartedAt()andtime.Now()withtime.RFC3339). The comparison of the whole document already passed, because the expected document also goes throughprotojson. The generator's output is correct: the same instant, written in UTC.
TestRunnerWrapperCommand_createListener (commands)
-
What it assumed: a short temp directory path. The test put its unix socket in
t.TempDir(), whose path includes the test name. On macOS that path is 112 bytes, and a unix socket path there must be shorter than 104 bytes (sun_path). On Linux the limit is 108 bytes, and under/tmpthe path is at most 68. -
How it failed off CI, on macOS:
listen unix /var/folders/rn/lf8f_jfn39l5294n66sylplc0000gn/T/TestRunnerWrapperCommand_createListener2377177605/001/test.sock: bind: invalid argument panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]The subtest checked the error with
assert.NoError, carried on, and calledAddr()on the nil listener. The panic ended thecommandstest binary, so the package's remaining tests did not run. -
The fix: the socket goes in a directory from
os.MkdirTemp("", "wrap-*"), removed int.Cleanup. On macOS that path is at most 74 bytes.require.NoErrorreplacesassert.NoError, so a listener that cannot bind fails the subtest instead of panicking. With a deliberately over-longTMPDIR(162 bytes), the two unix socket subtests now fail with the bind error and the other subtests still run.
createListener itself passes the --grpc-listen path to net.Listen unchanged. Runner does not build that path, so the length limit only applies to a path the user chooses, and an over-long one stops the wrapper at startup with the bind error. This MR does not change it.
Why was this MR needed?
The three tests fail on developer machines that are arm64, not set to UTC, or running macOS, although the code they test is correct. The wrapper test's panic also stops the rest of the commands package from running, which hides any other result in that package.
What's the best way to test this MR?
Each command fails on main and passes on this branch:
# On an arm64 host, for example Apple Silicon or a linux/arm64 container
go test -count=1 -run '^TestPrepare$' ./executors/kubernetes
# On any host
TZ=Australia/Sydney go test -count=1 -run '^TestGenerateMetadataToFile$' ./commands/helpers
# On macOS
go test -count=1 -run '^TestRunnerWrapperCommand_createListener$' ./commands
# On Linux, a longer TMPDIR has the same effect (a socket path of up to 129 bytes on main)
d=/tmp/$(printf '%060d' 0); mkdir -p "$d"
TMPDIR="$d" go test -count=1 -run '^TestRunnerWrapperCommand_createListener$' ./commandsWhat I ran:
- On darwin/arm64, in BST: the three tests pass on this branch in the local zone, with
TZ=UTC, and withTZ=Australia/Sydney. They also pass as amd64 binaries under Rosetta (GOARCH=amd64 go test ...). Onmain,TestPreparepasses as amd64, so the architecture is its only host dependency. - In a
golang:1.26.5linux/arm64 container, onmain:TestPreparefails;TestGenerateMetadataToFilepasses in UTC and fails withTZ=Australia/Sydney;TestRunnerWrapperCommand_createListenerpasses under/tmpand panics with the 65-byteTMPDIRabove. On this branch all of them pass. go test -race -count=1on./executors/kubernetes,./commands/helpersand./commands, before and after, with per-test results compared fromgo test -json. The only changes are these tests going from fail to pass, and thecommandstests that did not run onmainbecause of the panic now running and passing. The race detector reported nothing. On this branch the three packages also pass withTZ=UTCandTZ=Australia/Sydney(both with-race), and withGOARCH=amd64.
What are the relevant issue numbers?
Related to #40155.