Files
Agent-Native/runtime/reminders/reminders_test.go
T
weichenandCursor 6fd1d441a9
ci / vet-and-test (pull_request) Successful in 45s
ci / docker-checkout-hostgateway (pull_request) Successful in 1s
Keep tool pairs and fold reminders into the last result
Why: Old tool results were filling the window, compaction could split a tool group or commit a stale summary, and reminders arrived as extra user messages.
Evidence: Compaction retries a conflict and opens the circuit after three failures; clearing keeps the last five tool results; a stale file write is rejected; RPC reports started, queued, or handled.
Impact: Requests over the context window replace older tool results with a placeholder. Rewriting an existing file now requires a read in the same run. Subagent text over 32000 characters is capped.
Refs: feature/context-engineering
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-03 16:19:36 +00:00

54 lines
1.7 KiB
Go

package reminders
import (
"strings"
"testing"
"time"
"agent-native/runtime/llm"
)
func TestAttachDoesNotAddUserAfterTool(t *testing.T) {
msgs := []llm.Message{
{Role: llm.RoleUser, Content: "请改文件"},
{Role: llm.RoleAssistant, ToolCalls: []llm.ToolCall{{ID: "c1", Name: "read_file"}}},
{Role: llm.RoleTool, Name: "read_file", ToolCallID: "c1", Content: "原文"},
}
out := Attach(msgs, []string{"计划和待办已过期"})
if len(out) != len(msgs) {
t.Fatalf("len %d, want %d", len(out), len(msgs))
}
for i := range msgs {
if out[i].Role != msgs[i].Role {
t.Fatalf("role changed at %d: %s", i, out[i].Role)
}
}
last := out[len(out)-1]
if last.Role != llm.RoleTool || !strings.Contains(last.Content, "原文") || !strings.Contains(last.Content, "system-reminder") {
t.Fatalf("reminder not folded into tool result: %+v", last)
}
if strings.Contains(out[0].Content, "system-reminder") {
t.Fatal("reminder leaked onto the earlier user message")
}
}
func TestAdmitThrottles(t *testing.T) {
bus := New(time.Minute, 2)
now := time.Now()
if !bus.Admit(Note{Kind: KindBudget, Key: "near", Text: "预算将尽"}, now) {
t.Fatal("first admit")
}
if bus.Admit(Note{Kind: KindBudget, Key: "near", Text: "预算将尽"}, now.Add(time.Second)) {
t.Fatal("duplicate key admitted")
}
if bus.Admit(Note{Kind: KindBackground, Key: "job", Text: "后台结束"}, now.Add(time.Second)) {
t.Fatal("inside min gap admitted")
}
if !bus.Admit(Note{Kind: KindBackground, Key: "job", Text: "后台结束"}, now.Add(time.Minute)) {
t.Fatal("after gap")
}
if bus.Admit(Note{Kind: KindDeliverable, Key: "doc", Text: "交付物待确认"}, now.Add(2*time.Minute)) {
t.Fatal("over cap")
}
}