mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? (1) Generate JSON test summary, too (2) Tweak summary detail capture esp for `Await` ## Why? Allow AI agents to easily/quickly/cheaply inspect CI results. <img width="1582" height="707" alt="Screenshot 2026-05-25 at 6 46 13 PM" src="https://github.com/user-attachments/assets/ca232f52-4f6f-45cb-9b52-450d32999d0c" /> <img width="2158" height="254" alt="Screenshot 2026-05-25 at 6 47 03 PM" src="https://github.com/user-attachments/assets/447ccf28-bec7-424b-a961-630c44a02cb0" />
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
package await
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// reportAttemptErrors emits the collected attempt failures. When there are
|
|
// many, only the first and the last few are shown — long polls would
|
|
// otherwise produce hundreds of duplicate lines.
|
|
const (
|
|
reportHeadAttempts = 1
|
|
reportTailAttempts = 3
|
|
)
|
|
|
|
type attemptFailure struct {
|
|
attempt int
|
|
errors []string
|
|
}
|
|
|
|
// reportTimeout reports the timeout failure plus collected attempt errors.
|
|
func reportTimeout(tb testing.TB, failures []attemptFailure, funcName, timeoutMsg string, effectiveTimeout time.Duration, polls int) {
|
|
reportAttemptErrors(tb, failures)
|
|
if timeoutMsg != "" {
|
|
tb.Fatalf("%s: %s (not satisfied after %v, %d polls)", funcName, timeoutMsg, effectiveTimeout, polls)
|
|
} else {
|
|
tb.Fatalf("%s: condition not satisfied after %v (%d polls)", funcName, effectiveTimeout, polls)
|
|
}
|
|
}
|
|
|
|
func reportAttemptErrors(tb testing.TB, failures []attemptFailure) {
|
|
if len(failures) == 0 {
|
|
return
|
|
}
|
|
|
|
var b strings.Builder
|
|
b.WriteString("attempt errors:")
|
|
if len(failures) <= reportHeadAttempts+reportTailAttempts {
|
|
for _, f := range failures {
|
|
writeAttemptFailure(&b, f)
|
|
}
|
|
} else {
|
|
for _, f := range failures[:reportHeadAttempts] {
|
|
writeAttemptFailure(&b, f)
|
|
}
|
|
omitted := len(failures) - reportHeadAttempts - reportTailAttempts
|
|
fmt.Fprintf(&b, "\n ... %d attempts omitted ...", omitted)
|
|
for _, f := range failures[len(failures)-reportTailAttempts:] {
|
|
writeAttemptFailure(&b, f)
|
|
}
|
|
}
|
|
tb.Errorf("%s", b.String())
|
|
}
|
|
|
|
func writeAttemptFailure(b *strings.Builder, f attemptFailure) {
|
|
fmt.Fprintf(b, "\n\n --- attempt %d ---", f.attempt)
|
|
if len(f.errors) == 0 {
|
|
b.WriteString("\n (attempt failed without recorded assertion output)")
|
|
return
|
|
}
|
|
for _, e := range f.errors {
|
|
for line := range strings.SplitSeq(e, "\n") {
|
|
b.WriteString("\n ")
|
|
b.WriteString(line)
|
|
}
|
|
}
|
|
}
|