test(hooks): skip the stdin-JSON hook test when jq is missing - #4053
Open
dwin-gharibi wants to merge 1 commit into
Open
test(hooks): skip the stdin-JSON hook test when jq is missing#4053dwin-gharibi wants to merge 1 commit into
dwin-gharibi wants to merge 1 commit into
Conversation
printStdinJSONFieldCmd shells out to jq, the only test helper here needing a
JSON parser in the shell. POSIX has no built-in one; the Windows mirror can
lean on PowerShell's ConvertFrom-Json.
Without jq the hook still ran, produced no output, and the test failed on its
content assertion instead, reporting
"" does not contain "final answer content"
which reads as a defect in the hook plumbing rather than a missing tool on the
machine. Skip with the real reason instead, so the diagnosis is immediate and
coverage is unchanged wherever jq is installed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
printStdinJSONFieldCmdshells out tojq. Whenjqis absent the hook still runs and exitscleanly, producing no output, so the test fails on its content assertion rather than on a
missing command — reporting a hook-plumbing defect that does not exist.
Closes #4052.
Before
On a machine without
jq(e.g. stockgolang:1.27):After
With
jqpresent, unchanged:What changed
The helper takes
*testing.Tand guards onexec.LookPath:The Windows mirror takes the same parameter for signature parity but needs no guard —
PowerShell's
ConvertFrom-Jsonis built in. One caller updated.Why skip rather than drop the dependency
Removing
jqwould mean either parsing JSON withsed/awk— fragile, and a fragile test isworse than a skipped one — or weakening the assertion to "the value appears somewhere in the
payload", which stops testing that the value arrives in the named field.
Skipping keeps the assertion exact wherever
jqexists (CI, most dev machines) and makes thefailure mode honest everywhere else. Coverage is unchanged on any machine that had
jq.Verification
Tested both paths in a container, by moving
/usr/bin/jqaside and back:jqpresentjqabsentokFAIL— misleading assertionok(PASS)ok(SKIP, names jq)Full
pkg/hookspackage passes in both states;go vetclean.Note
This is a test-only change. No production code is touched, and behaviour on machines with
jqinstalled is byte-for-byte identical.