返回 DeepSeek-Reasonix
session_markdown_export_test.go
根目录 / desktop / session_markdown_export_test.go
1 package main
2
3 import (
4 "bytes"
5 "errors"
6 "io"
7 "os"
8 "path/filepath"
9 "strings"
10 "testing"
11
12 "reasonix/internal/transcript"
13 )
14
15 func TestWriteSessionMarkdownStreamsCompleteRecords(t *testing.T) {
16 var out bytes.Buffer
17 messages := []HistoryMessage{
18 {Role: "user", Content: "question"},
19 {Role: "assistant", Reasoning: "thought", Content: "answer", ToolCalls: []transcript.ToolCall{{Name: "bash", Arguments: "echo ```"}}},
20 {Role: "tool", Content: "done"},
21 }
22 if err := writeSessionMarkdown(&out, "demo\nsession", messages); err != nil {
23 t.Fatal(err)
24 }
25 text := out.String()
26 for _, want := range []string{"# demo session", "## User", "question", "### Reasoning", "thought", "## Assistant", "answer", "### Tool: bash", "````", "done"} {
27 if !strings.Contains(text, want) {
28 t.Fatalf("export missing %q:\n%s", want, text)
29 }
30 }
31 }
32
33 func TestWriteStreamingExportDoesNotPublishPartialFile(t *testing.T) {
34 path := filepath.Join(t.TempDir(), "session.md")
35 err := writeStreamingExport(path, func(dst io.Writer) error {
36 _, _ = dst.Write([]byte("partial"))
37 return errors.New("stop")
38 })
39 if err == nil {
40 t.Fatal("expected write failure")
41 }
42 if _, statErr := os.Stat(path); !os.IsNotExist(statErr) {
43 t.Fatalf("partial destination published: %v", statErr)
44 }
45 }
46
46 lines GO