返回 DeepSeek-Reasonix
turn_message_origin_test.go
根目录 / internal / control / turn_message_origin_test.go
1 package control
2
3 import (
4 "context"
5 "path/filepath"
6 "testing"
7
8 "reasonix/internal/agent"
9 "reasonix/internal/event"
10 "reasonix/internal/provider"
11 "reasonix/internal/tool"
12 )
13
14 func TestTurnOrchestratorUserTextMatchingLegacySyntheticPrefixKeepsUserOrigin(t *testing.T) {
15 dir := t.TempDir()
16 path := filepath.Join(dir, "session.jsonl")
17 sess := agent.NewSession("sys")
18 prov := &scriptedTurns{turns: [][]provider.Chunk{textTurn("done")}}
19 exec := agent.New(prov, tool.NewRegistry(), sess, agent.Options{}, event.Discard)
20 c := newOwnedTestController(t, Options{Runner: exec, Executor: exec, SessionDir: dir, SessionPath: path, Label: "test"})
21
22 raw := agent.CompletionValidationContinuationPrefix + " give me a plan only"
23 if !IsSyntheticUserMessage(raw) {
24 t.Fatal("test setup: raw text must match the legacy compatibility classifier")
25 }
26 if err := newTurnOrchestrator(c).runTurnWithRawDisplay(context.Background(), raw, raw, ""); err != nil {
27 t.Fatal(err)
28 }
29
30 msgs := sess.Snapshot()
31 if len(msgs) < 2 || msgs[1].Role != provider.RoleUser || msgs[1].Origin != provider.MessageOriginUser || msgs[1].RawContent != raw {
32 t.Fatalf("persisted user message = %+v, want explicit user origin and raw content", msgs)
33 }
34 if cps := c.Checkpoints(); len(cps) != 1 || cps[0].Prompt != raw {
35 t.Fatalf("checkpoints = %+v, want a real user checkpoint", cps)
36 }
37 }
38
39 func TestComposedSyntheticTurnPersistsHostOriginWithoutKeywordFallback(t *testing.T) {
40 sess := agent.NewSession("sys")
41 prov := &scriptedTurns{turns: [][]provider.Chunk{textTurn("done")}}
42 exec := agent.New(prov, tool.NewRegistry(), sess, agent.Options{}, event.Discard)
43 c := newOwnedTestController(t, Options{Runner: exec, Executor: exec, Label: "test"})
44
45 const synthetic = "ordinary looking continuation"
46 if IsSyntheticUserMessage(synthetic) {
47 t.Fatal("test setup: synthetic text must not match the legacy classifier")
48 }
49 if err := newTurnOrchestrator(c).runComposedSyntheticTurn(context.Background(), synthetic); err != nil {
50 t.Fatal(err)
51 }
52
53 msgs := sess.Snapshot()
54 if len(msgs) < 2 || msgs[1].Origin != provider.MessageOriginHost || msgs[1].RawContent != synthetic {
55 t.Fatalf("persisted synthetic message = %+v, want explicit host origin and raw content", msgs)
56 }
57 }
58
58 lines GO