From 8bdae0476421d07bed99e1c98ebb9d96b490c0f3 Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Tue, 6 Jan 2026 11:30:32 -0500 Subject: [PATCH 1/3] test: remove GetRepoRootPath --- graft/subnet-evm/tests/load/load_test.go | 30 ++++++++++++++----- .../fixture/bootstrapmonitor/e2e/e2e_test.go | 25 +++++++++++----- tests/fixture/e2e/helpers.go | 19 ------------ 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/graft/subnet-evm/tests/load/load_test.go b/graft/subnet-evm/tests/load/load_test.go index 08b980e54406..02e52bd9c79d 100644 --- a/graft/subnet-evm/tests/load/load_test.go +++ b/graft/subnet-evm/tests/load/load_test.go @@ -4,9 +4,11 @@ package load import ( + "flag" "fmt" "os" "os/exec" + "path/filepath" "strings" "testing" @@ -30,11 +32,20 @@ const ( subnetAName = "load-subnet-a" ) -var flagVars *e2e.FlagVars +var ( + flagVars *e2e.FlagVars + repoRootPath string +) func init() { // Configures flags used to configure tmpnet flagVars = e2e.RegisterFlags() + flag.StringVar( + &repoRootPath, + "repo-root", + "", + "absolute path to the repository root (required if scripts cannot be found via relative paths)", + ) } func TestE2E(t *testing.T) { @@ -45,16 +56,20 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() { require := require.New(ginkgo.GinkgoT()) var ( - env *e2e.TestEnvironment - repoRoot string + env *e2e.TestEnvironment + scriptPath string ) ginkgo.BeforeAll(func() { tc := e2e.NewTestContext() - var err error - repoRoot, err = e2e.GetRepoRootPath("tests/load") - require.NoError(err) + scriptPath = filepath.Join("..", "..", "..", "..", "scripts", "run_simulator.sh") + if _, err := os.Stat(scriptPath); err != nil { + if repoRootPath != "" { + scriptPath = filepath.Join(repoRootPath, "scripts", "run_simulator.sh") + } + require.NoError(err, "failed to locate run_simulator.sh - try specifying -repo-root flag") + } nodes := utils.NewTmpnetNodes(nodeCount) env = e2e.NewTestEnvironment( @@ -90,8 +105,7 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() { require.NoError(os.Setenv("RPC_ENDPOINTS", commaSeparatedRPCEndpoints)) log.Info("Running load simulator...", "rpcEndpoints", commaSeparatedRPCEndpoints) - cmd := exec.Command("./scripts/run_simulator.sh") - cmd.Dir = repoRoot + cmd := exec.Command(scriptPath) log.Info("Running load simulator script", "cmd", cmd.String()) out, err := cmd.CombinedOutput() diff --git a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go index 3cf76ede148f..8a86920183f1 100644 --- a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go +++ b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go @@ -41,11 +41,6 @@ func TestE2E(t *testing.T) { } const ( - // The relative path to the repo root enables discovery of the - // repo root when the test is executed from the root or the path - // of this file. - repoRelativePath = "tests/fixture/bootstrapmonitor/e2e" - avalanchegoImage = "localhost:5001/avalanchego" masterAvalanchegoImage = avalanchegoImage + ":master" monitorImage = "localhost:5001/bootstrap-monitor" @@ -65,6 +60,7 @@ var ( kubeconfigVars *flags.KubeconfigVars skipAvalanchegoImageBuild bool skipMonitorImageBuild bool + repoRootPath string nodeDataDir = bootstrapmonitor.NodeDataDir(dataDir) // Use a subdirectory of the data path so that os.RemoveAll can be used when starting a new test ) @@ -83,6 +79,12 @@ func init() { false, "whether to skip building the bootstrap-monitor image", ) + flag.StringVar( + &repoRootPath, + "repo-root", + "", + "absolute path to the repository root (required if scripts cannot be found via relative paths)", + ) } var _ = ginkgo.Describe("[Bootstrap Tester]", func() { @@ -238,12 +240,19 @@ func buildAvalanchegoImage(tc tests.TestContext, imageName string, forceNewHash func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scriptName string) { require := require.New(tc) - repoRoot, err := e2e.GetRepoRootPath(repoRelativePath) - require.NoError(err) + // Check for script via relative path from this test directory + scriptPath := filepath.Join("..", "..", "..", "..", "scripts", scriptName) + if _, err := os.Stat(scriptPath); err != nil { + // Fall back to the provided repo root flag + if repoRootPath != "" { + scriptPath = filepath.Join(repoRootPath, "scripts", scriptName) + } + require.NoError(err, "failed to locate %s - try specifying -repo-root flag", scriptName) + } args := []string{ "-x", // Ensure script output to aid in debugging - filepath.Join(repoRoot, "scripts", scriptName), + scriptPath, } if forceNewHash { // Ensure the build results in a new image hash by preventing use of a cached final stage diff --git a/tests/fixture/e2e/helpers.go b/tests/fixture/e2e/helpers.go index 4b8a475d2748..57e539f87022 100644 --- a/tests/fixture/e2e/helpers.go +++ b/tests/fixture/e2e/helpers.go @@ -357,22 +357,3 @@ func NewPChainFeeCalculatorFromContext(context *builder.Context) fee.Calculator } return fee.NewSimpleCalculator(0) } - -// GetRepoRootPath strips the provided suffix from the current working -// directory. If the test binary is executed from the root of the repo, the -// result will be the repo root. -func GetRepoRootPath(suffix string) (string, error) { - // - When executed via a test binary, the working directory will be wherever - // the binary is executed from, but scripts should require execution from - // the repo root. - // - // - When executed via ginkgo (nicer for development + supports - // parallel execution) the working directory will always be the - // target path (e.g. [repo root]./tests/bootstrap/e2e) and getting the repo - // root will require stripping the target path suffix. - cwd, err := os.Getwd() - if err != nil { - return "", err - } - return strings.TrimSuffix(cwd, suffix), nil -} From eee6e2836496aa686e1e2031983de923109252cf Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Tue, 6 Jan 2026 11:34:33 -0500 Subject: [PATCH 2/3] docs comments --- tests/fixture/bootstrapmonitor/e2e/e2e_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go index 8a86920183f1..9baa8660928f 100644 --- a/tests/fixture/bootstrapmonitor/e2e/e2e_test.go +++ b/tests/fixture/bootstrapmonitor/e2e/e2e_test.go @@ -240,10 +240,8 @@ func buildAvalanchegoImage(tc tests.TestContext, imageName string, forceNewHash func buildImage(tc tests.TestContext, imageName string, forceNewHash bool, scriptName string) { require := require.New(tc) - // Check for script via relative path from this test directory scriptPath := filepath.Join("..", "..", "..", "..", "scripts", scriptName) if _, err := os.Stat(scriptPath); err != nil { - // Fall back to the provided repo root flag if repoRootPath != "" { scriptPath = filepath.Join(repoRootPath, "scripts", scriptName) } From a9b6d0a3b9032532335cafc53b38326e2cbbcdce Mon Sep 17 00:00:00 2001 From: Jonathan Oppenheimer Date: Tue, 6 Jan 2026 11:46:12 -0500 Subject: [PATCH 3/3] fix: correct path --- graft/subnet-evm/tests/load/load_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graft/subnet-evm/tests/load/load_test.go b/graft/subnet-evm/tests/load/load_test.go index 02e52bd9c79d..4e99eb70f295 100644 --- a/graft/subnet-evm/tests/load/load_test.go +++ b/graft/subnet-evm/tests/load/load_test.go @@ -63,7 +63,7 @@ var _ = ginkgo.Describe("[Load Simulator]", ginkgo.Ordered, func() { ginkgo.BeforeAll(func() { tc := e2e.NewTestContext() - scriptPath = filepath.Join("..", "..", "..", "..", "scripts", "run_simulator.sh") + scriptPath = filepath.Join("..", "..", "scripts", "run_simulator.sh") if _, err := os.Stat(scriptPath); err != nil { if repoRootPath != "" { scriptPath = filepath.Join(repoRootPath, "scripts", "run_simulator.sh")