Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
results and reports now match what Codex reports. Earlier versions
overcounted runs with cache hits, so a stored baseline from them can hide a
later increase in `compare`.
- Check every requested offline report format before writing any output files.
- Count primary cases consistently in Markdown and CLI summaries for benchmark
runs, without counting baseline rows as extra cases or discarding their details.
- Reject malformed `--include-case-name` and `--exclude-case-name` glob patterns
Expand Down
26 changes: 17 additions & 9 deletions internal/cli/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ func runReport(cmd *cobra.Command, args []string) error {
outputDir = filepath.Dir(resultPath)
}

type output struct {
format, path string
reporter report.Reporter
}
outputs := make([]output, 0, len(formats))
for _, format := range formats {
reporter, path, err := buildReportCommandReporter(format, outputDir)
if err != nil {
return err
}
outputs = append(outputs, output{format: format, path: path, reporter: reporter})
}

// Ensure the output directory exists.
if err := os.MkdirAll(outputDir, 0o755); err != nil {
return fmt.Errorf("create output directory %s: %w", outputDir, err)
Expand All @@ -69,17 +82,12 @@ func runReport(cmd *cobra.Command, args []string) error {
// 3. Generate reports
ctx := context.Background()

for _, format := range formats {
reporter, outputPath, err := buildReportCommandReporter(format, outputDir)
if err != nil {
return err
}

if err := reporter.Write(ctx, input); err != nil {
return fmt.Errorf("write %s report: %w", format, err)
for _, out := range outputs {
if err := out.reporter.Write(ctx, input); err != nil {
return fmt.Errorf("write %s report: %w", out.format, err)
}

_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Generated %s report: %s\n", format, outputPath)
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Generated %s report: %s\n", out.format, out.path)
}

// 4. Print summary
Expand Down
19 changes: 19 additions & 0 deletions internal/cli/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,25 @@ func TestRunReport_UnsupportedFormat(t *testing.T) {
}
}

func TestReportInvalidFormatLeavesEarlierReportIntact(t *testing.T) {
t.Parallel()
dir := t.TempDir()
input := writeResultJSON(t, dir, makeReportInput(judge.StatusPass))
path := filepath.Join(dir, "report.xml")
if err := os.WriteFile(path, []byte("previous report"), 0o600); err != nil {
t.Fatal(err)
}
cmd := newReportCmd()
cmd.SetArgs([]string{input, "--format", "junit", "--format", "csv"})
if err := cmd.Execute(); err == nil || !strings.Contains(err.Error(), "csv") {
t.Fatalf("report error = %v, want unsupported csv format", err)
}
got, err := os.ReadFile(path)
if err != nil || string(got) != "previous report" {
t.Fatalf("invalid format list replaced the existing report (read error %v)", err)
}
}

func TestRunReport_SummaryOutput(t *testing.T) {
t.Parallel()
dir := t.TempDir()
Expand Down
Loading