mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
feat(testrun): report violations as a typed error under exit-on-violation
This commit is contained in:
1 parent
39289f81df
commit
4d45c428f8
2 files changed
+67
-9
No files matched your search
@@ -1,12 +1,14 @@
|
||||
package testrun
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/priyanshujain/sanderling/internal/runner"
|
||||
"github.com/priyanshujain/sanderling/internal/verifier"
|
||||
)
|
||||
|
||||
@@ -231,3 +233,31 @@ func TestBuildRunMeta_OmitsModelWhenSpecDeclaresNoLLMGenerator(t *testing.T) {
|
||||
t.Errorf("model recorded without a spec-declared llm generator: %q", meta.Model)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRunOutcome_ReportsViolationsOnlyUnderTheFlag pins the CI contract: the
|
||||
// typed error is what makes `sanderling test` exit 2, and it must appear only
|
||||
// when the caller asked for it. A run that finds violations without the flag
|
||||
// stays a successful run, which is what every existing invocation expects.
|
||||
func TestRunOutcome_ReportsViolationsOnlyUnderTheFlag(t *testing.T) {
|
||||
violated := runner.Summary{
|
||||
Steps: 7,
|
||||
Violations: []runner.ViolationRecord{{StepIndex: 3, Properties: []string{"balanceMoves"}}},
|
||||
}
|
||||
clean := runner.Summary{Steps: 7}
|
||||
|
||||
if err := runOutcome(Options{}, violated); err != nil {
|
||||
t.Errorf("without --exit-on-violation a violated run must succeed, got %v", err)
|
||||
}
|
||||
if err := runOutcome(Options{ExitOnViolation: true}, clean); err != nil {
|
||||
t.Errorf("a clean run must succeed under --exit-on-violation, got %v", err)
|
||||
}
|
||||
|
||||
err := runOutcome(Options{ExitOnViolation: true}, violated)
|
||||
var violations ViolationsError
|
||||
if !errors.As(err, &violations) {
|
||||
t.Fatalf("expected a ViolationsError, got %v", err)
|
||||
}
|
||||
if violations.Count != 1 {
|
||||
t.Errorf("count: got %d, want 1", violations.Count)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user