返回 DeepSeek-Reasonix
legacy_execution_policy_test.go
根目录 / internal / agent / legacy_execution_policy_test.go
1 package agent
2
3 import (
4 "context"
5 "strings"
6 "testing"
7
8 "reasonix/internal/event"
9 "reasonix/internal/provider"
10 "reasonix/internal/tool"
11 )
12
13 func TestLegacyExecutionPolicyIsStrippedFromProviderRequest(t *testing.T) {
14 sess := NewSession("system")
15 sess.Add(provider.Message{
16 Role: provider.RoleUser,
17 Content: "fix parser.go\n\n<execution-policy version=\"2\">\nroute=full-plan risk=high\n</execution-policy>",
18 RawContent: "fix parser.go",
19 })
20 sess.Add(provider.Message{Role: provider.RoleAssistant, Content: "looking"})
21 prov := &userInputCaptureProvider{}
22 a := New(prov, tool.NewRegistry(), sess, Options{}, event.Discard)
23 if err := a.Run(WithRawUserInput(context.Background(), "continue"), "continue"); err != nil {
24 t.Fatalf("Run: %v", err)
25 }
26 for _, m := range prov.request.Messages {
27 if m.Role == provider.RoleUser && strings.Contains(m.Content, "<execution-policy") {
28 t.Fatalf("historical execution-policy leaked into provider request: %q", m.Content)
29 }
30 }
31 stored := sess.Snapshot()
32 if !strings.Contains(stored[1].Content, "<execution-policy version=\"2\">") {
33 t.Fatal("stored historical execution-policy must remain readable")
34 }
35 if stored[1].RawContent != "fix parser.go" {
36 t.Fatalf("raw content rewritten: %q", stored[1].RawContent)
37 }
38 }
39
39 lines GO