Download this file
| 1 | package chatstream |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 5 | "context" |
| 6 | "encoding/json" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | func TestBoundedForwarding(t *testing.T) { |
| 12 | calls := 0 |
| 13 | f := Forwarder{Send: func(context.Context, string, int64) error { calls++; return nil }} |
| 14 | delta := []byte(`{"event":{"type":"content_block_delta","delta":{"type":"text_delta","text":"words"}}}`) |
| 15 | for range 100 { |
| 16 | if err := f.Add(context.Background(), delta); err != nil { |
| 17 | t.Fatal(err) |
| 18 | } |
| 19 | } |
| 20 | if calls != 1 { |
| 21 | t.Fatal("unbounded event rate", calls) |
| 22 | } |
| 23 | e := TextEvent(runnerproto.Event{}, strings.Repeat("đŸ˜€<\n", 10000), 1) |
| 24 | var text runnerproto.CoordinatorText |
| 25 | if json.Unmarshal(e.Payload, &text) != nil || text.Validate() != nil || len(e.Payload) > runnerproto.MaxEventBytes { |
| 26 | t.Fatal("unbounded or broken UTF-8 snapshot") |
| 27 | } |
| 28 | } |
| 29 | |