diff --git a/tools/flakeguard/go.mod b/tools/flakeguard/go.mod index e62e3d7b8..da37112a4 100644 --- a/tools/flakeguard/go.mod +++ b/tools/flakeguard/go.mod @@ -1,6 +1,6 @@ module github.com/smartcontractkit/chainlink-testing-framework/tools/flakeguard -go 1.24.3 +go 1.24.0 require ( github.com/andygrunwald/go-jira v1.16.0 diff --git a/tools/flakeguard/main.go b/tools/flakeguard/main.go index 28249af16..1a80ae91c 100644 --- a/tools/flakeguard/main.go +++ b/tools/flakeguard/main.go @@ -1,7 +1,6 @@ package main import ( - "io" "os" "time" @@ -29,14 +28,17 @@ func Execute() { } func init() { + zerolog.SetGlobalLevel(zerolog.DebugLevel) zerolog.TimeFieldFormat = time.RFC3339Nano - log.Logger = log.Output(zerolog.ConsoleWriter{ - Out: io.Discard, - TimeFormat: "15:04:05.00", // hh:mm:ss.ss format - }) + // log.Logger = log.Output(zerolog.ConsoleWriter{ + // Out: io.Discard, + // TimeFormat: "15:04:05.00", // hh:mm:ss.ss format + // }) zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + log.Info().Msg("FlakeGuard tool initialized - 0.0.1") + rootCmd.AddCommand(cmd.FindTestsCmd) rootCmd.AddCommand(cmd.RunTestsCmd) rootCmd.AddCommand(cmd.CheckTestOwnersCmd) diff --git a/tools/flakeguard/runner/executor/executor.go b/tools/flakeguard/runner/executor/executor.go index af7269cff..966c1cb45 100644 --- a/tools/flakeguard/runner/executor/executor.go +++ b/tools/flakeguard/runner/executor/executor.go @@ -4,6 +4,7 @@ import ( "bytes" "errors" "fmt" + "io" "os" "os/exec" "path/filepath" @@ -102,20 +103,20 @@ func (e *commandExecutor) RunTestPackage(cfg Config, packageName string, runInde var stderrBuf bytes.Buffer cmd.Stderr = &stderrBuf - stdoutBytes, err := cmd.Output() - - writeErr := os.WriteFile(tempFilePath, stdoutBytes, 0644) - if writeErr != nil { - log.Error().Err(writeErr).Str("file", tempFilePath).Msg("Failed to write captured stdout to temp file") - _ = os.Remove(tempFilePath) - return "", false, fmt.Errorf("failed to write command output to %s: %w", tempFilePath, writeErr) + // Open the temp file for writing + tmpFileWriter, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + return "", false, fmt.Errorf("failed to open temp file for writing: %w", err) } + defer tmpFileWriter.Close() - if err != nil { + // Write to both STDOUT and the file + cmd.Stdout = io.MultiWriter(os.Stdout, tmpFileWriter) + + if err := cmd.Run(); err != nil { if stderrStr := stderrBuf.String(); stderrStr != "" { log.Error().Str("package", packageName).Str("stderr", stderrStr).Msg("Command failed with error and stderr output") } - var exitErr *exec.ExitError if errors.As(err, &exitErr) { return tempFilePath, false, nil @@ -161,16 +162,17 @@ func (e *commandExecutor) RunCmd(cfg Config, testCmd []string, runIndex int) (te var stderrBuf bytes.Buffer cmd.Stderr = &stderrBuf - stdoutBytes, err := cmd.Output() - - writeErr := os.WriteFile(tempFilePath, stdoutBytes, 0644) - if writeErr != nil { - log.Error().Err(writeErr).Str("file", tempFilePath).Msg("Failed to write captured stdout to temp file (cmd run)") - _ = os.Remove(tempFilePath) - return "", false, fmt.Errorf("failed to write command output to %s: %w", tempFilePath, writeErr) + // Open the temp file for writing + tmpFileWriter, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_TRUNC, 0644) + if err != nil { + return "", false, fmt.Errorf("failed to open temp file for writing: %w", err) } + defer tmpFileWriter.Close() - if err != nil { + // Write to both STDOUT and the file + cmd.Stdout = io.MultiWriter(os.Stdout, tmpFileWriter) + + if err := cmd.Run(); err != nil { if stderrStr := stderrBuf.String(); stderrStr != "" { log.Error().Str("command", strings.Join(testCmd, " ")).Str("stderr", stderrStr).Msg("Custom command failed with error and stderr output") } diff --git a/tools/flakeguard/runner/parser/parser.go b/tools/flakeguard/runner/parser/parser.go index 2f4533272..c1bea8b91 100644 --- a/tools/flakeguard/runner/parser/parser.go +++ b/tools/flakeguard/runner/parser/parser.go @@ -291,13 +291,13 @@ func (p *defaultParser) processEvent(state *testProcessingState, rawEv rawEventD return } - if panicStarted := startPanicRe.MatchString(event.Output); panicStarted { + if startPanicRe.MatchString(event.Output) { state.panicDetectionMode = true state.detectedEntries = append(state.detectedEntries, rawEv) return } - if raceStarted := startRaceRe.MatchString(event.Output); raceStarted { + if startRaceRe.MatchString(event.Output) { state.raceDetectionMode = true state.detectedEntries = append(state.detectedEntries, rawEv) return