pkg/hooks tests fail with a misleading assertion when jq is not installed
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 3.3k
- Forks
- 462
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 273
Description
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
- Use a machine or container without
jq(e.g. the stockgolang:1.27image). go test ./pkg/hooks/- 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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pkg/hooks/hooks_test.go, especially printStdinJSONFieldCmd and TestExecuteStopReceivesResponseContent. Run go test ./pkg/hooks/ in an environment without jq, then inspect how the helper is invoked and how test prerequisites are handled elsewhere. Done means the test skips with a reason naming jq and the package still reports ok.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, shell
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100