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>
41 lines
984 B
Go
41 lines
984 B
Go
package filestate
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestCheckWriteRejectsStaleFile(t *testing.T) {
|
|
dir := t.TempDir()
|
|
path := filepath.Join(dir, "note.txt")
|
|
if err := os.WriteFile(path, []byte("v1"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
tr := New()
|
|
if err := tr.CheckWrite(path); err == nil || !strings.Contains(err.Error(), "请先读取") {
|
|
t.Fatalf("unread write: %v", err)
|
|
}
|
|
if err := tr.NoteRead(path); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := tr.CheckWrite(path); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// 改大小,并尽量推开修改时间。
|
|
time.Sleep(20 * time.Millisecond)
|
|
if err := os.WriteFile(path, []byte("v1-changed"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err := tr.CheckWrite(path)
|
|
if err == nil || !strings.Contains(err.Error(), "请重新读取") {
|
|
t.Fatalf("stale write: %v", err)
|
|
}
|
|
missing := filepath.Join(dir, "new.txt")
|
|
if err := tr.CheckWrite(missing); err != nil {
|
|
t.Fatalf("create: %v", err)
|
|
}
|
|
}
|