ronantakizawa/codereview-bench huggingface dataset:
Repository: etcd-io/etcd
File: server/embed/config_test.go (Go)

Code before:
			getExperimentalFlagVal := func(flagName string) *bool {
				if flagName != "experimental-stop-grpc-service-on-defrag" || tc.experimentalStopGRPCServiceOnDefrag == "" {
					return nil
				}
				flagVal, parseErr := strconv.ParseBool(tc.experimentalStopGRPCServiceOnDefrag)
				if parseErr != nil {
					t.Fatal(parseErr)
				}
				return &flagVal
			}
			err = SetFeatureGatesFromExperimentalFlags(fg, getExperimentalFlagVal, tc.featureGatesFlag)
			if tc.expectErr {
				if err == nil {
					t.Fatal("expect error")
				}
				return
			}
			if err != nil {
				t.Fatal(err)
			}
			for k, v := range tc.expectedFeatures {
				if fg.Enabled(k) != v {
					t.Errorf("expected feature gate %s=%v, got %v", k, v, fg.Enabled(k))
				}
			}
		})
	}
}


Review comment (suggestion):
```suggestion			
			if tc.experimentalStopGRPCServiceOnDefrag != "" {
				// overwrite the value for `features.StopGRPCServiceOnDefrag`
				// based on flag `--experimental-stop-grpc-service-on-defrag`.
				getExperimentalFlagVal := func(flagName string) *bool {
					if flagName != "experimental-stop-grpc-service-on-defrag" {
						return nil
					}
					flagVal, parseErr := strconv.ParseBool(tc.experimentalStopGRPCServiceOnDefrag)
					require.NoError(t, parseErr)
					return &flagVal
				}

				err = SetFeatureGatesFromExperimentalFlags(fg, getExperimentalFlagVal, tc.featureGatesFlag)
				if tc.expectErr {
					require.True(t, err != nil, "expect error")
					return
				}
				require.NoError(t, err)
			}			
```

Code after:
				// experimental flag is not explicitly set
				getExperimentalFlagVal = func(flagName string) *bool {
					return nil
				}
			} else {
				// mexperimental flag is explicitly set
				getExperimentalFlagVal = func(flagName string) *bool {
					// only the experimental-stop-grpc-service-on-defrag flag can be set in this test.
					if flagName != "experimental-stop-grpc-service-on-defrag" {
						return nil
					}
					flagVal, parseErr := strconv.ParseBool(tc.experimentalStopGRPCServiceOnDefrag)
					require.NoError(t, parseErr)
					return &flagVal
				}
			}
			err = SetFeatureGatesFromExperimentalFlags(fg, getExperimentalFlagVal, tc.featureGatesFlag)
			if tc.expectErr {
				require.Error(t, err)
				return
			}
			require.NoError(t, err)
			for k, v := range tc.expectedFeatures {
				if fg.Enabled(k) != v {
					t.Errorf("expected feature gate %s=%v, got %v", k, v, fg.Enabled(k))
				}
			}
		})
	}
}
Repository: etcd-io/etcd
File: client/v3/kubernetes/client.go (Go)

Code before:
)

// New creates Client from config.
// Caller is responsible to call Close() to clean up client.
func New(cfg clientv3.Config) (*Client, error) {
	c, err := clientv3.New(cfg)
	if err != nil {
		return nil, err
	}
	kc := &Client{
		Client: c,
	}
	return kc, nil
}

type Client struct {
	*clientv3.Client
}

var _ Interface = (*Client)(nil)

func (k Client) Get(ctx context.Context, key string, opts GetOptions) (resp GetResponse, err error) {
	rangeResp, err := k.KV.Get(ctx, key, clientv3.WithRev(opts.Revision), clientv3.WithLimit(1))
	if err != nil {
		return resp, err
	}
	resp.Revision = rangeResp.Header.Revision
	if len(rangeResp.Kvs) == 1 {
		resp.KV = rangeResp.Kvs[0]
	}
	return resp, nil
}

func (k Client) List(ctx context.Context, prefix string, opts ListOptions) (resp ListResponse, err error) {
	rangeStart := prefix
	if opts.Continue != "" {
		rangeStart = opts.Continue + "\x00"
	}
	rangeEnd := clientv3.GetPrefixRangeEnd(prefix)
	rangeResp, err := k.KV.Get(ctx, rangeStart, clientv3.WithRange(rangeEnd), clientv3.WithLimit(opts.Limit), clientv3.WithRev(opts.Revision))
	if err != nil {
		return resp, err
	}
	resp.Kvs = rangeResp.Kvs
	resp.Count = rangeResp.Count
	resp.Revision = rangeResp.Header.Revision
	return resp, nil
}

func (k Client) Count(ctx context.Context, prefix string, _ CountOptions) (int64, error) {
	resp, err := k.KV.Get(ctx, prefix, clientv3.WithPrefix(), clientv3.WithCountOnly())

Review comment (suggestion):
minor comment, either way works, but `k.Get` is a little simpler. This comment applies to some other similar places as well. 
```suggestion
	rangeResp, err := k.Get(ctx, key, clientv3.WithRev(opts.Revision), clientv3.WithLimit(1))
```

Code after:
	clientv3 "go.etcd.io/etcd/client/v3"
)

// New creates Client from config.
// Caller is responsible to call Close() to clean up client.
func New(cfg clientv3.Config) (*Client, error) {
	c, err := clientv3.New(cfg)
	if err != nil {
		return nil, err
	}
	kc := &Client{
		Client: c,
	}
	kc.Kubernetes = kc
	return kc, nil
}

type Client struct {
	*clientv3.Client
	Kubernetes Interface
}

var _ Interface = (*Client)(nil)

func (k Client) Get(ctx context.Context, key string, opts GetOptions) (resp GetResponse, err error) {
	rangeResp, err := k.KV.Get(ctx, key, clientv3.WithRev(opts.Revision), clientv3.WithLimit(1))
	if err != nil {
		return resp, err
	}
	resp.Revision = rangeResp.Header.Revision
	if len(rangeResp.Kvs) == 1 {
		resp.KV = rangeResp.Kvs[0]
	}
	return resp, nil
}

func (k Client) List(ctx context.Context, prefix string, opts ListOptions) (resp ListResponse, err error) {
	rangeStart := prefix
	if opts.Continue != "" {
		rangeStart = opts.Continue
	}
	rangeEnd := clientv3.GetPrefixRangeEnd(prefix)
	rangeResp, err := k.KV.Get(ctx, rangeStart, clientv3.WithRange(rangeEnd), clientv3.WithLimit(opts.Limit), clientv3.WithRev(opts.Revision))
	if err != nil {
		return resp, err
	}
	resp.Kvs = rangeResp.Kvs
	resp.Count = rangeResp.Count
	resp.Revision = rangeResp.Header.Revision
	return resp, nil
}
Repository: etcd-io/etcd
File: tools/etcd-dump-db/page.go (Go)

Code before:

const pageHeaderSize = unsafe.Sizeof(page{})
const leafPageElementSize = unsafe.Sizeof(leafPageElement{})
const pageMaxAllocSize = 0xFFFFFFF

const (
	leafPageFlag = 0x02
)

type page struct {
	id       uint64
	flags    uint16
	count    uint16
	overflow uint32
}

func (p *page) isLeafPage() bool {
	return p.flags == leafPageFlag
}

func loadPage(buf []byte) *page {
	return (*page)(unsafe.Pointer(&buf[0]))
}

// LeafPageElement retrieves the leaf node by index
func (p *page) LeafPageElement(index uint16) *leafPageElement {
	return (*leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
		leafPageElementSize, int(index)))
}

// leafPageElement represents a node on a leaf page.
type leafPageElement struct {
	flags uint32
	pos   uint32
	ksize uint32
	vsize uint32
}

// Key returns a byte slice of the node key.
func (n *leafPageElement) key() []byte {
	i := int(n.pos)
	j := i + int(n.ksize)
	return unsafeByteSlice(unsafe.Pointer(n), 0, i, j)
}

// Value returns a byte slice of the node value.
func (n *leafPageElement) value() []byte {
	i := int(n.pos) + int(n.ksize)
	j := i + int(n.vsize)
	return unsafeByteSlice(unsafe.Pointer(n), 0, i, j)
}

Review comment (suggestion):
Suggestion to export the `leafPageElement` struct. Ref: #18370 / golang/lint#210

Code after:

const pageHeaderSize = unsafe.Sizeof(page{})
const leafPageElementSize = unsafe.Sizeof(leafPageElement{})
const pageMaxAllocSize = 0xFFFFFFF

const (
	leafPageFlag = 0x02
)

type page struct {
	id       uint64
	flags    uint16
	count    uint16
	overflow uint32
}

func (p *page) isLeafPage() bool {
	return p.flags == leafPageFlag
}

func loadPage(buf []byte) *page {
	return (*page)(unsafe.Pointer(&buf[0]))
}

// leafPageElement retrieves the leaf node by index
func (p *page) leafPageElement(index uint16) *leafPageElement {
	return (*leafPageElement)(unsafeIndex(unsafe.Pointer(p), unsafe.Sizeof(*p),
		leafPageElementSize, int(index)))
}

// leafPageElement represents a node on a leaf page.
type leafPageElement struct {
	flags uint32
	pos   uint32
	ksize uint32
	vsize uint32
}

// Key returns a byte slice of the node key.
func (n *leafPageElement) key() []byte {
	i := int(n.pos)
	j := i + int(n.ksize)
	return unsafeByteSlice(unsafe.Pointer(n), 0, i, j)
}

// Value returns a byte slice of the node value.
func (n *leafPageElement) value() []byte {
	i := int(n.pos) + int(n.ksize)
	j := i + int(n.vsize)
	return unsafeByteSlice(unsafe.Pointer(n), 0, i, j)
}
Repository: etcd-io/etcd
File: tools/etcd-dump-db/meta.go (Go)

Code before:
// Copyright 2024 The etcd Authors
//
// 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.

package main

import "unsafe"

const magic uint32 = 0xED0CDAED

type inBucket struct {
	root     uint64 // page id of the bucket's root-level page
	sequence uint64 // monotonically incrementing, used by NextSequence()
}

type Meta struct {
	magic    uint32
	version  uint32
	pageSize uint32
	flags    uint32
	root     inBucket
	freelist uint64
	pgid     uint64
	txid     uint64
	checksum uint64
}

func loadPageMeta(buf []byte) *Meta {
	return (*Meta)(unsafe.Pointer(&buf[pageHeaderSize]))
}


Review comment (suggestion):
Just an idea but in future could we pull some of these values from `bbolt` rather than duplicating them here? i.e. https://github.com/etcd-io/bbolt/blob/0cecda66e016f212c9d13aa74cfd93cb07948ff6/internal/common/meta.go#L12

Also https://github.com/etcd-io/bbolt/blob/0cecda66e016f212c9d13aa74cfd93cb07948ff6/internal/common/types.go#L16

Code after:
// Copyright 2024 The etcd Authors
//
// 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.

package main

import "unsafe"

const magic uint32 = 0xED0CDAED

type inBucket struct {
	root     uint64 // page id of the bucket's root-level page
	sequence uint64 // monotonically incrementing, used by NextSequence()
}

type meta struct {
	magic    uint32
	version  uint32
	pageSize uint32
	flags    uint32
	root     inBucket
	freelist uint64
	pgid     uint64
	txid     uint64
	checksum uint64
}

func loadPageMeta(buf []byte) *meta {
	return (*meta)(unsafe.Pointer(&buf[pageHeaderSize]))
}
Repository: etcd-io/etcd
File: tools/etcd-dump-db/scan.go (Go)

Code before:
// 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.

package main

import (
	"fmt"
	"io"
	"os"

	"go.etcd.io/etcd/server/v3/storage/mvcc"
)

func scanKeys(dbPath string, startRev int64) error {
	pgSize, hwm, err := readPageAndHWMSize(dbPath)
	if err != nil {
		return fmt.Errorf("failed to read page and HWM size: %w", err)
	}

	for pageID := uint64(2); pageID < hwm; {
		p, _, err := readPage(dbPath, pgSize, pageID)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Reading page %d failed: %v. Continuting...\n", pageID, err)
			pageID++
			continue
		}

		if !p.isLeafPage() {
			pageID++
			continue
		}

		for i := uint16(0); i < p.count; i++ {
			e := p.LeafPageElement(i)

			rev, err := bytesToBucketKey(e.key())
			if err != nil {
				if exceptionCheck(e.key()) {
					break
				}
				fmt.Fprintf(os.Stderr, "Decoding revision failed, pageID: %d, index: %d, key: %x, error: %v\n", pageID, i, string(e.key()), err)
				continue

Review comment (suggestion):
Nitpick: Is it intentional that some error messages start lowercase and some start uppercase?  Would be nice if we could be consistent where possible.

Code after:
// 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.

package main

import (
	"fmt"
	"io"
	"os"

	"go.etcd.io/etcd/server/v3/storage/mvcc"
)

func scanKeys(dbPath string, startRev int64) error {
	pgSize, hwm, err := readPageAndHWMSize(dbPath)
	if err != nil {
		return fmt.Errorf("failed to read page and HWM size: %w", err)
	}

	for pageID := uint64(2); pageID < hwm; {
		p, _, err := readPage(dbPath, pgSize, pageID)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Reading page %d failed: %v. Continuting...\n", pageID, err)
			pageID++
			continue
		}

		if !p.isLeafPage() {
			pageID++
			continue
		}

		for i := uint16(0); i < p.count; i++ {
			e := p.leafPageElement(i)

			rev, err := bytesToBucketKey(e.key())
			if err != nil {
				if exceptionCheck(e.key()) {
					break
				}
				fmt.Fprintf(os.Stderr, "Decoding revision failed, pageID: %d, index: %d, key: %x, error: %v\n", pageID, i, string(e.key()), err)
				continue
Repository: etcd-io/etcd
File: server/storage/wal/wal_test.go (Go)

Code before:
func TestCreateNewWALFile(t *testing.T) {
	tests := []struct {
		name     string
		fileType interface{}
		truncate bool
	}{
		{
			name:     "creating standard file should succeed",
			fileType: &os.File{},
		},
		{
			name:     "creating locked file should succeed",
			fileType: &fileutil.LockedFile{},
		},
		{
			name:     "creating standard file with truncate should succeed",
			fileType: &os.File{},
			truncate: true,
		},
		{
			name:     "creating locked file with truncate should succeed",
			fileType: &fileutil.LockedFile{},
			truncate: true,
		},
	}

	for i, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			p := filepath.Join(t.TempDir(), walName(0, uint64(i)))

			var err error
			var f interface{}

			switch tt.fileType.(type) {
			case *os.File:
				f, err = createNewWALFile[*os.File](p, tt.truncate)
				require.IsType(t, &os.File{}, f)
			case *fileutil.LockedFile:
				f, err = createNewWALFile[*fileutil.LockedFile](p, tt.truncate)
				require.IsType(t, &fileutil.LockedFile{}, f)
			}

			require.NoError(t, err)

			// Validate the file permissions
			fi, err := os.Stat(p)
			require.NoError(t, err)
			expectedPerms := fmt.Sprintf("%o", os.FileMode(fileutil.PrivateFileMode))
			actualPerms := fmt.Sprintf("%o", fi.Mode().Perm())
			require.Equal(t, expectedPerms, actualPerms, "unexpected file permissions on %q", p)
		})

Review comment (suggestion):
can you also add two cases to verify the following two cases?
- truncate:`true`, it should truncate the file content if present
- truncate: `false`: it shouldn't truncate the file content if present

Code after:
func TestCreateNewWALFile(t *testing.T) {
	tests := []struct {
		name     string
		fileType interface{}
		forceNew bool
	}{
		{
			name:     "creating standard file should succeed and not truncate file",
			fileType: &os.File{},
			forceNew: false,
		},
		{
			name:     "creating locked file should succeed and not truncate file",
			fileType: &fileutil.LockedFile{},
			forceNew: false,
		},
		{
			name:     "creating standard file with forceNew should truncate file",
			fileType: &os.File{},
			forceNew: true,
		},
		{
			name:     "creating locked file with forceNew should truncate file",
			fileType: &fileutil.LockedFile{},
			forceNew: true,
		},
	}

	for i, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			p := filepath.Join(t.TempDir(), walName(0, uint64(i)))

			// create initial file with some data to verify truncate behavior
			err := os.WriteFile(p, []byte("test data"), fileutil.PrivateFileMode)
			require.NoError(t, err)

			var f interface{}
			switch tt.fileType.(type) {
			case *os.File:
				f, err = createNewWALFile[*os.File](p, tt.forceNew)
				require.IsType(t, &os.File{}, f)
			case *fileutil.LockedFile:
				f, err = createNewWALFile[*fileutil.LockedFile](p, tt.forceNew)
				require.IsType(t, &fileutil.LockedFile{}, f)
			default:
				panic("unknown file type")
			}

			require.NoError(t, err)

			// validate the file permissions
Repository: etcd-io/etcd
File: server/storage/wal/wal.go (Go)

Code before:
		return nil
	}
	start := time.Now()
	if perr = fileutil.Fsync(pdir); perr != nil {
		dirCloser()
		lg.Warn(
			"failed to fsync the parent data directory file",
			zap.String("parent-dir-path", filepath.Dir(w.dir)),
			zap.String("dir-path", w.dir),
			zap.Error(perr),
		)
		return nil, perr
	}
	walFsyncSec.Observe(time.Since(start).Seconds())
	if err = dirCloser(); err != nil {
		return nil, err
	}

	return w, nil
}

// createNewWALFile creates a WAL file.
// To create a locked file, use *fileutil.LockedFile type parameter.
// To create a standard file, use *os.File type parameter.
// If truncate is true, the file will be truncated if it already exists.
func createNewWALFile[T *os.File | *fileutil.LockedFile](path string, truncate bool) (T, error) {
	flag := os.O_WRONLY | os.O_CREATE
	if truncate {
		flag |= os.O_TRUNC
	}

	if _, isLockedFile := any(T(nil)).(*fileutil.LockedFile); isLockedFile {
		lockedFile, err := fileutil.LockFile(path, flag, fileutil.PrivateFileMode)
		if err != nil {
			return nil, err
		}
		return any(lockedFile).(T), nil
	}

	file, err := os.OpenFile(path, flag, fileutil.PrivateFileMode)
	if err != nil {
		return nil, err
	}
	return any(file).(T), nil
}

func (w *WAL) Reopen(lg *zap.Logger, snap walpb.Snapshot) (*WAL, error) {
	err := w.Close()
	if err != nil {
		lg.Panic("failed to close WAL during reopen", zap.Error(err))
	}

Review comment (suggestion):
`truncate` is imperative name, while `forceNew` is declarative name.
```suggestion
func createNewWALFile[T *os.File | *fileutil.LockedFile](path string, forceNew bool) (T, error) {
```

Code after:
		return nil
	}
	start := time.Now()
	if perr = fileutil.Fsync(pdir); perr != nil {
		dirCloser()
		lg.Warn(
			"failed to fsync the parent data directory file",
			zap.String("parent-dir-path", filepath.Dir(w.dir)),
			zap.String("dir-path", w.dir),
			zap.Error(perr),
		)
		return nil, perr
	}
	walFsyncSec.Observe(time.Since(start).Seconds())
	if err = dirCloser(); err != nil {
		return nil, err
	}

	return w, nil
}

// createNewWALFile creates a WAL file.
// To create a locked file, use *fileutil.LockedFile type parameter.
// To create a standard file, use *os.File type parameter.
// If forceNew is true, the file will be truncated if it already exists.
func createNewWALFile[T *os.File | *fileutil.LockedFile](path string, forceNew bool) (T, error) {
	flag := os.O_WRONLY | os.O_CREATE
	if forceNew {
		flag |= os.O_TRUNC
	}

	if _, isLockedFile := any(T(nil)).(*fileutil.LockedFile); isLockedFile {
		lockedFile, err := fileutil.LockFile(path, flag, fileutil.PrivateFileMode)
		if err != nil {
			return nil, err
		}
		return any(lockedFile).(T), nil
	}

	file, err := os.OpenFile(path, flag, fileutil.PrivateFileMode)
	if err != nil {
		return nil, err
	}
	return any(file).(T), nil
}

func (w *WAL) Reopen(lg *zap.Logger, snap walpb.Snapshot) (*WAL, error) {
	err := w.Close()
	if err != nil {
		lg.Panic("failed to close WAL during reopen", zap.Error(err))
	}
Repository: etcd-io/etcd
File: scripts/update_dep.sh (Shell)

Code before:
#!/bin/bash 

# Usage:
#    ./scripts/update_dep.sh should_force_upgrade module version
# or ./scripts/update_dep.sh should_force_upgrade module
# e.g.
#   ./scripts/update_dep.sh false github.com/golang/groupcache
#   ./scripts/update_dep.sh false github.com/soheilhy/cmux v0.1.5
#
# Updates version of given dependency in all the modules that depend on the mod.

set -euo pipefail

source ./scripts/test_lib.sh

if [ "$#" -ne 3 ]; then
    echo "Illegal number of parameters"
    exit 1
fi

should_force_upgrade="$1"
mod="$2"
ver="$3"

function print_current_dep_version {
  echo "${mod} version in all go mod files"
  grep --exclude-dir=.git --include=\*.mod -Ri "${mod}" | grep -v sum
  printf "\n\n"
}

Review comment (suggestion):
Suggest not to introduce the additional parameter `should_force_upgrade` to keep the script as simple as possible. If we don't want to bump pure indirect dependency, then we shouldn't run this script at all.

Code after:
#!/usr/bin/env bash
# Copyright 2025 The etcd Authors
#
# 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.
#
# Usage:
#    ./scripts/update_dep.sh module version
# or ./scripts/update_dep.sh module (to update to the latest version)
# e.g.
#   ./scripts/update_dep.sh github.com/golang/groupcache
#   ./scripts/update_dep.sh github.com/soheilhy/cmux v0.1.5
#
# Updates version of given dependency in all the modules that depend on the mod.

set -euo pipefail

source ./scripts/test_lib.sh

if [ "$#" -lt 1 ] || [ "$#" -gt 2 ]; then
Repository: etcd-io/etcd
File: scripts/update_dep.sh (Shell)

Code before:
  run go mod edit -require "${mod}@${ver:-latest}" || true

  # Check if the module is a dependency.
  if go list -m all | grep -q -E "^\s*${mod}\s"; then
    if [ -z "${ver}" ]; then
      log_info "Updating ${mod} to latest version in $(module_subdir)..."
      run go get -u "${mod}"
    else
      log_info "Updating ${mod} to version ${ver} in $(module_subdir)..."
      run go get "${mod}@${ver}"
    fi
  fi

  make fix
}

print_current_dep_version
if is_fully_indirect; then
  read -p "Module ${mod} is a purely indirect dependency. Are you sure you want to update it? [y/N] " -r confirm
  [[ "${confirm,,}" == "y" ]] || exit # Default is No
fi

run_for_modules update_module

./scripts/fix.sh
PASSES="dep" ./scripts/test.sh

print_current_dep_version


Review comment (suggestion):
We should replace this with:

```suggestion
make fix verify-dep
```

Code after:
  # commands (like `go mod tidy`) will automatically move it back
  # to an indirect dependency, but at the designated updated version.
  #
  # Note: `go mod edit` requires a specific version (e.g., v1.2.3), so we only
  # use it when a version is explicitly provided. For "latest", we skip this
  # step and let `go get -u` handle it directly.
  if [ -n "${ver}" ]; then
    run go mod edit -require "${mod}@${ver}" || true
  fi

  # Check if the module is a dependency.
  if go list -m all | grep -q -E "^\s*${mod}\s"; then
    log_info "  Updating in ${subdir}..."
    if [ -z "${ver}" ]; then
      run go get -u "${mod}"
    else
      run go get "${mod}@${ver}"
    fi
  fi
}

print_current_dep_version
if is_fully_indirect; then
  read -p "Module ${mod} is a purely indirect dependency. Are you sure you want to update it? [y/N] " -r confirm
  [[ "$confirm" == [Yy] ]] || exit # Default is No
fi

log_info "Updating '${mod}' to ${ver:-latest} across all modules..."
run_for_modules update_module

make fix-mod-tidy fix-bom update-go-workspace verify-dep

print_current_dep_version