From 5c7d1bdd863642910f577da45813c95988bcb471 Mon Sep 17 00:00:00 2001 From: Samuel K <69881238+skevetter@users.noreply.github.com> Date: Sun, 27 Sep 2026 23:24:25 -0600 Subject: [PATCH 1/5] ci: run Go unit tests on pull requests No workflow executed `go test`. The only occurrence compiled the e2e binary with `go test -c`, and the e2e suites need Docker and a built CLI, so the 401 unit test files were never run on a pull request. That is how a redactor bug and eight failing tests in pkg/agent/delivery survived unnoticed. Add a unit-tests job mirroring `task cli:test`: race detector, coverage profile, -p 4 to keep the wall-clock assertions from being exceeded on a busy runner, and the same exclusion of /test and /e2e. It uploads the coverage profile as an artifact. The job is report-only, and one line away from required. The suite's intermittent failures were a poll defect, fixed in this branch; the one remaining wall-clock test, TestWaitContainerRunningFailsFastOnExit, has a wide margin. Promoting it means a slow runner can block an unrelated pull. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/pr-ci.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index c690f16b15..3134b88575 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -151,6 +151,39 @@ jobs: - name: Check license policy and attribution run: go run ./hack/licenses --check + unit-tests: + name: Unit Tests + # Report-only, and one line from required. The suite's intermittent + # failures were a poll defect, now fixed; the one remaining wall-clock + # test, TestWaitContainerRunningFailsFastOnExit, has a wide margin. + # Promoting it means a slow runner can block an unrelated pull. + needs: [changes, precommit, lint] + if: needs.changes.outputs.go == 'true' + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7 + with: + go-version-file: go.mod + + - name: Create coverage output directory + run: mkdir -p dist + + # Mirrors `task cli:test`. -p 4 caps parallelism because the wall-clock + # assertions are exceeded at full parallelism on a busy runner. + - name: Run unit tests + run: go test $(go list ./... | grep -v -e /test -e /e2e) -race -p 4 -coverprofile=dist/profile.out -covermode=atomic + + - name: Upload coverage profile + if: always() + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 + with: + name: unit-coverage-profile + path: dist/profile.out + if-no-files-found: warn + integration-tests-unprivileged: name: Test ${{ matrix.label }} on ${{ matrix.runner }} needs: [changes, build-cli] From 9bcbb0835478bf114d8a5527ff5915919ce9b977 Mon Sep 17 00:00:00 2001 From: Samuel K <69881238+skevetter@users.noreply.github.com> Date: Sun, 27 Sep 2026 23:24:26 -0600 Subject: [PATCH 2/5] test: make two environment-dependent tests hermetic Both fail on a developer machine for reasons unrelated to the code under test. TestFindDarwinDockerCLIRancherDesktopPath searched the full candidate list, which begins with machine-wide locations such as /usr/local/bin/docker. Installing Docker therefore made the search return the real binary instead of the fixture. Check that the Rancher location is among the candidates and look it up on its own. TestChangedFilesDetectsWorkingTree created a throwaway repository and committed to it. This project requires signed commits, so contributors commonly set commit.gpgsign globally, and that setting is inherited by the throwaway repo, where no signing key is available; the setup commit exited 128. Disable signing in the fixture repository. Co-Authored-By: Claude Opus 4.8 (1M context) --- cmd/internal/agentworkspace/docker_darwin_test.go | 11 ++++++++++- hack/sign_commit/main_test.go | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/internal/agentworkspace/docker_darwin_test.go b/cmd/internal/agentworkspace/docker_darwin_test.go index 2be8490f48..70d5435d6e 100644 --- a/cmd/internal/agentworkspace/docker_darwin_test.go +++ b/cmd/internal/agentworkspace/docker_darwin_test.go @@ -5,6 +5,7 @@ package agentworkspace import ( "os" "path/filepath" + "slices" "strings" "testing" ) @@ -28,11 +29,19 @@ func TestFindDarwinDockerCLIAtKnownPath(t *testing.T) { } } +// The full candidate list also contains machine-wide docker paths, so the +// result is not asserted against it; that depends on the host. func TestFindDarwinDockerCLIRancherDesktopPath(t *testing.T) { home := t.TempDir() rancher := filepath.Join(home, ".rd", "bin", "docker") writeExecutable(t, rancher) - path, err := findDarwinDockerCLIInPaths(darwinDockerCandidatePaths(home)) + + candidates := darwinDockerCandidatePaths(home) + if !slices.Contains(candidates, rancher) { + t.Fatalf("candidate paths %v missing rancher path %q", candidates, rancher) + } + + path, err := findDarwinDockerCLIInPaths([]string{rancher}) if err != nil || path != rancher { t.Fatalf("find docker CLI = %q, %v; want %q", path, err, rancher) } diff --git a/hack/sign_commit/main_test.go b/hack/sign_commit/main_test.go index 65d6e72207..9348c0f93b 100644 --- a/hack/sign_commit/main_test.go +++ b/hack/sign_commit/main_test.go @@ -405,6 +405,8 @@ func TestChangedFilesDetectsWorkingTree(t *testing.T) { gitRun(t, dir, "init", "--quiet") gitRun(t, dir, "config", "user.email", "t@t.com") gitRun(t, dir, "config", "user.name", "test") + // Contributors of this project commonly sign globally, which breaks this. + gitRun(t, dir, "config", "commit.gpgsign", "false") gitRun(t, dir, "checkout", "-b", testMainBranch) writeFile(t, filepath.Join(dir, "committed.txt"), "x") writeFile(t, filepath.Join(dir, "staged.txt"), "s") From fb0c314739a92c04074abb3b38d75283a60dbd9c Mon Sep 17 00:00:00 2001 From: Samuel K <69881238+skevetter@users.noreply.github.com> Date: Sun, 27 Sep 2026 23:24:33 -0600 Subject: [PATCH 3/5] fix(docker): report a missing image when the inspect poll times out waitForLocalImage documents that it returns the last ErrImageNotFound once the poll timeout elapses, but that only held while the poll was not interrupted mid-command. When the deadline fires while a docker inspect is still in flight, the context kills that process and the "signal: killed" failure is returned instead. Callers branch on that error to decide that a built image must never be resolved by a pull, so the wrong error changes behavior under load rather than only changing a message. Treat a deadline-expired poll as a miss and let the deadline decide the outcome. A cancelled parent context still propagates, so callers keep seeing the cancellation they asked for. This was the cause of the intermittent EnsureImage failures: with the fix, the full suite passes where before it failed three to five tests per run. The new test forces the deadline to land inside an inspect and fails with the original "inspect image: signal: killed" symptom if the fix is reverted. Also fix a race in TestCommandDevContainer_CancelWrapsCtxErr, whose helper goroutine gave up after one second and cancelled regardless, so on a slow start it cancelled while the driver was still in the inspect call preceding exec. Co-Authored-By: Claude Opus 4.8 (1M context) --- pkg/driver/docker/lifecycle.go | 9 ++++++++ pkg/driver/docker/lifecycle_test.go | 34 ++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/pkg/driver/docker/lifecycle.go b/pkg/driver/docker/lifecycle.go index 6dc365b202..b5fbf5409c 100644 --- a/pkg/driver/docker/lifecycle.go +++ b/pkg/driver/docker/lifecycle.go @@ -391,6 +391,15 @@ func (d *dockerDriver) waitForLocalImage(ctx context.Context, image string) erro lastErr = err return false, nil } + // A deadline that fires mid-inspect kills the subprocess, so the + // failure arrives as "signal: killed". That is the poll timing + // out, not the daemon failing, so let the deadline decide. + if errors.Is(ctx.Err(), context.DeadlineExceeded) { + if lastErr == nil { + lastErr = docker.ErrImageNotFound + } + return false, nil + } return false, err }, ) diff --git a/pkg/driver/docker/lifecycle_test.go b/pkg/driver/docker/lifecycle_test.go index c8aa4ed607..7bec9ca672 100644 --- a/pkg/driver/docker/lifecycle_test.go +++ b/pkg/driver/docker/lifecycle_test.go @@ -87,6 +87,36 @@ func withShortImageInspectPoll(t *testing.T) { }) } +// A deadline firing mid-inspect must still report the image missing: callers +// branch on that to avoid pulling a locally-built image. +func TestEnsureImage_PollDeadlineDuringInspectReportsNotFound(t *testing.T) { + withShortImageInspectPoll(t) + imageInspectPollTimeout = 200 * time.Millisecond + + dir := t.TempDir() + marker := filepath.Join(dir, "pulled") + bin := filepath.Join(dir, "docker-fake") + // The inspect outlives the poll deadline, so it is always killed. + script := `#!/bin/sh +case "$1" in + inspect) sleep 5 ;; + pull) echo pulled > "` + marker + `" ;; +esac +` + require.NoError(t, os.WriteFile(bin, []byte(script), 0o755)) //nolint:gosec + + d := &dockerDriver{Docker: &docker.DockerHelper{DockerCommand: bin}} + + err := d.EnsureImage( + context.Background(), + &driver.RunOptions{Image: testImageRef, ImageBuilt: true}, + ) + + require.Error(t, err) + assert.ErrorIs(t, err, docker.ErrImageNotFound) + assert.NoFileExists(t, marker) +} + func TestEnsureImage_BuiltImageNeverFoundDoesNotPull(t *testing.T) { withShortImageInspectPoll(t) marker := filepath.Join(t.TempDir(), "pulled") @@ -308,7 +338,9 @@ esac ctx, cancel := context.WithCancel(context.Background()) go func() { - deadline := time.Now().Add(time.Second) + // Cancelling before exec starts kills the preceding inspect instead, + // losing the context error. The deadline is only a backstop. + deadline := time.Now().Add(30 * time.Second) for time.Now().Before(deadline) { if _, err := os.Stat(ready); err == nil { break From 8116dbbee2886e8599af35b5840ea2f0eb836b2f Mon Sep 17 00:00:00 2001 From: Samuel K <69881238+skevetter@users.noreply.github.com> Date: Sun, 27 Sep 2026 23:24:33 -0600 Subject: [PATCH 4/5] fix(docker): widen the post-deadline diagnostic budget WaitContainerRunning re-inspects without the poll deadline so a daemon error survives into the final message, but that retry had a 250ms budget hard-coded inline. On a loaded machine the retry is itself killed and the diagnostic degrades to "signal: killed", which is what TestWaitContainerRunning_PreservesDeadlineExceededWithInspectError asserts against. Name the budget and raise it to 2s. It only runs on the slow path, where the alternative is losing the error entirely. Co-Authored-By: Claude Opus 4.8 (1M context) --- pkg/docker/helper.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/docker/helper.go b/pkg/docker/helper.go index ce9336fb47..f43b27cf04 100644 --- a/pkg/docker/helper.go +++ b/pkg/docker/helper.go @@ -22,6 +22,10 @@ import ( "k8s.io/apimachinery/pkg/util/wait" ) +// postDeadlineDiagnosticTimeout bounds the un-deadlined inspect after a poll +// deadline fires; too small a budget loses the daemon error to a killed child. +const postDeadlineDiagnosticTimeout = 2 * time.Second + // DockerBuilder represents the Docker builder types. type DockerBuilder int @@ -515,7 +519,7 @@ func (r *DockerHelper) WaitContainerRunning(ctx context.Context, containerID str // daemon error can still be captured for the final diagnostic. diagnosticCtx, diagnosticCancel := context.WithTimeout( context.WithoutCancel(ctx), - 250*time.Millisecond, + postDeadlineDiagnosticTimeout, ) details, err = r.InspectContainers(diagnosticCtx, []string{containerID}) diagnosticCancel() From 55f65665dba518eefb0e52dda99313f6db4bb630 Mon Sep 17 00:00:00 2001 From: Samuel K <69881238+skevetter@users.noreply.github.com> Date: Sun, 27 Sep 2026 23:39:24 -0600 Subject: [PATCH 5/5] fix(ci): silence shellcheck on the unit test package list actionlint runs shellcheck over `run:` blocks, and SC2046 flagged the `$(go list ...)` substitution in the unit test step. The word splitting is the point there: the package list is meant to become arguments. Verify the scope first: ./pkg/... ./cmd/... is not a substitute, since the list also covers the root module, hack/ and providers/. Keep the substitution and disable the check for that line. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/pr-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index 3134b88575..9d4bf430ee 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -174,7 +174,9 @@ jobs: # Mirrors `task cli:test`. -p 4 caps parallelism because the wall-clock # assertions are exceeded at full parallelism on a busy runner. - name: Run unit tests - run: go test $(go list ./... | grep -v -e /test -e /e2e) -race -p 4 -coverprofile=dist/profile.out -covermode=atomic + run: | + # shellcheck disable=SC2046 # the package list is meant to become arguments + go test $(go list ./... | grep -v -e /test -e /e2e) -race -p 4 -coverprofile=dist/profile.out -covermode=atomic - name: Upload coverage profile if: always()