| 1 | package transcript |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/event" |
| 9 | "reasonix/internal/provider" |
| 10 | ) |
| 11 | |
| 12 | func TestFailureHistoryRetainsCauseAcrossSerialization(t *testing.T) { |
| 13 | const cause = "Image processing failed: configured image understanding model does not accept images" |
| 14 | message := provider.Message{ID: "failure", Role: provider.RoleTool, LocalOnly: true, ToolCallID: provider.LocalOnlyToolID, Name: provider.LocalOnlyToolName, |
| 15 | InterruptedTurn: &provider.InterruptedTurnRecovery{TerminalStatus: "failed", Pending: true, Cause: cause, FailureDiagnostic: &provider.FailureDiagnostic{Kind: provider.FailureKindImageInput}}, |
| 16 | } |
| 17 | raw, err := json.Marshal(message) |
| 18 | if err != nil { |
| 19 | t.Fatal(err) |
| 20 | } |
| 21 | var reopened provider.Message |
| 22 | if err := json.Unmarshal(raw, &reopened); err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | rows := History([]provider.Message{reopened}, HistoryOptions{}) |
| 26 | if len(rows) != 1 || rows[0].Code != event.NoticeCodeProviderRequestFailed || rows[0].Content != cause || rows[0].Detail != cause || rows[0].Diagnostic.Kind != provider.FailureKindImageInput { |
| 27 | t.Fatalf("lost detail: %+v", rows) |
| 28 | } |
| 29 | if len(provider.ModelMessages([]provider.Message{reopened})) != 0 { |
| 30 | t.Fatal("failure detail entered provider context") |
| 31 | } |
| 32 | message.InterruptedTurn.Cause = "" |
| 33 | message.InterruptedTurn.FailureDiagnostic = &provider.FailureDiagnostic{Kind: "unknown"} |
| 34 | legacy := History([]provider.Message{message}, HistoryOptions{}) |
| 35 | if !strings.Contains(legacy[0].Content, "were not saved") || legacy[0].Detail != "" { |
| 36 | t.Fatalf("invented legacy cause: %+v", legacy) |
| 37 | } |
| 38 | } |
| 39 |