Repository navigation
fix(notices): anchor go-licenses test guards and cover the fail-closed path - #2163
Conversation
📝 WalkthroughWalkthroughThe test script strengthens quote-tolerant checks for Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tools/generate-notices_test.sh`:
- Around line 45-46: Update the grep assertions around INSTALL_ACTION and the
corresponding workflow install check in generate-notices_test.sh to accept
unquoted, double-quoted, and single-quoted github.com/google/go-licenses paths,
while preserving the existing GOFLAGS= go install validation.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 12c13613-9915-45c6-8c3d-34539dbc2fe3
📒 Files selected for processing (1)
tools/generate-notices_test.sh
2a54719 to
cdb284a
Compare
mchmarny
left a comment
There was a problem hiding this comment.
Approved — no blockers. Verified the guards anchor to executable install lines, cover all supported quote forms, run license checks independently of yq, and fail closed on an unusable GOROOT. Shell validation and the merge gate pass.
cdb284a to
5b8bf47
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tools/generate-notices_test.sh`:
- Around line 55-56: Update the install-command validation around INSTALL_ACTION
so compliance is evaluated per command rather than allowing a whole line
containing GOFLAGS= go install to bypass the check. Require the approved
expression to match the complete executable line with only an optional trailing
comment, or explicitly reject command separators and multiple install commands
on the same line.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Enterprise
Run ID: 800e2f09-1e51-49c5-b8f4-f64ae006d39e
📒 Files selected for processing (1)
tools/generate-notices_test.sh
|
@mchmarny re-review please — one new guard since your approval, plus a rebase onto current main. Your approval was on What changed: an independent review pointed out that the install-action assertion was a presence check. It proved at least one correct install exists, not that every install does — so a second install line appended to that action without Verified as a control/mutant pair, including the false-positive direction:
|
5b8bf47 to
a92f126
Compare
…d path The guards added with the GOROOT fix pass in states they exist to reject. - The install-action assertion did a whole-file `grep -q 'GOFLAGS= go install'`, which the action's own explanatory comment satisfies. Deleting `GOFLAGS=` from the real `run:` step left the suite green, so the -trimpath/empty-GOROOT regression could return undetected. Anchor the match to the executable line. - That assertion is a presence check: it proves at least one correct install exists, not that every install is. A second install line appended to the same action without `GOFLAGS=` would leave it green, and the workflow scan below deliberately does not cover .github/actions/, so nothing else would catch it. Reject any install line in the action that does not clear GOFLAGS. - The inline-install scan required whitespace directly before the module path, so it matched only an unquoted `go install github.com/...`. Every install site in this repo quotes the path, so a quoted inline install in a workflow was not detected. Accept either quote form: matching only `"` would still let a single-quoted install through. The scan stays scoped to .github/workflows/ on purpose - the canonical action is where the real install lives, so widening the root would flag it as a violation of itself. - `make license-check` had no negative case. The stub go-licenses exits 0 unconditionally, so deleting the recipe's GOROOT validation branch left the suite green and only the export half was covered. Add a control that stubs `go env GOROOT` to print an unusable path while exiting 0. Exporting GOROOT=/nonexistent does not work: the real `go env` rejects it and exits 2, aborting the recipe under `set -e` before the branch is reached, which passes against a recipe with no validation at all. - The yq gate exited 0 for the whole file, discarding the license-check cases that never invoke the generator and so have no yq dependency. Locally that disabled every new assertion. Move the shared fixtures above the gate and run the license-check cases first, leaving the gate to guard only the generator. Follow-up to NVIDIA#2159. Signed-off-by: Yuan Chen <[email protected]>
a92f126 to
52efab7
Compare
|
Rebased onto current main ( One further change since the re-review request, from a review comment: the new install-action guard had the same granularity bug it was written to catch. It excluded any line containing Verified in both directions:
Still one file ( |
Summary
The guards added with the
go-licensesGOROOT fix in #2159 pass in the states they exist to reject. Anchor them to what they actually assert, add the missing negative control formake license-check, and stop the yq gate from discarding the assertions that do not need yq.Motivation / Context
#2159 fixed a real defect: a
-trimpath-linkedgo-licensescarries no baked-inGOROOT, so the stdlib prefix collapses to/, the whole dependency graph is classified as standard library, andmake license-checkpasses while inspecting nothing. The runtime fixes in that PR are correct and are not changed here.What is changed is the enforcement around them. Each guard was verified by mutation: reproduce the regression it names, then check whether the suite goes red. Most did not.
The install-action assertion was a presence check. Beyond being satisfied by a comment (below), it proved only that at least one correct install exists. A second install line appended to the same action without
GOFLAGS=left it green, and the workflow scan deliberately does not cover.github/actions/, so nothing else caught it. Every go-licenses install line must now match in full — aGOFLAGS=-cleared install and nothing else, bar a trailing comment. Matching in full rather than excluding lines that merely contain the prefix matters:GOFLAGS= go install <other>; go install <go-licenses>contains it while leaving the go-licenses install unguarded, so the trailing[^;&|]*$bans command separators and pins one install per line.The install-action assertion is satisfied by a comment.
tools/generate-notices_test.shdid a whole-filegrep -q 'GOFLAGS= go install', andinstall-go-licenses/action.ymlcontains that literal twice — once at line 32 explaining the contract in prose, once at line 60 as the realrun:step. DeletingGOFLAGS=from line 60 left the suite green, so the exact-trimpathregression the action exists to prevent could return undetected.The inline-install scan matched a form nobody writes. The pattern required whitespace directly before the module path, so it caught
go install github.com/...but missedgo install "github.com/...". Every install site in this repo quotes the path, so a quoted inline install added to a workflow was not detected. Both quote forms are now accepted — matching only"would still let a single-quoted install through.make license-checkhad no negative case. The stubgo-licensesexits 0 unconditionally and the only assertions were "exit 0" plus the GOROOT probe. Deleting the recipe's validation branch left the suite green, so the export half was covered and the fail-closed half was not.The yq gate disabled the cases that do not need yq. It exited 0 for the whole file, but the
license-checkcases never invoke the generator and have no yq dependency. On a machine without mikefarah yq,make testran none of the new assertions.Fixes: N/A
Related: #2159
Type of Change
Component(s) Affected
cmd/aicr,pkg/cli)cmd/aicrd,pkg/server)pkg/recipe)pkg/bundler,pkg/component/*)pkg/collector,pkg/snapshotter)pkg/validator)pkg/errors,pkg/k8s)docs/,examples/)Implementation Notes
The inline-install scan stays scoped to
.github/workflows/. Widening it to all of.github/looks like the obvious companion fix and is wrong: once the quote is optional, the pattern matches the canonicalinstall-go-licensesaction itself, and the pre-existing install ingo-build-release. The guard would then flag the very install it exists to steer people toward. The comment records that reasoning so the next reader does not re-derive it.The negative control stubs
go env GOROOTrather than exportingGOROOT. SettingGOROOT=/nonexistentlooks equivalent and is vacuous: the realgo env GOROOTrejects an invalidGOROOTand exits 2, soset -eaborts the recipe before the validation branch is ever reached. That test passes against a recipe with no validation at all. The stub instead prints an unusable path while exiting 0, which is the only state that actually reaches the branch. Everything other than theGOROOTlookup defers to the real toolchain, so the rest of the recipe runs unmodified.Ordering. The shared fixtures (temp dir, stub
go-licenses,assert_goroot_exported) moved above the yq gate so thelicense-checkcases can run first. The gate now guards only the generator case, which is the sole consumer of yq.No production code changed; this is test-only.
Testing
make test-shell # exit 0, 0 failures bash tools/generate-notices_test.shEach guard was verified as a control/mutant pair — the mutation must pass before the change and fail after, or the guard is decoration:
GOFLAGS=from the action'srun:stepGOFLAGS=GOFLAGS=(legitimate)GOFLAGS=line (...; go install ...)go installto a workflowgo installto a workflowlicense-checkGOROOT validation branchmake test-shellpasses with zero failures, and the suite's three assertions run:Also ran
bash -nandshellcheck -S warningon the changed file, both clean.Full
make qualifywas not run. The change is a single shell test file with no Go source, so the Go build, race tests, coverage gate, e2e, scan, and api-diff lanes cannot regress from it;make test-shellis the lane that actually executes the changed file, and it passes.Risk Assessment
Rollout notes: N/A — test-only, no runtime or released-artifact behavior change. Worth noting for reviewers: these guards now genuinely fail on the states they name, so they can start failing on a future change that would previously have passed unexamined. That is the intent.
Checklist
make testwith-race) —make test-shell; no Go source changedmake lint) —shellcheck -S warningandbash -non the changed filegit commit -S) — GPG signing info