From 8f00e57c02ce1cf242c9c66ea8bbc8047a3f8011 Mon Sep 17 00:00:00 2001 From: AlexanderGomes Date: Fri, 22 Aug 2025 13:01:11 -0700 Subject: [PATCH 1/2] Closes #52 --- cli/helpers.go | 10 ++++++++-- engine/benchmark/api.go | 22 +++++++++++++++++----- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/cli/helpers.go b/cli/helpers.go index d5c06d3..2ce9a46 100644 --- a/cli/helpers.go +++ b/cli/helpers.go @@ -465,13 +465,19 @@ func discoverAvailableProfiles(tag, benchmarkName string) ([]string, error) { } func runTUI(_ *cobra.Command, _ []string) error { - benchNames, err := benchmark.DiscoverBenchmarks() + // Get current working directory for scope-aware benchmark discovery + currentDir, err := os.Getwd() + if err != nil { + return fmt.Errorf("failed to get current working directory: %w", err) + } + + benchNames, err := benchmark.DiscoverBenchmarks(currentDir) if err != nil { return fmt.Errorf("failed to discover benchmarks: %w", err) } if len(benchNames) == 0 { - return errors.New("no benchmarks found in this module (look for func BenchmarkXxx(b *testing.B) in *_test.go)") + return errors.New("no benchmarks found in this directory or its subdirectories (look for func BenchmarkXxx(b *testing.B) in *_test.go)") } var selectedBenches []string diff --git a/engine/benchmark/api.go b/engine/benchmark/api.go index 685b837..f52a3b2 100644 --- a/engine/benchmark/api.go +++ b/engine/benchmark/api.go @@ -48,11 +48,23 @@ func RunBenchmarks(benchmarks, profiles []string, tag string, count int) error { // A benchmark is identified by functions matching: // // func BenchmarkXxx(b *testing.B) { ... } -func DiscoverBenchmarks() ([]string, error) { - root, err := internal.FindGoModuleRoot() - if err != nil { - return nil, fmt.Errorf("failed to locate module root: %w", err) +// +// If scope is provided, only searches within that directory and its subdirectories. +// If scope is empty, searches the entire module from the root. +func DiscoverBenchmarks(scope string) ([]string, error) { + var searchRoot string + var err error + + if scope != "" { + // Use the provided scope directory + searchRoot = scope + } else { + // Fall back to searching from module root + searchRoot, err = internal.FindGoModuleRoot() + if err != nil { + return nil, fmt.Errorf("failed to locate module root: %w", err) + } } - return scanForBenchmarks(root) + return scanForBenchmarks(searchRoot) } From c46589261e5480086551af0b7cfb58dbde92fc66 Mon Sep 17 00:00:00 2001 From: AlexanderGomes Date: Fri, 22 Aug 2025 13:03:08 -0700 Subject: [PATCH 2/2] fixed: linter errors --- engine/benchmark/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/benchmark/api.go b/engine/benchmark/api.go index f52a3b2..051d4c6 100644 --- a/engine/benchmark/api.go +++ b/engine/benchmark/api.go @@ -54,7 +54,7 @@ func RunBenchmarks(benchmarks, profiles []string, tag string, count int) error { func DiscoverBenchmarks(scope string) ([]string, error) { var searchRoot string var err error - + if scope != "" { // Use the provided scope directory searchRoot = scope