返回 DeepSeek-Reasonix
plan_execution_identity_test.go
根目录 / internal / control / plan_execution_identity_test.go
1 package control
2
3 import (
4 "context"
5 "testing"
6
7 "reasonix/internal/event"
8 "reasonix/internal/provider"
9 )
10
11 // The approved-plan execution turn runs in the planning turn's context, which
12 // carries the user message identity the controller reserved for that turn.
13 func TestApprovedPlanExecutionMintsItsOwnUserMessageID(t *testing.T) {
14 prov := &scriptedTurns{turns: planThenExecuteTurns("Plan:\n1. Change it", "Done.")}
15 ag := newPlanTestAgent(prov)
16 approvalID := make(chan string, 1)
17 c := newOwnedTestController(t, Options{
18 Runner: ag,
19 Executor: ag,
20 Sink: event.FuncSink(func(e event.Event) {
21 if e.Kind == event.ApprovalRequest {
22 approvalID <- e.Approval.ID
23 }
24 }),
25 })
26 c.SetPlanMode(true)
27 go func() { c.Approve(<-approvalID, true, false, false) }()
28
29 if err := c.runTurnWithRaw(context.Background(), "change it", "change it"); err != nil {
30 t.Fatalf("runTurnWithRaw: %v", err)
31 }
32 users := 0
33 seen := map[string]bool{}
34 for _, message := range ag.Session().Messages {
35 if message.Role == provider.RoleUser {
36 users++
37 }
38 if seen[message.ID] {
39 t.Fatalf("message id %q appears twice (second as %s/%s)", message.ID, message.Role, message.Origin)
40 }
41 seen[message.ID] = true
42 }
43 if users < 2 {
44 t.Fatalf("user messages = %d, want the request and the approved-plan continuation", users)
45 }
46 }
47
47 lines GO