Files
harness/runtime/cap_test.go
sausheong 2d557bb7f5 feat(runtime): configurable per-tool-result truncation cap
Adds LoopConfig.MaxToolResultLen with the same config > env > default precedence as the existing MaxToolConcurrency / MaxAgentDepth knobs:

  1. Runtime.AgentLoop.MaxToolResultLen (>0) — config wins
  2. HARNESS_MAX_TOOL_RESULT_LEN env (>0) — env fallback
  3. defaultMaxToolResultLen (4000) — unchanged for back-compat

The previous 4000-char cap was conservative for agents doing real engineering work (read_file, web_fetch, browser, bash output). Setting MaxToolResultLen to 16000-25000 lets a typical source file or test run land in-context without hitting spillover; spill remains the safety net for genuinely large outputs.

No behaviour change for callers that don't set the field.
2026-05-21 07:55:16 +08:00

51 lines
1.5 KiB
Go

package runtime
import (
"testing"
)
// TestMaxToolResultLen_Precedence locks in the config > env > default
// precedence so a regression here doesn't silently swap one source for
// another.
func TestMaxToolResultLen_Precedence(t *testing.T) {
t.Run("default when nothing set", func(t *testing.T) {
t.Setenv("HARNESS_MAX_TOOL_RESULT_LEN", "")
r := &Runtime{}
if got := r.maxToolResultLen(); got != defaultMaxToolResultLen {
t.Fatalf("want %d, got %d", defaultMaxToolResultLen, got)
}
})
t.Run("env overrides default", func(t *testing.T) {
t.Setenv("HARNESS_MAX_TOOL_RESULT_LEN", "12345")
r := &Runtime{}
if got := r.maxToolResultLen(); got != 12345 {
t.Fatalf("want 12345, got %d", got)
}
})
t.Run("config overrides env", func(t *testing.T) {
t.Setenv("HARNESS_MAX_TOOL_RESULT_LEN", "12345")
r := &Runtime{AgentLoop: LoopConfig{MaxToolResultLen: 25000}}
if got := r.maxToolResultLen(); got != 25000 {
t.Fatalf("want 25000, got %d", got)
}
})
t.Run("zero env is ignored", func(t *testing.T) {
t.Setenv("HARNESS_MAX_TOOL_RESULT_LEN", "0")
r := &Runtime{}
if got := r.maxToolResultLen(); got != defaultMaxToolResultLen {
t.Fatalf("want %d, got %d", defaultMaxToolResultLen, got)
}
})
t.Run("garbage env is ignored", func(t *testing.T) {
t.Setenv("HARNESS_MAX_TOOL_RESULT_LEN", "not-a-number")
r := &Runtime{}
if got := r.maxToolResultLen(); got != defaultMaxToolResultLen {
t.Fatalf("want %d, got %d", defaultMaxToolResultLen, got)
}
})
}