ronantakizawa/codereview-bench huggingface dataset:
Repository: google/eleventy-high-performance-blog
File: _data/webvitals.js (JavaScript)

Code before:
/**
 * Copyright (c) 2020 Google Inc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

const metadata = require("./metadata.json");

module.exports = function () {
  // Check opt-in to send CWV metrics to GA.
  let sendWebVitals = metadata.sendWebVitals;

  // Check that web-vitals.js exists.
  let cwvLibraryExists = false;
  try {
    require("../js/web-vitals.js").getCLS;
    cwvLibraryExists = true;
  } catch (error) {
    console.error(error);
  }
 
  return cwvLibraryExists && sendWebVitals;
};


Review comment (suggestion):
I'd say that here we should just short-circuit (if `false` return `false`) and then return the try block below.

Code after:
/**
 * Copyright (c) 2020 Google Inc
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

const metadata = require("./metadata.json");

module.exports = function () {
  // Check opt-in to send CWV metrics to GA.
  return metadata.sendWebVitals;
};
Repository: google/eleventy-high-performance-blog
File: src/main.js (JavaScript)

Code before:
var timeout = setTimeout(
  (onload = function () {
    clearTimeout(timeout);
    ga("send", "pageview");
  }),
  1000
);

var ref = +new Date();
function ping(event) {
  var now = +new Date();
  if (now - ref < 1000) {
    return;
  }
  ga("send", {
    hitType: "event",
    eventCategory: "page",
    eventAction: event.type,
    eventLabel: Math.round((now - ref) / 1000),
  });
  ref = now;
}
addEventListener("pagehide", ping);
addEventListener("visibilitychange", ping);
addEventListener("DOMContentLoaded", function() {
  webVitals.getCLS(sendToGoogleAnalytics);
  webVitals.getFID(sendToGoogleAnalytics);
  webVitals.getLCP(sendToGoogleAnalytics);
});

addEventListener(
  "click",
  function (e) {
    var button = e.target.closest("button");
    if (!button) {
      return;
    }
    ga("send", {
      hitType: "event",
      eventCategory: "button",
      eventAction: button.getAttribute("aria-label") || button.textContent,
    });
  },
  true
);
var selectionTimeout;
addEventListener(
  "selectionchange",
  function () {
    clearTimeout(selectionTimeout);
    var text = String(document.getSelection()).trim();

Review comment (suggestion):
This could happen after `DOMContentLoaded` and then not fire. You can remove the event listener because the script element has `defer`

Code after:
var timeout = setTimeout(
  (onload = function () {
    clearTimeout(timeout);
    ga("send", "pageview");
  }),
  1000
);

var ref = +new Date();
function ping(event) {
  var now = +new Date();
  if (now - ref < 1000) {
    return;
  }
  ga("send", {
    hitType: "event",
    eventCategory: "page",
    eventAction: event.type,
    eventLabel: Math.round((now - ref) / 1000),
  });
  ref = now;
}
addEventListener("pagehide", ping);
addEventListener("visibilitychange", ping);

/**
 * Injects a script into document.head
 * @param {string} src path of script to be injected in <head>
 * @return {Promise} Promise object that resolves on script load event
 */
const dynamicScriptInject = (src) => {
  return new Promise((resolve) => {
    const script = document.createElement("script");
    script.src = src;
    script.type = "text/javascript";
    document.head.appendChild(script);
    script.addEventListener("load", () => {
      resolve(script);
    });
  });
};

// Script web-vitals.js will be injected dynamically if user opts-in to sending CWV data.
const sendWebVitals = document.currentScript.getAttribute("data-cwv-src");

if (/web-vitals.js/.test(sendWebVitals)) {
  dynamicScriptInject(`${window.location.origin}/js/web-vitals.js`)
  .then(() => {
    webVitals.getCLS(sendToGoogleAnalytics);
    webVitals.getFID(sendToGoogleAnalytics);
    webVitals.getLCP(sendToGoogleAnalytics);
Repository: google/gemma.cpp
File: util/app.h (C/C++)

Code before:
  }

 public:
  AppArgs(int argc, char* argv[]) {
    InitAndParse(argc, argv);
    ChooseNumThreads();
  }

  Path log;  // output
  int verbosity;
  size_t num_threads;

  template <class Visitor>
  void ForEach(const Visitor& visitor) {
    visitor(log, "log", Path{"/tmp/log.txt"}, "Logging file", 2);
    visitor(verbosity, "verbosity", 1,
            "Show verbose developer information\n   0 = only print generation "
            "output\n   1 = standard user-facing terminal ui\n   2 = show "
            "developer/debug info).\n   Default = 1.",
            2);
    visitor(num_threads, "num_threads",
            kDefaultNumThreads,  // see ChooseNumThreads
            "Number of threads to use. Default value is set based on an "
            "estimate of "
            "how many concurrent threads are supported.",
            2);
  }
};

}  // namespace gcpp

#endif  // THIRD_PARTY_GEMMA_CPP_UTIL_APP_H_


Review comment (suggestion):
@jan-wassenberg the way the CLI arg parsing works, are there certain characters that would be inexpressible (eg if you wanted some other whitespace like '\t' or ' '?

Another consideration to think about is, is end-of-prompt best specified as:
- a string?
- a character?
- a token ID?

I wonder if either a character or token ID might be preferable to string (and then '\n' becomes a special case), but open to having other perspectives chime in here. 

OTOH the nice thing about using a line string is that:
- it can easily be entered in interactively (not always the case for a rare token/character)
- if you need to allow for the entire vocabulary, you can effectively use a unique-by-design string as a quasi-out-of-vocabulary sentinel  token.

Code after:
 public:
  AppArgs(int argc, char* argv[]) {
    InitAndParse(argc, argv);
    ChooseNumThreads();
  }

  Path log;  // output
  int verbosity;
  size_t num_threads;
  std::string eot_line;

  template <class Visitor>
  void ForEach(const Visitor& visitor) {
    visitor(log, "log", Path{"/tmp/log.txt"}, "Logging file", 2);
    visitor(verbosity, "verbosity", 1,
            "Show verbose developer information\n   0 = only print generation "
            "output\n   1 = standard user-facing terminal ui\n   2 = show "
            "developer/debug info).\n   Default = 1.",
            2);
    visitor(num_threads, "num_threads",
            kDefaultNumThreads,  // see ChooseNumThreads
            "Number of threads to use. Default value is set based on an "
            "estimate of "
            "how many concurrent threads are supported.",
            2);
    visitor(eot_line, "eot_line", std::string(""),
            "End of turn line. "
            "When you specify this, the prompt will be all lines "
            "before the line where only the given string appears.",
            2);
  }
};

}  // namespace gcpp

#endif  // THIRD_PARTY_GEMMA_CPP_UTIL_APP_H_
Repository: google/gvisor
File: pkg/cpuid/native_amd64.go (Go)

Code before:
//go:nosplit
func (*Native) Query(in In) Out {
	if int(in.Eax) < len(allowedBasicFunctions) && allowedBasicFunctions[in.Eax] {
		return native(in)
	} else if in.Eax >= uint32(extendedStart) {
		if l := int(in.Eax - uint32(extendedStart)); l < len(allowedExtendedFunctions) && allowedExtendedFunctions[l] {
			return native(in)
		}
	}
	return Out{} // All zeros.
}

// query is a internal wrapper.
//
//go:nosplit
func (fs FeatureSet) query(fn cpuidFunction) (uint32, uint32, uint32, uint32) {
	out := fs.Query(In{Eax: fn.eax(), Ecx: fn.ecx()})
	return out.Eax, out.Ebx, out.Ecx, out.Edx
}

// Intersect returns the intersection of features between self and allowedFeatures.
func (fs FeatureSet) Intersect(allowedFeatures map[Feature]struct{}) (FeatureSet, error) {
	hs := fs.ToStatic()

	// only keep features inside allowedFeatures.
	if allowedFeatures != nil {
		for f, _ := range allFeatures {
			if fs.HasFeature(f) {
				if _, ok := allowedFeatures[f]; !ok {
					log.Infof("Removing CPU feature %v as it is not allowed.", f)
					hs.Remove(f)
				}
			}
		}
	}

	return hs.ToFeatureSet(), nil
}

var hostFeatureSet FeatureSet

// HostFeatureSet returns a host CPUID.
//
//go:nosplit
func HostFeatureSet() FeatureSet {
	return hostFeatureSet
}

var (
	// cpuFreqMHz is the native CPU frequency.
	cpuFreqMHz float64

Review comment (suggestion):
In Go, nil maps are treated as empty: https://go.dev/play/p/zWZvBuQFalt. So I think it would be better to *not* have this check, so that `fs.Intersect(nil)` returns a `FeatureSet` with all features removed, rather than returning `fs` which seems surprising.

Code after:
//go:nosplit
func (*Native) Query(in In) Out {
	if int(in.Eax) < len(allowedBasicFunctions) && allowedBasicFunctions[in.Eax] {
		return native(in)
	} else if in.Eax >= uint32(extendedStart) {
		if l := int(in.Eax - uint32(extendedStart)); l < len(allowedExtendedFunctions) && allowedExtendedFunctions[l] {
			return native(in)
		}
	}
	return Out{} // All zeros.
}

// query is a internal wrapper.
//
//go:nosplit
func (fs FeatureSet) query(fn cpuidFunction) (uint32, uint32, uint32, uint32) {
	out := fs.Query(In{Eax: fn.eax(), Ecx: fn.ecx()})
	return out.Eax, out.Ebx, out.Ecx, out.Edx
}

// Intersect returns the intersection of features between self and allowedFeatures.
func (fs FeatureSet) Intersect(allowedFeatures map[Feature]struct{}) (FeatureSet, error) {
	hs := fs.ToStatic()

	// only keep features inside allowedFeatures.
	for f, _ := range allFeatures {
		if fs.HasFeature(f) {
			if _, ok := allowedFeatures[f]; !ok {
				log.Infof("Removing CPU feature %v as it is not allowed.", f)
				hs.Remove(f)
			}
		}
	}

	return hs.ToFeatureSet(), nil
}

var hostFeatureSet FeatureSet

// HostFeatureSet returns a host CPUID.
//
//go:nosplit
func HostFeatureSet() FeatureSet {
	return hostFeatureSet
}

var (
	// cpuFreqMHz is the native CPU frequency.
	cpuFreqMHz float64
)
Repository: google/gvisor
File: runsc/boot/gofer_conf.go (Go)

Code before:
		return "lisafs"
	case Erofs:
		return erofs.Name
	}
	panic(fmt.Sprintf("Invalid gofer mount config lower layer type: %d", l))
}

// Set sets the value. Set(String()) should be idempotent.
func (l *GoferMountConfLowerType) Set(v string) error {
	switch v {
	case "none":
		*l = NoneLower
	case "lisafs":
		*l = Lisafs
	case erofs.Name:
		*l = Erofs
	default:
		return fmt.Errorf("invalid gofer mount config lower layer type: %s", v)
	}
	return nil
}

// GoferMountConf describes how a gofer mount is configured in the sandbox.
type GoferMountConf struct {
	Upper     GoferMountConfUpperType `json:"upper"`
	UpperSize string                  `json:"upperSize,omitempty"`
	Lower     GoferMountConfLowerType `json:"lower"`
}

// String returns a human-readable string representing the gofer mount config.
func (g GoferMountConf) String() string {
	return fmt.Sprintf("%s:%s:upperSize=%s", g.Lower, g.Upper, g.UpperSize)
}

// Set sets the value. Set(String()) should be idempotent.
func (g *GoferMountConf) Set(v string) error {
	parts := strings.Split(v, ":")
	if len(parts) != 3 {
		return fmt.Errorf("invalid gofer mount config format: %q", v)
	}
	if err := g.Lower.Set(parts[0]); err != nil {
		return err
	}
	if err := g.Upper.Set(parts[1]); err != nil {
		return err
	}
	if !g.valid() {
		return fmt.Errorf("invalid gofer mount config: %+v", g)
	}
	sizeArg := parts[2]
	size, cut := strings.CutPrefix(sizeArg, "upperSize=")

Review comment (suggestion):
Rename `UpperSize` -> `Size`. It doesn't make sense to apply the size to lower layer, since lower is an immutable layer so doesn't need size limits. The gofer mount's size limit will be defined by the upper layer only.

Code after:
		return "lisafs"
	case Erofs:
		return erofs.Name
	}
	panic(fmt.Sprintf("Invalid gofer mount config lower layer type: %d", l))
}

// Set sets the value. Set(String()) should be idempotent.
func (l *GoferMountConfLowerType) Set(v string) error {
	switch v {
	case "none":
		*l = NoneLower
	case "lisafs":
		*l = Lisafs
	case erofs.Name:
		*l = Erofs
	default:
		return fmt.Errorf("invalid gofer mount config lower layer type: %s", v)
	}
	return nil
}

// GoferMountConf describes how a gofer mount is configured in the sandbox.
type GoferMountConf struct {
	Lower GoferMountConfLowerType `json:"lower"`
	Upper GoferMountConfUpperType `json:"upper"`
	Size  string                  `json:"size,omitempty"`
}

// String returns a human-readable string representing the gofer mount config.
func (g GoferMountConf) String() string {
	res := fmt.Sprintf("%s:%s", g.Lower, g.Upper)
	if g.Size != "" {
		res += ":size=" + g.Size
	}
	return res
}

// Set sets the value. Set(String()) should be idempotent.
func (g *GoferMountConf) Set(v string) error {
	parts := strings.Split(v, ":")
	if len(parts) < 2 || len(parts) > 3 {
		return fmt.Errorf("invalid gofer mount config format: %q", v)
	}
	if err := g.Lower.Set(parts[0]); err != nil {
		return err
	}
	if err := g.Upper.Set(parts[1]); err != nil {
		return err
	}
	g.Size = ""
Repository: google/gvisor
File: runsc/boot/gofer_conf_test.go (Go)

Code before:
	}
}

func TestGoferConfFlags(t *testing.T) {
	want := GoferMountConfFlags{
		{Lower: NoneLower, Upper: MemoryOverlay},
		{Lower: NoneLower, Upper: SelfOverlay},
		{Lower: NoneLower, Upper: AnonOverlay},
		{Lower: Lisafs, Upper: NoOverlay},
		{Lower: Lisafs, Upper: MemoryOverlay},
		{Lower: Lisafs, Upper: SelfOverlay},
		{Lower: Lisafs, Upper: AnonOverlay},
		{Lower: Erofs, Upper: NoOverlay},
		{Lower: Erofs, Upper: MemoryOverlay},
		{Lower: Erofs, Upper: SelfOverlay},
		{Lower: Erofs, Upper: AnonOverlay},
	}
	var got GoferMountConfFlags
	got.Set(want.String())
	if len(got) != len(want) {
		t.Fatalf("gofer conf flags is incorrect length: want = %d, got = %d", len(want), len(got))
	}
	for i := range want {
		if want[i] != got[i] {
			t.Errorf("gofer conf is incorrect: want = %d, got = %d", want[i], got[i])
		}
	}
}

func TestGoferMountConfSetGet(t *testing.T) {
	t.Run("Without size", func(t *testing.T) {
		conf := GoferMountConf{}
		err := conf.Set("lisafs:anon")
		if err != nil {
			t.Fatalf("Expect success: %v", err)
		}
		s := conf.String()
		if s != "lisafs:anon" {
			t.Fatalf("Expected lisafs:anon, got %s", s)
		}
	})
	t.Run("With size", func(t *testing.T) {
		conf := GoferMountConf{}
		err := conf.Set("lisafs:anon:size=1719")
		if err != nil {
			t.Fatalf("Expect success: %v", err)
		}
		s := conf.String()
		if s != "lisafs:anon:size=1719" {
			t.Fatalf("Expected lisafs:anon:size=1719, got %s", s)
		}

Review comment (bug):
Please update line 174 to use `%s` instead of `%d`. It was incorrect before this change, but now that `GoferMountConf` has a string in it, it causes our nogo tool to complain.

Code after:
	}
}

func TestGoferConfFlags(t *testing.T) {
	want := GoferMountConfFlags{
		{Lower: NoneLower, Upper: MemoryOverlay},
		{Lower: NoneLower, Upper: SelfOverlay},
		{Lower: NoneLower, Upper: AnonOverlay},
		{Lower: Lisafs, Upper: NoOverlay},
		{Lower: Lisafs, Upper: MemoryOverlay},
		{Lower: Lisafs, Upper: SelfOverlay},
		{Lower: Lisafs, Upper: AnonOverlay},
		{Lower: Erofs, Upper: NoOverlay},
		{Lower: Erofs, Upper: MemoryOverlay},
		{Lower: Erofs, Upper: SelfOverlay},
		{Lower: Erofs, Upper: AnonOverlay},
	}
	var got GoferMountConfFlags
	got.Set(want.String())
	if len(got) != len(want) {
		t.Fatalf("gofer conf flags is incorrect length: want = %d, got = %d", len(want), len(got))
	}
	for i := range want {
		if want[i] != got[i] {
			t.Errorf("gofer conf is incorrect: want = %s, got = %s", want[i], got[i])
		}
	}
}

func TestGoferMountConfSetGet(t *testing.T) {
	t.Run("Without size", func(t *testing.T) {
		conf := GoferMountConf{}
		err := conf.Set("lisafs:anon")
		if err != nil {
			t.Fatalf("Expect success: %v", err)
		}
		s := conf.String()
		if s != "lisafs:anon" {
			t.Fatalf("Expected lisafs:anon, got %s", s)
		}
	})
	t.Run("With size", func(t *testing.T) {
		conf := GoferMountConf{}
		err := conf.Set("lisafs:anon:size=1719")
		if err != nil {
			t.Fatalf("Expect success: %v", err)
		}
		s := conf.String()
		if s != "lisafs:anon:size=1719" {
			t.Fatalf("Expected lisafs:anon:size=1719, got %s", s)
		}
Repository: google/gvisor
File: runsc/cmd/pidfile.go (Go)

Code before:
package cmd

import (
	"fmt"
	"os"
	"path/filepath"
	"strconv"
)

func fileExists(path string) bool {
	_, err := os.Stat(path)
	return !os.IsNotExist(err)
}

// WritePidFile writes pid file atomically if possible.
func WritePidFile(path string, pid int) error {
	pidStr := []byte(strconv.Itoa(pid))

	if fileExists(path) {
		// If path exists, write in place, because file could be pipe or something.
		if err := os.WriteFile(path, pidStr, 0644); err != nil {
			return fmt.Errorf("failed to write pid file %s: %w", path, err)
		}
	} else {
		// Otherwise write using temp file to make write atomic.
		dir := filepath.Dir(path)
		tempFile, err := os.CreateTemp(dir, "pid-tmp-*")
		if err != nil {
			return fmt.Errorf("failed to create temp pid file in dir %s: %w", dir, err)
		}

		tempFileRenamed := false
		defer func(tempFile *os.File) {
			_ = tempFile.Close()
			if !tempFileRenamed {
				_ = os.Remove(tempFile.Name())
			}
		}(tempFile)

Review comment (suggestion):
Seems lossy. What if you get a transport error, such as when `stat`ing a fuse filesystem? That would be seen as a "file exists" scenario.

I think you can just call `os.Stat` in `WritePidFile` and handle the three cases separately (`err == nil`, `err != nil && os.IsNotExist(err)`, `err != nil && !os.IsNotExist(err)`).

Code after:
// Copyright 2025 The gVisor 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 cmd

import (
	"fmt"
	"os"
	"path/filepath"
	"strconv"
)

// WritePidFile writes pid file atomically if possible.
func WritePidFile(path string, pid int) error {
	pidStr := []byte(strconv.Itoa(pid))

	st, err := os.Stat(path)
	if err == nil && !st.Mode().IsRegular() {
		// If not regular file, write in place.
		if err := os.WriteFile(path, pidStr, 0644); err != nil {
			return fmt.Errorf("failed to write pid file %s: %w", path, err)
		}
		return nil
	}
	if err != nil && !os.IsNotExist(err) {
		return fmt.Errorf("stat file %s failed: %w", path, err)
	}
Repository: google/gvisor
File: runsc/cmd/pidfile_test.go (Go)

Code before:

	path := filepath.Join(tempDir, "test.pid")
	if err := WritePidFile(path, 17); err != nil {
		t.Fatalf("failed to write pid file: %v", err)
	}

	pidStr, err := os.ReadFile(path)
	if err != nil {
		t.Fatalf("failed to read pid file: %v", err)
	}
	if string(pidStr) != "17" {
		t.Fatalf("pid file did not contain pid '17'")
	}

	// Overwrite existing file.

	if err := WritePidFile(path, 19); err != nil {
		t.Fatalf("failed to overwrite write pid file: %v", err)
	}
	pidStr, err = os.ReadFile(path)
	if err != nil {
		t.Fatalf("failed to read pid file: %v", err)
	}
	if string(pidStr) != "19" {
		t.Fatalf("pid file did not contain pid '19'")
	}
}


Review comment (suggestion):
Please wrap the two cases ("Write new file" and "Overwrite existing file") using two `t.Run` invocations.

Code after:
	"path/filepath"
	"testing"
)

func TestWritePidFile(t *testing.T) {
	tempDir, err := os.MkdirTemp("", "test-*")
	if err != nil {
		t.Fatalf("failed to create temp dir: %v", err)
	}
	defer func() {
		_ = os.RemoveAll(tempDir)
	}()

	t.Run("Write new file", func(t *testing.T) {
		path := filepath.Join(tempDir, "test-new.pid")
		if err := WritePidFile(path, 17); err != nil {
			t.Fatalf("failed to write pid file: %v", err)
		}

		pidStr, err := os.ReadFile(path)
		if err != nil {
			t.Fatalf("failed to read pid file: %v", err)
		}
		if string(pidStr) != "17" {
			t.Fatalf("pid file did not contain pid '17'")
		}
	})

	t.Run("Overwrite existing file", func(t *testing.T) {
		path := filepath.Join(tempDir, "test-overwrite.pid")
		if err := os.WriteFile(path, []byte("11"), 0600); err != nil {
			t.Fatalf("failed to write pid file: %v", err)
		}

		if err := WritePidFile(path, 19); err != nil {
			t.Fatalf("failed to overwrite write pid file: %v", err)
		}
		pidStr, err := os.ReadFile(path)
		if err != nil {
			t.Fatalf("failed to read pid file: %v", err)
		}
		if string(pidStr) != "19" {
			t.Fatalf("pid file did not contain pid '19'")
		}
	})
}