| 1 | package transcript |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/provider" |
| 9 | ) |
| 10 | |
| 11 | func TestPresentedFilesJSONRoundTripAndOmitEmpty(t *testing.T) { |
| 12 | want := []provider.PresentedFile{{Path: "game.html", Description: "Playable game"}} |
| 13 | encoded, err := json.Marshal(Message{Role: "tool", ToolCallID: "present-1", PresentedFiles: want}) |
| 14 | if err != nil { |
| 15 | t.Fatal(err) |
| 16 | } |
| 17 | if !strings.Contains(string(encoded), `"presentedFiles"`) { |
| 18 | t.Fatalf("trusted metadata missing from transcript JSON: %s", encoded) |
| 19 | } |
| 20 | var decoded Message |
| 21 | if err := json.Unmarshal(encoded, &decoded); err != nil { |
| 22 | t.Fatal(err) |
| 23 | } |
| 24 | if len(decoded.PresentedFiles) != 1 || decoded.PresentedFiles[0] != want[0] { |
| 25 | t.Fatalf("round trip = %#v, want %#v", decoded.PresentedFiles, want) |
| 26 | } |
| 27 | empty, err := json.Marshal(Message{Role: "tool", ToolCallID: "ordinary"}) |
| 28 | if err != nil { |
| 29 | t.Fatal(err) |
| 30 | } |
| 31 | if strings.Contains(string(empty), `"presentedFiles"`) { |
| 32 | t.Fatalf("empty metadata was not omitted: %s", empty) |
| 33 | } |
| 34 | } |
| 35 |