Skip to content

Commit 9b91339

Browse files
committed
Use configs
1 parent 2768edb commit 9b91339

File tree

3 files changed

+40
-43
lines changed

3 files changed

+40
-43
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,8 @@ var RunTestsCmd = &cobra.Command{
152152
skipTests,
153153
selectTests,
154154
// Parser specific config
155+
ignoreParentFailuresOnSubtests, // Pass parser config directly
155156
omitOutputsOnSuccess,
156-
passRatioThreshold, // Pass the calculated threshold
157-
ignoreParentFailuresOnSubtests,
158157
// Dependencies (pass nil to get defaults)
159158
nil, // exec
160159
nil, // parser

tools/flakeguard/runner/parser/parser.go

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (e entry) String() string {
6060
type Parser interface {
6161
// ParseFiles takes a list of raw output file paths, processes them (including potential transformation),
6262
// and returns the aggregated test results and the list of file paths that were actually parsed.
63-
ParseFiles(rawFilePaths []string, runPrefix string, expectedRuns int, ignoreParentFailures bool, omitSuccessOutputs bool) ([]reports.TestResult, []string, error)
63+
ParseFiles(rawFilePaths []string, runPrefix string, expectedRuns int, cfg Config) ([]reports.TestResult, []string, error)
6464
}
6565

6666
// Config holds configuration relevant to the parser.
@@ -85,20 +85,20 @@ func NewParser() Parser {
8585

8686
// ParseFiles is the main entry point for the parser.
8787
// It orchestrates transformation (if needed) and parsing of multiple files.
88-
func (p *defaultParser) ParseFiles(rawFilePaths []string, runPrefix string, expectedRuns int, ignoreParentFailures bool, omitSuccessOutputs bool) ([]reports.TestResult, []string, error) {
88+
func (p *defaultParser) ParseFiles(rawFilePaths []string, runPrefix string, expectedRuns int, cfg Config) ([]reports.TestResult, []string, error) {
8989
var parseFilePaths = rawFilePaths
9090

91-
// If the option is enabled, transform each JSON output file before parsing.
92-
if ignoreParentFailures {
91+
// Use cfg for transformation decision
92+
if cfg.IgnoreParentFailuresOnSubtests {
9393
err := p.transformTestOutputFiles(rawFilePaths)
9494
if err != nil {
9595
return nil, nil, fmt.Errorf("failed during output transformation: %w", err)
9696
}
9797
parseFilePaths = p.transformedOutputFiles
9898
}
9999

100-
// Now parse the selected files (raw or transformed)
101-
results, err := p.parseTestResults(parseFilePaths, runPrefix, expectedRuns, omitSuccessOutputs)
100+
// Pass cfg down to parseTestResults
101+
results, err := p.parseTestResults(parseFilePaths, runPrefix, expectedRuns, cfg)
102102
if err != nil {
103103
return nil, parseFilePaths, err // Return paths even on error?
104104
}
@@ -109,7 +109,7 @@ func (p *defaultParser) ParseFiles(rawFilePaths []string, runPrefix string, expe
109109
// parseTestResults reads the test output Go test json output files and returns processed TestResults.
110110
// This is the core logic moved from the original Runner.parseTestResults.
111111
// It now takes file paths directly.
112-
func (p *defaultParser) parseTestResults(parseFilePaths []string, runPrefix string, expectedRuns int, omitSuccessOutputs bool) ([]reports.TestResult, error) {
112+
func (p *defaultParser) parseTestResults(parseFilePaths []string, runPrefix string, expectedRuns int, cfg Config) ([]reports.TestResult, error) {
113113
var (
114114
testDetails = make(map[string]*reports.TestResult) // Holds run, pass counts, and other details for each test
115115
panickedPackages = map[string]struct{}{} // Packages with tests that panicked
@@ -185,10 +185,8 @@ func (p *defaultParser) parseTestResults(parseFilePaths []string, runPrefix stri
185185
if entryLine.Test != "" {
186186
// If it's a subtest, associate it with its parent for easier processing of panics later
187187
key := fmt.Sprintf("%s/%s", entryLine.Package, entryLine.Test)
188-
// Call the utility function (assuming it's accessible, might need import alias or move)
189-
// For now, assume it's callable directly if parser stays in runner package temporarily, or needs adjustment.
190-
// Let's assume we need to call a utility function `parseSubTest`.
191-
parentTestName, subTestName := parseSubTest(entryLine.Test) // This needs to resolve
188+
// Call the utility function (now internal to this package)
189+
parentTestName, subTestName := parseSubTest(entryLine.Test) // Use internal parseSubTest
192190
if subTestName != "" {
193191
parentTestKey := fmt.Sprintf("%s/%s", entryLine.Package, parentTestName)
194192
// Ensure slice exists before appending
@@ -554,7 +552,7 @@ func (p *defaultParser) parseTestResults(parseFilePaths []string, runPrefix stri
554552
result.PackageOutputs = outputs
555553
}
556554

557-
if omitSuccessOutputs {
555+
if cfg.OmitOutputsOnSuccess {
558556
result.PassedOutputs = make(map[string][]string)
559557
result.Outputs = make(map[string][]string)
560558
}
@@ -617,12 +615,8 @@ func (p *defaultParser) transformTestOutputFiles(filePaths []string) error {
617615
return nil
618616
}
619617

620-
// parseSubTest needs to be accessible here. It should be moved to a shared utility location
621-
// or this parser needs to be part of the runner package still.
622-
// Assuming it's moved to runner/utils.go and this file becomes part of the runner package
623-
// OR this file becomes parser package and imports runner (circular dependency risk) or utils.
624-
// Let's assume utils for now.
625-
// This function is currently duplicated - needs cleanup.
618+
// parseSubTest checks if a test name is a subtest and returns the parent and sub names.
619+
// Moved back into parser package and kept unexported.
626620
func parseSubTest(testName string) (parentTestName, subTestName string) {
627621
parts := strings.SplitN(testName, "/", 2)
628622
if len(parts) == 1 {

tools/flakeguard/runner/runner.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,16 @@ import (
1111
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/reports"
1212
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/runner/executor"
1313
"github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard/runner/parser"
14-
// No parser import needed if files are in the same package
1514
)
1615

1716
const (
1817
RawOutputDir = "./flakeguard_raw_output"
19-
// Removed RawOutputTransformedDir - belongs in parser.go
20-
)
21-
22-
var (
23-
// buildErr remains defined in the parser package
24-
// Consider defining shared errors in a common errors package if needed elsewhere
2518
)
2619

2720
// Runner describes the test run parameters and manages test execution and result parsing.
28-
// It now delegates command execution to an Executor and result parsing to a Parser.
21+
// It delegates command execution to an Executor and result parsing to a Parser.
2922
type Runner struct {
30-
// Configuration fields (consider grouping into a Config struct if it grows larger)
31-
// Keep only fields relevant to Runner's orchestration role or executor config
23+
// Configuration fields
3224
ProjectPath string
3325
Verbose bool
3426
RunCount int
@@ -42,10 +34,9 @@ type Runner struct {
4234
SkipTests []string
4335
SelectTests []string
4436

45-
// Configuration for the parser
46-
OmitOutputsOnSuccess bool
47-
MaxPassRatio float64 // TODO: Is this still used by Runner or belongs elsewhere?
37+
// Configuration passed down to the parser
4838
IgnoreParentFailuresOnSubtests bool
39+
OmitOutputsOnSuccess bool
4940

5041
// Dependencies
5142
exec executor.Executor // Injected Executor
@@ -68,10 +59,9 @@ func NewRunner(
6859
failFast bool,
6960
skipTests []string,
7061
selectTests []string,
71-
// Parser specific config
62+
// Parser specific config (passed during initialization)
63+
ignoreParentFailuresOnSubtests bool,
7264
omitOutputsOnSuccess bool,
73-
maxPassRatio float64, // Note: MaxPassRatio currently unused after refactor, belongs in reporting?
74-
ignoreParentFailuresOnSubtests bool, // Passed to parser
7565
// Dependencies (allow injection for testing)
7666
exec executor.Executor,
7767
p parser.Parser, // Use interface type directly
@@ -95,9 +85,8 @@ func NewRunner(
9585
FailFast: failFast,
9686
SkipTests: skipTests,
9787
SelectTests: selectTests,
98-
OmitOutputsOnSuccess: omitOutputsOnSuccess,
99-
MaxPassRatio: maxPassRatio,
10088
IgnoreParentFailuresOnSubtests: ignoreParentFailuresOnSubtests,
89+
OmitOutputsOnSuccess: omitOutputsOnSuccess,
10190
exec: exec,
10291
parser: p,
10392
}
@@ -120,6 +109,14 @@ func (r *Runner) getExecutorConfig() executor.Config {
120109
}
121110
}
122111

112+
// Helper function to create parser.Config from Runner fields
113+
func (r *Runner) getParserConfig() parser.Config {
114+
return parser.Config{
115+
IgnoreParentFailuresOnSubtests: r.IgnoreParentFailuresOnSubtests,
116+
OmitOutputsOnSuccess: r.OmitOutputsOnSuccess,
117+
}
118+
}
119+
123120
// RunTestPackages executes the tests for each provided package and aggregates all results.
124121
func (r *Runner) RunTestPackages(packages []string) ([]reports.TestResult, error) {
125122
rawOutputFiles := make([]string, 0) // Collect output file paths for this run
@@ -151,12 +148,12 @@ ParseResults:
151148
}
152149

153150
log.Info().Int("file_count", len(rawOutputFiles)).Msg("Parsing output files")
151+
// Create parser config and pass it
152+
parserCfg := r.getParserConfig()
154153
// Ignore the returned file paths here, as they aren't used in this flow
155-
results, _, err := r.parser.ParseFiles(rawOutputFiles, "run", len(rawOutputFiles), r.IgnoreParentFailuresOnSubtests, r.OmitOutputsOnSuccess)
154+
results, _, err := r.parser.ParseFiles(rawOutputFiles, "run", len(rawOutputFiles), parserCfg)
156155
if err != nil {
157156
// Check if it's a build error from the parser
158-
// Use errors.Is with the error defined in the parser package (or a shared error package)
159-
// Assuming parser.ErrBuild is exported:
160157
if errors.Is(err, parser.ErrBuild) { // Updated check
161158
// No extra wrapping needed if buildErr already provides enough context
162159
return nil, err
@@ -195,8 +192,10 @@ func (r *Runner) RunTestCmd(testCmd []string) ([]reports.TestResult, error) {
195192
}
196193

197194
log.Info().Int("file_count", len(rawOutputFiles)).Msg("Parsing output files from custom command")
195+
// Create parser config and pass it
196+
parserCfg := r.getParserConfig()
198197
// Ignore the returned file paths here as well
199-
results, _, err := r.parser.ParseFiles(rawOutputFiles, "run", len(rawOutputFiles), r.IgnoreParentFailuresOnSubtests, r.OmitOutputsOnSuccess)
198+
results, _, err := r.parser.ParseFiles(rawOutputFiles, "run", len(rawOutputFiles), parserCfg)
200199
if err != nil {
201200
if errors.Is(err, parser.ErrBuild) { // Updated check
202201
return nil, err
@@ -287,19 +286,24 @@ func (r *Runner) RerunFailedTests(failedTests []reports.TestResult, rerunCount i
287286
}
288287

289288
log.Info().Int("file_count", len(rerunOutputFiles)).Msg("Parsing rerun output files")
289+
// Create parser config and pass it
290+
parserCfg := r.getParserConfig()
290291
// For parsing reruns, the effective number of runs *per test included in the output* is `rerunCount`.
291292
// The parser's `expectedRuns` helps adjust for potential overcounting within each file, using `rerunCount` seems correct here.
292-
rerunResults, parsedFilePaths, err := r.parser.ParseFiles(rerunOutputFiles, "rerun", rerunCount, r.IgnoreParentFailuresOnSubtests, r.OmitOutputsOnSuccess)
293+
rerunResults, parsedFilePaths, err := r.parser.ParseFiles(rerunOutputFiles, "rerun", rerunCount, parserCfg)
293294
if err != nil {
294295
// Check for build error specifically?
295296
if errors.Is(err, parser.ErrBuild) { // Updated check
296297
log.Error().Err(err).Msg("Build error occurred unexpectedly during test reruns")
297298
// Fallthrough to return wrapped error
298299
}
300+
// Return the file paths even if parsing failed? No, the report wouldn't be useful.
299301
return nil, nil, fmt.Errorf("failed to parse rerun results: %w", err)
300302
}
301303

302304
// 5. Return Results
303305
log.Info().Int("result_count", len(rerunResults)).Msg("Finished parsing rerun results")
306+
// Return the parsed results AND the list of files parsed.
307+
// Note: The function signature needs to change back to return []string
304308
return rerunResults, parsedFilePaths, nil
305309
}

0 commit comments

Comments
 (0)