| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | |
| 7 | "reasonix/internal/event" |
| 8 | "reasonix/internal/provider" |
| 9 | ) |
| 10 | |
| 11 | func TestHistoryRestoresProviderFailureInsteadOfInterruptedNotice(t *testing.T) { |
| 12 | message := provider.Message{ |
| 13 | Role: provider.RoleTool, LocalOnly: true, |
| 14 | InterruptedTurn: &provider.InterruptedTurnRecovery{ |
| 15 | Pending: true, TerminalStatus: "failed", |
| 16 | FailureDiagnostic: &provider.FailureDiagnostic{Kind: "request", Status: 404, ProviderID: "deepseek-anthropic", ProviderDisplayName: "Deepseek2", Protocol: "openai", RequestPath: "/anthropic/v1/chat/completions"}, |
| 17 | }, |
| 18 | } |
| 19 | history := historyMessages([]provider.Message{message}, func(value string) string { return value }) |
| 20 | if len(history) != 1 { |
| 21 | t.Fatalf("history = %+v", history) |
| 22 | } |
| 23 | got := history[0] |
| 24 | if got.Code != event.NoticeCodeProviderRequestFailed || got.Level != "warn" || !strings.Contains(got.Content, "Deepseek2 · Chat Completions") || !strings.Contains(got.Content, "HTTP 404") { |
| 25 | t.Fatalf("failure history = %+v", got) |
| 26 | } |
| 27 | if got.Detail != "Connection ID: deepseek-anthropic\nRequest path: /anthropic/v1/chat/completions" || got.Diagnostic == nil || got.Diagnostic.ProviderID != "deepseek-anthropic" { |
| 28 | t.Fatalf("failure detail = %+v", got) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestHistoryKeepsLegacyAndExplicitInterruptionsCompatible(t *testing.T) { |
| 33 | for _, recovery := range []*provider.InterruptedTurnRecovery{{Pending: true}, {Pending: true, TerminalStatus: "interrupted"}} { |
| 34 | history := historyMessages([]provider.Message{{Role: provider.RoleTool, LocalOnly: true, InterruptedTurn: recovery}}, func(value string) string { return value }) |
| 35 | if len(history) != 1 || history[0].Code != event.NoticeCodeCancelledTurn { |
| 36 | t.Fatalf("interrupted history = %+v", history) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 |