diff --git a/cmd/waza/cmd_run.go b/cmd/waza/cmd_run.go index 8a6bf2922..33861d58c 100644 --- a/cmd/waza/cmd_run.go +++ b/cmd/waza/cmd_run.go @@ -182,6 +182,26 @@ func runCommandE(cmd *cobra.Command, args []string) error { if len(specPaths) == 1 { results, err := runCommandForSpec(cmd, specPaths[0]) + + // Only write outputs when the run produced meaningful results: + // either success (err == nil) or test failures (outcomes are still valid). + // For other errors (spec load/parse failures), skip writing and return early. + if err != nil { + if _, ok := errors.AsType[*TestFailureError](err); !ok { + return err + } + } + + // Write structured directory output when --output-dir is specified + if outputDir != "" { + if wErr := writeOutputDir(outputDir, []skillRunResult{ + {skillName: specPaths[0].skillName, outcomes: results}, + }); wErr != nil { + return fmt.Errorf("failed to write output directory: %w", wErr) + } + } + + // Auto-upload after all local writes succeed autoUploadOutcomes(cmd, cfg, results) return err } diff --git a/cmd/waza/cmd_run_test.go b/cmd/waza/cmd_run_test.go index f9ca5161a..77cbc1d94 100644 --- a/cmd/waza/cmd_run_test.go +++ b/cmd/waza/cmd_run_test.go @@ -1905,6 +1905,39 @@ func TestRunCommand_OutputDirMutualExclusion(t *testing.T) { assert.Contains(t, err.Error(), "--output and --output-dir are mutually exclusive") } +func TestRunCommand_OutputDirSingleSkill(t *testing.T) { + resetRunGlobals() + defer resetRunGlobals() + + specPath := createTestSpec(t, "mock") + outDir := filepath.Join(t.TempDir(), "results") + + cmd := newRunCommand() + cmd.SetArgs([]string{specPath, "--output-dir", outDir}) + + err := cmd.Execute() + require.NoError(t, err) + + // Verify output directory was created with a result JSON file + entries, err := os.ReadDir(outDir) + require.NoError(t, err) + require.NotEmpty(t, entries, "expected output files in --output-dir") + + // Find and validate the JSON result file + var found bool + for _, e := range entries { + if filepath.Ext(e.Name()) == ".json" { + data, err := os.ReadFile(filepath.Join(outDir, e.Name())) + require.NoError(t, err) + var outcome models.EvaluationOutcome + require.NoError(t, json.Unmarshal(data, &outcome)) + assert.Equal(t, "test-eval", outcome.BenchName) + found = true + } + } + assert.True(t, found, "expected at least one .json result in output dir") +} + func TestWriteOutputDir_SingleSkill(t *testing.T) { dir := t.TempDir()