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
4 changes: 2 additions & 2 deletions internal/classifier/classify.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func detectToolError(t *trace.Trace) *Classification {
for i, it := range t.Iterations {
if it.Phase == trace.PhaseError {
errorIters = append(errorIters, i+1)
}
if it.Verification != nil && it.Verification.Status == "fail" {
} else if it.Verification != nil && it.Verification.Status == "fail" {
// else-if: PhaseError + tool-ish verify fail must not record the same iter twice
output := strings.ToLower(it.Verification.Output)
if strings.Contains(output, "file not found") ||
strings.Contains(output, "permission denied") ||
Expand Down
69 changes: 69 additions & 0 deletions internal/classifier/classify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,72 @@ func TestNoClassification_HealthyTrace(t *testing.T) {
t.Errorf("expected 0 classifications for healthy trace, got %d: %v", len(results), results)
}
}

func TestDetectToolError_NoDuplicateIterations(t *testing.T) {
// Iteration with PhaseError AND a tool-ish verify fail used to be recorded twice
// (e.g. "Tool errors at iterations [3, 3, 5]").
tr := trace.New([]trace.Iteration{
{Number: 1, Phase: trace.PhaseAct},
{Number: 2, Phase: trace.PhaseAct},
{
Number: 3,
Phase: trace.PhaseError,
Verification: &trace.Verification{
Status: "fail",
Output: "Error: file not found: src/missing.ts",
},
},
{Number: 4, Phase: trace.PhaseAct},
{
Number: 5,
Phase: trace.PhaseError,
Verification: &trace.Verification{
Status: "fail",
Output: "permission denied",
},
},
})

results := Classify(tr)
var evidence string
found := false
for _, r := range results {
if r.Category == CatToolError {
found = true
evidence = r.Evidence
}
}
if !found {
t.Fatal("expected tool_error classification")
}
if evidence != "Tool errors at iterations [3 5], never recovered" {
t.Fatalf("expected deduped iterations [3 5], got evidence %q", evidence)
}
}

func TestDetectToolError_VerifyFailWithoutPhaseError(t *testing.T) {
tr := trace.New([]trace.Iteration{
{
Number: 1,
Phase: trace.PhaseVerify,
Verification: &trace.Verification{
Status: "fail",
Output: "command not found: foo",
},
},
})

results := Classify(tr)
found := false
for _, r := range results {
if r.Category == CatToolError {
found = true
if r.Evidence != "Tool errors at iterations [1], never recovered" {
t.Fatalf("unexpected evidence: %q", r.Evidence)
}
}
}
if !found {
t.Fatal("expected tool_error when verify fail has tool-ish output")
}
}