Skip to content

Commit 51d6638

Browse files
authored
Fix --output-dir having no effect for single-skill runs (#109)
1 parent 445c89f commit 51d6638

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

cmd/waza/cmd_run.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,26 @@ func runCommandE(cmd *cobra.Command, args []string) error {
182182

183183
if len(specPaths) == 1 {
184184
results, err := runCommandForSpec(cmd, specPaths[0])
185+
186+
// Only write outputs when the run produced meaningful results:
187+
// either success (err == nil) or test failures (outcomes are still valid).
188+
// For other errors (spec load/parse failures), skip writing and return early.
189+
if err != nil {
190+
if _, ok := errors.AsType[*TestFailureError](err); !ok {
191+
return err
192+
}
193+
}
194+
195+
// Write structured directory output when --output-dir is specified
196+
if outputDir != "" {
197+
if wErr := writeOutputDir(outputDir, []skillRunResult{
198+
{skillName: specPaths[0].skillName, outcomes: results},
199+
}); wErr != nil {
200+
return fmt.Errorf("failed to write output directory: %w", wErr)
201+
}
202+
}
203+
204+
// Auto-upload after all local writes succeed
185205
autoUploadOutcomes(cmd, cfg, results)
186206
return err
187207
}

cmd/waza/cmd_run_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,39 @@ func TestRunCommand_OutputDirMutualExclusion(t *testing.T) {
19051905
assert.Contains(t, err.Error(), "--output and --output-dir are mutually exclusive")
19061906
}
19071907

1908+
func TestRunCommand_OutputDirSingleSkill(t *testing.T) {
1909+
resetRunGlobals()
1910+
defer resetRunGlobals()
1911+
1912+
specPath := createTestSpec(t, "mock")
1913+
outDir := filepath.Join(t.TempDir(), "results")
1914+
1915+
cmd := newRunCommand()
1916+
cmd.SetArgs([]string{specPath, "--output-dir", outDir})
1917+
1918+
err := cmd.Execute()
1919+
require.NoError(t, err)
1920+
1921+
// Verify output directory was created with a result JSON file
1922+
entries, err := os.ReadDir(outDir)
1923+
require.NoError(t, err)
1924+
require.NotEmpty(t, entries, "expected output files in --output-dir")
1925+
1926+
// Find and validate the JSON result file
1927+
var found bool
1928+
for _, e := range entries {
1929+
if filepath.Ext(e.Name()) == ".json" {
1930+
data, err := os.ReadFile(filepath.Join(outDir, e.Name()))
1931+
require.NoError(t, err)
1932+
var outcome models.EvaluationOutcome
1933+
require.NoError(t, json.Unmarshal(data, &outcome))
1934+
assert.Equal(t, "test-eval", outcome.BenchName)
1935+
found = true
1936+
}
1937+
}
1938+
assert.True(t, found, "expected at least one .json result in output dir")
1939+
}
1940+
19081941
func TestWriteOutputDir_SingleSkill(t *testing.T) {
19091942
dir := t.TempDir()
19101943

0 commit comments

Comments
 (0)