Skip to content

fix(notices): anchor go-licenses test guards and cover the fail-closed path - #2163

Merged
mchmarny merged 2 commits into
NVIDIA:mainfrom
yuanchen8911:fix/notices-test-guards
Aug 11, 2026
Merged

mchmarny merged 2 commits into
NVIDIA:mainfrom
yuanchen8911:fix/notices-test-guards

Conversation

@yuanchen8911

@yuanchen8911 yuanchen8911 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The guards added with the go-licenses GOROOT fix in #2159 pass in the states they exist to reject. Anchor them to what they actually assert, add the missing negative control for make 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-linked go-licenses carries no baked-in GOROOT, so the stdlib prefix collapses to /, the whole dependency graph is classified as standard library, and make license-check passes 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 — a GOFLAGS=-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.sh did a whole-file grep -q 'GOFLAGS= go install', and install-go-licenses/action.yml contains that literal twice — once at line 32 explaining the contract in prose, once at line 60 as the real run: step. Deleting GOFLAGS= from line 60 left the suite green, so the exact -trimpath regression 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 missed go 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-check had no negative case. The stub go-licenses exits 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-check cases never invoke the generator and have no yq dependency. On a machine without mikefarah yq, make test ran none of the new assertions.

Fixes: N/A
Related: #2159

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Build/CI/tooling

Component(s) Affected

  • CLI (cmd/aicr, pkg/cli)
  • API server (cmd/aicrd, pkg/server)
  • Recipe engine / data (pkg/recipe)
  • Bundlers (pkg/bundler, pkg/component/*)
  • Collectors / snapshotter (pkg/collector, pkg/snapshotter)
  • Validator (pkg/validator)
  • Core libraries (pkg/errors, pkg/k8s)
  • Docs/examples (docs/, examples/)
  • Other: third-party notices test guards

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 canonical install-go-licenses action itself, and the pre-existing install in go-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 GOROOT rather than exporting GOROOT. Setting GOROOT=/nonexistent looks equivalent and is vacuous: the real go env GOROOT rejects an invalid GOROOT and exits 2, so set -e aborts 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 the GOROOT lookup 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 the license-check cases 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.sh

Each guard was verified as a control/mutant pair — the mutation must pass before the change and fail after, or the guard is decoration:

Mutation before after
Delete GOFLAGS= from the action's run: step exit 0 exit 1
Append a second install to the action without GOFLAGS= exit 0 exit 1
Append a second install with GOFLAGS= (legitimate) exit 0 exit 0 (no false positive)
Chain an unguarded install onto a GOFLAGS= line (...; go install ...) exit 0 exit 1
Add a double-quoted inline go install to a workflow exit 0 exit 1
Add a single-quoted inline go install to a workflow exit 0 exit 1
Delete the license-check GOROOT validation branch no case existed exit 1
yq unavailable SKIP, zero assertions ran 2 assertions run, then SKIP

make test-shell passes with zero failures, and the suite's three assertions run:

Running tools/generate-notices_test.sh...
make license-check exports a usable GOROOT to go-licenses
make license-check fails closed when GOROOT is unusable
generate-notices fails closed on an empty go-licenses collection

Also ran bash -n and shellcheck -S warning on the changed file, both clean.

Full make qualify was 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-shell is the lane that actually executes the changed file, and it passes.

Risk Assessment

  • Low — Isolated change, well-tested, easy to revert
  • Medium — Touches multiple components or has broader impact
  • High — Breaking change, affects critical paths, or complex rollout

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

  • Tests pass locally (make test with -race) — make test-shell; no Go source changed
  • Linter passes (make lint) — shellcheck -S warning and bash -n on the changed file
  • I did not skip/disable tests to make CI green
  • I added/updated tests for new functionality
  • I updated docs if user-facing behavior changed — N/A, no user-facing behavior change
  • Changes follow existing patterns in the codebase
  • Commits are cryptographically signed (git commit -S) — GPG signing info

@yuanchen8911
yuanchen8911 requested a review from a team as a code owner August 11, 2026 17:53
@yuanchen8911 yuanchen8911 added the theme/ci-dx CI pipelines, developer experience, and build tooling label Aug 11, 2026
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The test script strengthens quote-tolerant checks for go-licenses installation commands and rejects inline workflow installations. It adds license-check tests for valid and invalid GOROOT values. The generator test retains the yq dependency gate and runs after the license-check cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • NVIDIA/aicr#2159: Extends related generate-notices_test.sh regression coverage for GOROOT handling and go-licenses installation checks.

Suggested labels: area/ci

Suggested reviewers: njhensley, mchmarny

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the test-guard fixes for go-licenses and the fail-closed path.
Description check ✅ Passed The description directly explains the strengthened go-licenses guards, negative test, yq gating, scope, and validation results.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2e5908 and 2a54719.

📒 Files selected for processing (1)
  • tools/generate-notices_test.sh

Comment thread tools/generate-notices_test.sh Resolved
mchmarny
mchmarny previously approved these changes Aug 11, 2026

@mchmarny mchmarny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cdb284a and 5b8bf47.

📒 Files selected for processing (1)
  • tools/generate-notices_test.sh

Comment thread tools/generate-notices_test.sh Resolved
@yuanchen8911
yuanchen8911 requested a review from mchmarny August 11, 2026 20:06
@yuanchen8911

Copy link
Copy Markdown
Contributor Author

@mchmarny re-review please — one new guard since your approval, plus a rebase onto current main.

Your approval was on cdb284ac3; the head is now 5b8bf4719.

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 GOFLAGS= left the suite green, and the workflow scan deliberately does not cover .github/actions/, so nothing else caught it. The guard now rejects any install line in the action that does not clear GOFLAGS.

Verified as a control/mutant pair, including the false-positive direction:

  • second install without GOFLAGS= → exit 1
  • second install with GOFLAGS= (legitimate) → exit 0
  • original case, GOFLAGS= deleted from the only install → exit 1

make test-shell passes with zero failures; all checks are green on the rebased head. The rest of the PR is unchanged from what you approved.

@yuanchen8911
yuanchen8911 force-pushed the fix/notices-test-guards branch from 5b8bf47 to a92f126 Compare August 11, 2026 20:12
…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]>
@yuanchen8911
yuanchen8911 force-pushed the fix/notices-test-guards branch from a92f126 to 52efab7 Compare August 11, 2026 20:21
@yuanchen8911

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (b349a5905); head is now 52efab76a. All checks green.

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 GOFLAGS= go install, so GOFLAGS= go install <other>; go install <go-licenses> slipped through with the go-licenses install unguarded. Reproduced that bypass, then changed the guard to require each go-licenses install line to match in full — a GOFLAGS=-cleared install and nothing else, bar a trailing comment — with [^;&|]*$ banning command separators so one line carries exactly one install.

Verified in both directions:

  • chained unguarded install (...; go install ...) → exit 1
  • second unguarded install on its own line → exit 1
  • second legitimate GOFLAGS= install → exit 0, no false positive
  • clean run → exit 0

Still one file (tools/generate-notices_test.sh), one signed commit, no production code.

@mchmarny
mchmarny enabled auto-merge (squash) August 11, 2026 21:18
@mchmarny
mchmarny merged commit 908a2ca into NVIDIA:main Aug 11, 2026
37 of 38 checks passed
@yuanchen8911
yuanchen8911 deleted the fix/notices-test-guards branch August 19, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M theme/ci-dx CI pipelines, developer experience, and build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants