carlos / platform Public

console: the walk and session tests keep the console's log, leaving out only over-budget warnings

Both tests sent the whole log to a buffer nobody read, so an application
error behind a good status went unseen. The over-budget warnings the
injected latency causes are still dropped; every other line goes into
the test's output at the end, shown on a failure and with -v.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev f765166165cc9b0a07d50f5bcff39b84e06a7ae0 parent e42436c
1 file changed, +36 −8
  • internal/console/perfwalk_test.go +36 −8
diff --git a/internal/console/perfwalk_test.go b/internal/console/perfwalk_test.go
index c3ddb16bb..cb945dd4c 100644
--- a/internal/console/perfwalk_test.go
+++ b/internal/console/perfwalk_test.go
@@ -596,13 +596,44 @@ func ms(d time.Duration) string {
return strconv.FormatFloat(float64(d)/float64(time.Millisecond), 'f', 1, 64)
}
-func TestConsoleScreensMeetTheBudget(t *testing.T) {
- began := time.Now()
- // Over-budget pages log a warning; keep it out of the test's output.
+// perfOverBudgetLine marks the perf middleware's over-budget warning:
+// expected here, since the walk and the session run pages under injected
+// latency.
+const perfOverBudgetLine = "request over performance budget"
+
+// perfCaptureLogs sends the console's log output (the standard log
+// package, which slog.Default writes through) to a buffer for the rest of
+// the test, and returns the lines that are not over-budget warnings. At
+// the end of the test it puts those lines in the test's output, so an
+// application error logged behind a good status is seen on a failure
+// (and with -v) rather than discarded with the expected warnings.
+func perfCaptureLogs(t *testing.T) func() []string {
+ t.Helper()
logs := &syncBuffer{}
prev := log.Writer()
log.SetOutput(logs)
- t.Cleanup(func() { log.SetOutput(prev) })
+ unexpected := func() []string {
+ var out []string
+ for _, line := range strings.Split(logs.String(), "\n") {
+ if strings.TrimSpace(line) == "" || strings.Contains(line, perfOverBudgetLine) {
+ continue
+ }
+ out = append(out, line)
+ }
+ return out
+ }
+ t.Cleanup(func() {
+ log.SetOutput(prev)
+ if lines := unexpected(); len(lines) > 0 {
+ t.Logf("console log, over-budget warnings left out (%d lines):\n%s", len(lines), strings.Join(lines, "\n"))
+ }
+ })
+ return unexpected
+}
+
+func TestConsoleScreensMeetTheBudget(t *testing.T) {
+ began := time.Now()
+ perfCaptureLogs(t)
fx, lat := newPerfFixture(t)
recs := loadPerfBudgets(t)
@@ -771,10 +802,7 @@ func perfSessionCeiling(t *testing.T) (int64, string, bool) {
// to the ceiling in testdata/perf-session-s3.txt. Counts are
// deterministic, so this fails everywhere, not only in CI.
func TestPerfSessionS3Requests(t *testing.T) {
- logs := &syncBuffer{}
- prev := log.Writer()
- log.SetOutput(logs)
- t.Cleanup(func() { log.SetOutput(prev) })
+ perfCaptureLogs(t)
fx, lat := newPerfFixture(t)
c := signInPaul(t, fx)