Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions agent/go/.mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

dir: '{{.InterfaceDir}}/mock'
filename: "{{.InterfaceName}}.go"
template: testify
template-data:
unroll-variadic: true
packages:
github.com/NVIDIA/nodewright/agent/internal/config:
interfaces:
SchemaValidator: {}
github.com/NVIDIA/nodewright/agent/internal/history:
interfaces:
Store: {}
github.com/NVIDIA/nodewright/agent/internal/interrupts:
interfaces:
Interrupt: {}
github.com/NVIDIA/nodewright/agent/internal/step:
interfaces:
Step: {}
5 changes: 5 additions & 0 deletions agent/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ license-header-check: addlicense ## Fail if any agent Go source file is missing
fmt: license-fmt ## Format go files and update license headers.
$(GO) fmt ./...

.PHONY: generate-mocks
generate-mocks: mockery ## Generate interface mocks.
$(MOCKERY) --config .mockery.yaml
$(MAKE) fmt
Comment thread
coderabbitai[bot] marked this conversation as resolved.

.PHONY: vet
vet: ## Run go vet against code.
$(GO) vet ./...
Expand Down
10 changes: 9 additions & 1 deletion agent/go/deps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

GOLANGCI_LINT_VERSION ?= v2.12.2
GINKGO_VERSION ?= v2.32.0
MOCKERY_VERSION ?= v3.7.0

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
printf '%s\n' '--- agent/go/deps.mk ---'
cat -n agent/go/deps.mk
printf '%s\n' '--- Makefile and mockery references ---'
rg -n -C 4 'MOCKERY_VERSION|mockery|generate-mocks' agent/go --glob '!*vendor*'
printf '%s\n' '--- repository metadata ---'
rg -n 'mockery' .github Makefile* agent/go 2>/dev/null || true

Repository: NVIDIA/nodewright

Length of output: 9434


🌐 Web query:

Mockery v3 MOCKERY_VERSION environment variable configuration fails when set official documentation

💡 Result:

The issue where setting the MOCKERY_VERSION environment variable causes Mockery v3 to fail is a documented, known behavior [1][2][3]. Mockery uses the Viper library for configuration management [1][3]. Viper is configured to automatically detect and map environment variables that align with Mockery's internal configuration structure [3]. Because Mockery has an internal configuration setting named version, Viper automatically maps the MOCKERY_VERSION environment variable to this setting [1][2]. When you set MOCKERY_VERSION (for example, in a Dockerfile or CI environment), Mockery attempts to parse that value into its internal version configuration [3]. Since this internal configuration expects a boolean value (e.g., true/false), providing a version string like 2.5.1 or 3.6.4 results in a parsing error and prevents Mockery from executing [3]. The official resolution is to rename the environment variable to something other than MOCKERY_VERSION (e.g., MOCKERY_INSTALL_VERSION) to avoid this collision [1][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- agent/go/Makefile ---'
cat -n agent/go/Makefile | sed -n '1,75p'

printf '%s\n' '--- GNU Make export behavior: command-line override ---'
make -f - MOCKERY_VERSION=v3.7.0 <<'MAKE'
.PHONY: probe
probe:
	`@env` | grep '^MOCKERY_VERSION=' || true
MAKE

printf '%s\n' '--- GNU Make export behavior: command-line override plus unexport ---'
make -f - MOCKERY_VERSION=v3.7.0 <<'MAKE'
MOCKERY_VERSION ?= v3.7.0
unexport MOCKERY_VERSION
.PHONY: probe
probe:
	`@if` env | grep '^MOCKERY_VERSION='; then exit 1; else echo 'MOCKERY_VERSION not exported'; fi
MAKE

printf '%s\n' '--- GNU Make export behavior: environment override plus unexport ---'
MOCKERY_VERSION=v3.7.0 make -f - <<'MAKE'
MOCKERY_VERSION ?= v3.7.0
unexport MOCKERY_VERSION
.PHONY: probe
probe:
	`@if` env | grep '^MOCKERY_VERSION='; then exit 1; else echo 'MOCKERY_VERSION not exported'; fi
MAKE

Repository: NVIDIA/nodewright

Length of output: 3782


Keep MOCKERY_VERSION out of Mockery’s environment.

Mockery v3 maps this environment variable to its boolean version configuration. A version string causes Mockery to fail. Add unexport MOCKERY_VERSION after the assignment, or rename the Make variable.

Proposed fix
 MOCKERY_VERSION ?= v3.7.0
+unexport MOCKERY_VERSION
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
MOCKERY_VERSION ?= v3.7.0
MOCKERY_VERSION ?= v3.7.0
unexport MOCKERY_VERSION
🤖 Prompt for 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.

In `@agent/go/deps.mk` at line 23, Add `unexport MOCKERY_VERSION` immediately
after the `MOCKERY_VERSION` assignment in the Makefile, keeping the variable
available for Makefile expansion while preventing it from being passed to
Mockery’s environment.

ADDLICENSE_VERSION ?= v1.2.0

## Location to install dependencies to
Expand All @@ -29,10 +30,11 @@ $(LOCALBIN):

GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
GINKGO = $(LOCALBIN)/ginkgo
MOCKERY = $(LOCALBIN)/mockery
ADDLICENSE = $(LOCALBIN)/addlicense

.PHONY: install-deps
install-deps: golangci-lint ginkgo addlicense ## Install all dependencies.
install-deps: golangci-lint ginkgo mockery addlicense ## Install all dependencies.

.PHONY: golangci-lint
golangci-lint: $(LOCALBIN) ## Download golangci-lint locally if necessary.
Expand All @@ -47,6 +49,12 @@ ginkgo: $(LOCALBIN) ## Download ginkgo locally if necessary.
&& [ "$$($(GINKGO) version)" = "Ginkgo Version $(patsubst v%,%,$(GINKGO_VERSION))" ] \
|| GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)

.PHONY: mockery
mockery: $(LOCALBIN) ## Download Mockery locally if necessary.
@test -x $(MOCKERY) \
&& [ "$$($(MOCKERY) version)" = "$(MOCKERY_VERSION)" ] \
|| GOBIN=$(LOCALBIN) go install github.com/vektra/mockery/v3@$(MOCKERY_VERSION)

.PHONY: addlicense
addlicense: $(LOCALBIN) ## Download addlicense locally if necessary.
test -s $(ADDLICENSE) || GOBIN=$(LOCALBIN) go install github.com/google/addlicense@$(ADDLICENSE_VERSION)
5 changes: 5 additions & 0 deletions agent/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@ require (
github.com/onsi/ginkgo/v2 v2.32.0
github.com/onsi/gomega v1.42.1
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3
github.com/stretchr/testify v1.11.1
)

require (
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/pprof v0.0.0-20260402051712-545e8a4df936 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/mod v0.36.0 // indirect
golang.org/x/net v0.56.0 // indirect
golang.org/x/sync v0.21.0 // indirect
golang.org/x/sys v0.46.0 // indirect
golang.org/x/text v0.38.0 // indirect
golang.org/x/tools v0.45.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 4 additions & 2 deletions agent/go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28=
github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
Expand Down
112 changes: 112 additions & 0 deletions agent/go/internal/config/mock/SchemaValidator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions agent/go/internal/config/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

configmock "github.com/NVIDIA/nodewright/agent/internal/config/mock"
"github.com/NVIDIA/nodewright/agent/internal/schema"
"github.com/NVIDIA/nodewright/agent/internal/stage"
"github.com/NVIDIA/nodewright/agent/internal/step"
Expand Down Expand Up @@ -169,17 +170,14 @@ var _ = Describe("validateModes", func() {
var _ = Describe("Loader schema-validation seam", func() {
It("surfaces the injected validator's error without parsing the document", func() {
sentinel := errors.New("boom from fake validator")
loader := &Loader{validator: fakeValidator{err: sentinel}}
validator := configmock.NewMockSchemaValidator(GinkgoT())
validator.EXPECT().
Validate([]byte(validConfigJSON), schema.V1).
Return(sentinel).
Once()
loader := &Loader{validator: validator}

_, err := loader.Load([]byte(validConfigJSON), GinkgoT().TempDir(), nil)
Expect(err).To(MatchError(sentinel))
})
})

// fakeValidator is a SchemaValidator stand-in that returns a fixed result,
// proving Loader depends on the interface rather than the embedded schemas.
type fakeValidator struct {
err error
}

func (f fakeValidator) Validate(_ []byte, _ schema.SchemaVersion) error { return f.err }
Loading
Loading