| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "reasonix/internal/agent" |
| 10 | "reasonix/internal/config" |
| 11 | "reasonix/internal/control" |
| 12 | "reasonix/internal/event" |
| 13 | "reasonix/internal/memory" |
| 14 | ) |
| 15 | |
| 16 | func TestSubmitToTabHistoryDisplaysRawInputAfterStandingMemoryCompose(t *testing.T) { |
| 17 | isolateDesktopUserDirs(t) |
| 18 | dir := config.SessionDir() |
| 19 | if err := os.MkdirAll(dir, 0o755); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | |
| 23 | path := filepath.Join(dir, "memory-display.jsonl") |
| 24 | mem := memory.Load(memory.Options{CWD: t.TempDir()}) |
| 25 | sess := agent.NewSession("sys") |
| 26 | exec := agent.New(nil, nil, sess, agent.Options{}, event.Discard) |
| 27 | runner := &appendingDesktopRunner{session: sess, started: make(chan string, 1)} |
| 28 | ctrl := control.New(control.Options{ |
| 29 | Runner: runner, Executor: exec, Sink: event.Discard, SessionDir: dir, |
| 30 | SessionPath: path, Label: "test", Memory: mem, |
| 31 | }) |
| 32 | defer ctrl.Close() |
| 33 | |
| 34 | app := NewApp() |
| 35 | app.setTestCtrl(ctrl, "deepseek/test") |
| 36 | if _, err := ctrl.QuickAdd(memory.ScopeProject, "contribution count updated"); err != nil { |
| 37 | t.Fatal(err) |
| 38 | } |
| 39 | |
| 40 | const prompt = "不要,删了" |
| 41 | app.SubmitToTab("test", prompt) |
| 42 | composed := <-runner.started |
| 43 | waitNotRunning(t, ctrl) |
| 44 | if !strings.Contains(composed, "<memory-update>") || !strings.HasSuffix(composed, prompt) { |
| 45 | t.Fatalf("model input should include memory update followed by prompt, got %q", composed) |
| 46 | } |
| 47 | got := app.HistoryForTab("test") |
| 48 | if len(got) < 2 || got[0].Role != "system" || got[1].Role != "user" { |
| 49 | t.Fatalf("history roles = %+v, want system then user", got[:min(len(got), 2)]) |
| 50 | } |
| 51 | if got[1].Content != prompt || strings.Contains(got[1].Content, "<memory-update>") { |
| 52 | t.Fatalf("displayed user content = %q, want raw prompt %q", got[1].Content, prompt) |
| 53 | } |
| 54 | } |
| 55 |