| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "reasonix/internal/provider" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | ) |
| 9 | |
| 10 | func TestProtocolRecoveryHistoryVersionAndConsumption(t *testing.T) { |
| 11 | for _, tc := range []struct { |
| 12 | version int |
| 13 | state string |
| 14 | visible bool |
| 15 | }{{1, "pending", true}, {1, "consumed", false}, {99, "pending", false}} { |
| 16 | raw, _ := json.Marshal(provider.ProtocolRecoveryRecord{Version: tc.version, State: tc.state, ID: "fault", Prefix: 2, Fingerprint: "hash"}) |
| 17 | got := historyMessages([]provider.Message{{LocalOnly: true, ProtocolRecovery: raw}}, func(s string) string { return s }) |
| 18 | if (len(got) > 0) != tc.visible { |
| 19 | t.Fatalf("state=%+v history=%+v", tc, got) |
| 20 | } |
| 21 | if tc.visible && (got[0].ProtocolRecovery == nil || got[0].ProtocolRecovery.ID != "fault") { |
| 22 | t.Fatal("lost action token") |
| 23 | } |
| 24 | } |
| 25 | got := historyMessages([]provider.Message{{Role: provider.RoleAssistant, Content: "summary", ServerSearch: []provider.ServerSearchCall{{ID: "s", SourcesStatus: provider.SourcesNotProvided, Raw: json.RawMessage(`{"opaque":"private"}`)}}}}, func(s string) string { return s }) |
| 26 | raw, _ := json.Marshal(got) |
| 27 | if !strings.Contains(string(raw), "not_provided") || strings.Contains(string(raw), "private") { |
| 28 | t.Fatalf("search history=%s", raw) |
| 29 | } |
| 30 | } |
| 31 |