返回 DeepSeek-Reasonix
maintenance_history_test.go
根目录 / internal / control / maintenance_history_test.go
1 package control
2
3 import (
4 "fmt"
5 "path/filepath"
6 "strings"
7 "testing"
8 "time"
9
10 "reasonix/internal/agent"
11 "reasonix/internal/event"
12 "reasonix/internal/provider"
13 "reasonix/internal/sessioncontext"
14 )
15
16 func TestManualCompactHistoryReportsCompleted(t *testing.T) {
17 for _, window := range []int{0, 128_000} {
18 for _, slash := range []bool{false, true} {
19 t.Run(fmt.Sprintf("window=%d/slash=%v", window, slash), func(t *testing.T) {
20 prov := &recordingProvider{streams: [][]provider.Chunk{{
21 {Type: provider.ChunkText, Text: "- Completed implementation."},
22 {Type: provider.ChunkDone},
23 }}}
24 system := strings.Repeat("stable instructions ", 500)
25 sess := agent.NewSession(system)
26 sess.Add(agent.HostGeneratedUserMessage(sessioncontext.Build(sessioncontext.Sections{Workspace: strings.Repeat("workspace ", 500)}).Content))
27 sess.Add(provider.Message{Role: provider.RoleUser, Content: "Implement this task."})
28 sess.Add(provider.Message{Role: provider.RoleAssistant, Content: strings.Repeat("Implementation completed and verified. ", 50)})
29 exec := agent.New(prov, nil, sess, agent.Options{ContextWindow: window}, event.Discard)
30 dir := t.TempDir()
31 c := newOwnedTestController(t, Options{Executor: exec, SystemPrompt: system, SessionDir: dir, SessionPath: filepath.Join(dir, "session.jsonl"), Sink: event.Discard})
32 events := make(chan event.SessionOperationInfo, 8)
33 c.sink = event.FuncSink(func(e event.Event) {
34 if e.SessionOperation != nil {
35 events <- *e.SessionOperation
36 }
37 })
38 if slash {
39 if result := c.SubmitDisplayWithResult("/compact", "/compact"); result.Disposition != SubmitManagementHandled {
40 t.Fatalf("submit = %+v", result)
41 }
42 } else if err := c.Compact(t.Context(), ""); err != nil {
43 t.Fatal(err)
44 }
45 for _, status := range []string{"running", "finalizing", "completed"} {
46 select {
47 case e := <-events:
48 if e.Status != status {
49 t.Fatalf("operation = %+v, want %s", e, status)
50 }
51 if status == "completed" && (!e.Applied || e.Summary == "" || e.ResultTokens >= e.InputTokens) {
52 t.Fatalf("missing successful compaction receipt: %+v", e)
53 }
54 case <-time.After(5 * time.Second):
55 t.Fatalf("missing %s event", status)
56 }
57 }
58 })
59 }
60 }
61 }
62
62 lines GO