Skip to content

pkg/hooks tests fail with a misleading assertion when jq is not installed #4052

Description

@dwin-gharibi

Description

pkg/hooks has one test helper that needs a JSON parser in the shell:

func printStdinJSONFieldCmd(field string) string {
	return `cat | jq -r '.` + field + `'`
}

jq is not part of the Go toolchain and is absent from stock container images
(golang:1.27 does not ship it). When it is missing the hook still runs and exits cleanly — it
just produces no output — so the test does not fail on "command not found". It fails later, on
its content assertion, with an error that points at the hook plumbing instead of at the machine.

Expected Behavior

A missing external tool is reported as a missing external tool: the test skips with a reason
naming jq, and the package still reports ok.

Actual Behavior

TestExecuteStopReceivesResponseContent fails with:

"" does not contain "final answer content"

Nothing in that message mentions jq. It reads as "the stop hook is not receiving the response
content", i.e. a product defect in hook input plumbing.

Steps to Reproduce

  1. Use a machine or container without jq (e.g. the stock golang:1.27 image).
  2. go test ./pkg/hooks/
  3. Observe the failure above.

Docker Agent version

No response

OS & terminal

No response

Model used

No response

Error output

=== RUN   TestExecuteStopReceivesResponseContent
    hooks_test.go:586:
        	Error Trace:	pkg/hooks/hooks_test.go:586
        	Error:      	"" does not contain "final answer content"
        	Test:       	TestExecuteStopReceivesResponseContent
--- FAIL: TestExecuteStopReceivesResponseContent (0.00s)
FAIL	github.com/docker/docker-agent/pkg/hooks	20.059s


Confirmed as environmental, not a regression — it reproduces on unmodified `main`
(`f2807d1bb`), 3 runs out of 3, and disappears the moment `jq` is installed.

Screenshots

No response

Additional context

The cost of this is diagnostic time spent in the wrong place. Found while verifying an unrelated
branch: the failure was initially read as a merge regression, and it took a baseline run against
untouched main plus tracing the helper to identify a missing package as the cause.

It also makes the package quietly hostile to contributors whose machines lack jq — the first
run of the suite reports what looks like a real bug.

Only one test uses the helper, so the blast radius is small and the fix is contained.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/testingTest infrastructure, CI/CD, test runners, evaluation

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions