返回 DeepSeek-Reasonix
history_presentation_test.go
根目录 / internal / transcript / history_presentation_test.go
1 package transcript
2
3 import (
4 "strings"
5 "testing"
6
7 "reasonix/internal/event"
8 "reasonix/internal/provider"
9 )
10
11 func TestHistoryIdentityAndLegacyPresentation(t *testing.T) {
12 raw := "[Pasted text #1 · 2 lines]\n--- Begin [Pasted text #1 · 2 lines] ---\none\ntwo\n--- End [Pasted text #1 · 2 lines] ---"
13 messages := []provider.Message{{ID: "user", Role: provider.RoleUser, Origin: provider.MessageOriginUser, Content: raw, RawContent: raw},
14 {ID: "plan", Role: provider.RoleAssistant, Content: "plan and its final note", ToolCalls: []provider.ToolCall{{ID: "call", Name: "proxy", ResolvedName: "read_file", CapabilityID: "read", Arguments: "full args", Diff: "diff", Added: 1}}}}
15 rows := History(messages, HistoryOptions{SubmitContent: func(m provider.Message) string { return m.Content }, LegacyTurns: []LegacyDisplayTurn{{TurnID: "turn", UserMessageID: "user", Messages: []Message{{MessageID: "plan", Role: "assistant", Content: "plan"}}}}})
16 if len(rows) != 2 || rows[0].Content != "[Pasted text #1 · 2 lines]" || rows[0].SubmitText != raw {
17 t.Fatalf("legacy display/replay mismatch: %+v", rows)
18 }
19 if rows[1].RecordID != "m:plan" || rows[1].Content != "plan and its final note" {
20 t.Fatalf("identified planner duplicated: %+v", rows)
21 }
22 call := rows[1].ToolCalls[0]
23 if call.ResolvedName != "read_file" || call.CapabilityID != "read" || call.Arguments != "full args" || call.Diff != "diff" {
24 t.Fatalf("tool metadata lost: %+v", call)
25 }
26 }
27
28 func TestHistoryCancelledLegacySuppressesCanonicalLocalBody(t *testing.T) {
29 rows := History([]provider.Message{{ID: "u", Role: provider.RoleUser, Origin: provider.MessageOriginUser, Content: "q"},
30 {ID: "partial", Role: provider.RoleAssistant, LocalOnly: true, Content: "must not duplicate"},
31 {ID: "receipt", Role: provider.RoleAssistant, LocalOnly: true, DecisionReceipt: &provider.DecisionReceipt{ID: "decision"}}},
32 HistoryOptions{LegacyTurns: []LegacyDisplayTurn{{UserMessageID: "u", TurnID: "t", Messages: []Message{{Role: "assistant", Content: "partial display"}, {Role: "notice", Code: event.NoticeCodeCancelledTurn}}}}})
33 if len(rows) != 4 {
34 t.Fatalf("rows=%+v", rows)
35 }
36 for _, row := range rows {
37 if strings.Contains(row.Content, "must not duplicate") {
38 t.Fatal("canonical cancelled body duplicated")
39 }
40 }
41 if rows[3].DecisionReceipt == nil {
42 t.Fatal("independent receipt lost")
43 }
44 }
45
45 lines GO