Files
Agent-System-Backend/internal/runtime/context_window_test.go
weichen 43297795f5
ci / vet-and-test (pull_request) Successful in 48s
Keep original materials and cleared results reachable across turns
Why: Real-run before/after evidence (phase01 card) showed later turns never
re-read the uploaded source (0 original reads in plan-followup) because the
attachment only existed in the current turn's injection and the context window
hard default was 32000 chars - a 25k-char transcript tripped the clear-on-first
request, replacing old tool results with a pointer the model has no tool to
follow. MiniMax is an interleaved-thinking model whose docs require <think>
blocks in assistant history; dropping them degrades later turns.

Evidence: SELF - new tests TestThinkReplayWrapsAssistantHistory,
TestContextWindowScalesFromTokens, TestThinkReplayEnabled,
TestPersistInputTextsAndListWorkspaceInputs; go test ./internal/... passes;
live before/after comparison on the golden task set recorded on the phase02
task card per the new policy clause.

Impact: models.chat.contextWindow/outputReserve/contextBuffer (tokens,
defaults 128k/16k/4k) drive the in-run clear threshold, converted to chars;
cleared tool results spill to <sandbox>/.agent/results with readable paths;
attachment parse text persists as inputs/<name>.md and the env section lists
all workspace inputs every turn; context.thinkReplay (auto|on|off, auto =
MiniMax) replays thinking blocks into request-side assistant history only.
2026-10-09 14:28:39 +00:00

52 lines
1.5 KiB
Go

package runtime
import (
"strings"
"testing"
core "agent-system-core"
)
// 窗口按 token 配置并换算为字符阈值;此前 32000 字符硬默认会让长材料任务
// 在第一个请求就触发清理(被清内容只留「见会话记录」,模型无法取回)。
func TestContextWindowScalesFromTokens(t *testing.T) {
eff := core.EffectiveSettings{"models": map[string]any{"chat": map[string]any{
"contextWindow": float64(128000),
"outputReserve": float64(16384),
"contextBuffer": float64(4096),
}}}
w, r, b := contextWindow(eff)
if w != int(128000*3.35) {
t.Fatalf("window = %d, want %d", w, int(128000*3.35))
}
if r <= 0 || b <= 0 {
t.Fatalf("reserve/buffer must be positive chars: %d %d", r, b)
}
// 旧部署未配置时的默认:不再是 32k 字符。
def, _, _ := contextWindow(core.EffectiveSettings{})
if def < 100000*3 {
t.Fatalf("default window too small: %d", def)
}
}
func TestThinkReplayEnabled(t *testing.T) {
eff := func(v string) core.EffectiveSettings {
return core.EffectiveSettings{"context": map[string]any{"thinkReplay": v}}
}
if !thinkReplayEnabled(eff(""), "MiniMax-M2.7-highspeed") {
t.Fatal("auto should enable for minimax models")
}
if thinkReplayEnabled(eff(""), "gpt-5.1") {
t.Fatal("auto should stay off for other models")
}
if !thinkReplayEnabled(eff("on"), "gpt-5.1") {
t.Fatal("explicit on must win")
}
if thinkReplayEnabled(eff("off"), "MiniMax-M2.7-highspeed") {
t.Fatal("explicit off must win")
}
if !strings.Contains("checkpoint", "checkpoint") {
t.Fatal("sanity")
}
}