| 1 | package provider |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestModelMessagesStripsOriginWithoutChangingProviderBytes(t *testing.T) { |
| 9 | stored := []Message{{Role: RoleUser, Origin: MessageOriginUser, Content: "fix the bug", RawContent: "fix the bug"}} |
| 10 | legacy := []Message{{Role: RoleUser, Content: "fix the bug"}} |
| 11 | |
| 12 | model := ModelMessages(stored) |
| 13 | want := ModelMessages(legacy) |
| 14 | gotJSON, err := json.Marshal(model) |
| 15 | if err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | wantJSON, err := json.Marshal(want) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | if string(gotJSON) != string(wantJSON) { |
| 23 | t.Fatalf("origin changed provider bytes:\n got %s\nwant %s", gotJSON, wantJSON) |
| 24 | } |
| 25 | if stored[0].Origin != MessageOriginUser { |
| 26 | t.Fatal("provider projection mutated stored origin") |
| 27 | } |
| 28 | } |
| 29 |