返回 DeepSeek-Reasonix
tool_recovery_actions_test.go
根目录 / internal / agent / tool_recovery_actions_test.go
1 package agent
2
3 import (
4 "context"
5 "encoding/json"
6 "strings"
7 "testing"
8
9 "reasonix/internal/event"
10 "reasonix/internal/provider"
11 "reasonix/internal/tool"
12 )
13
14 func retiredRecoveryFixture() *Agent {
15 record := provider.ToolCallRecord{
16 Identity: provider.ActionIdentity{CallID: "old", AttemptID: "attempt", CanonicalTool: "external_write"},
17 State: provider.ToolRunUnknown,
18 Arguments: json.RawMessage(`{"value":"kept"}`),
19 }
20 session := NewSession("")
21 session.Add(provider.Message{Role: provider.RoleAssistant, ToolCalls: []provider.ToolCall{{ID: "old", Name: "external_write", Recovery: &record}}})
22 return New(nil, tool.NewRegistry(), session, Options{}, event.Discard)
23 }
24
25 func TestRetiredToolRecoveryActionsNeverRewriteOrReplay(t *testing.T) {
26 a := retiredRecoveryFixture()
27 fact, err := a.InspectToolRecovery(context.Background(), "attempt")
28 if err == nil || !strings.Contains(err.Error(), "tool_recovery_retired") || fact.State != provider.ToolRunUnknown {
29 t.Fatalf("inspect fact=%+v err=%v", fact, err)
30 }
31 if err := a.ResolveToolRecovery("attempt", "inspection", "confirm"); err == nil || !strings.Contains(err.Error(), "tool_recovery_retired") {
32 t.Fatalf("resolve err=%v", err)
33 }
34 if err := a.RetryToolRecovery(context.Background(), "attempt", "inspection"); err == nil || !strings.Contains(err.Error(), "tool_recovery_retired") {
35 t.Fatalf("retry err=%v", err)
36 }
37 pending := a.PendingToolRecovery()
38 if len(pending) != 1 || pending[0].State != provider.ToolRunUnknown || string(pending[0].Arguments) != `{"value":"kept"}` {
39 t.Fatalf("historical record changed: %+v", pending)
40 }
41 }
42
42 lines GO