| 1 | package stream |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestBackendStreams(t *testing.T) { |
| 10 | for _, tc := range []struct { |
| 11 | name, input string |
| 12 | want []string |
| 13 | }{ |
| 14 | {"codex", `{"type":"thread.started","thread_id":"thread"} |
| 15 | {"type":"item.started","item":{"type":"command_execution","command":"go test ./..."}} |
| 16 | {"type":"item.completed","item":{"type":"agent_message","text":"Finished"}} |
| 17 | {"type":"turn.completed","usage":{"input_tokens":1,"output_tokens":2}} |
| 18 | `, []string{"session started", "go test ./...", "Finished", "cost unavailable"}}, |
| 19 | {"agy", `{"event":"init","conversation_id":"thread","init":{"model":"test-model"}} |
| 20 | {"event":"step_update","step_update":{"step_type":"agent_response","state":"ACTIVE","text_delta":"Fin"}} |
| 21 | {"event":"step_update","step_update":{"step_type":"agent_response","state":"DONE","text_delta":"ished\n"}} |
| 22 | {"event":"result","result":{"status":"SUCCESS","response":"Finished\n"}} |
| 23 | `, []string{"test-model", "Finished\n", "cost unavailable"}}, |
| 24 | {"agy failure", `{"event":"result","result":{"status":"ERROR","error":"authentication required"}} |
| 25 | `, []string{"agent failed"}}, |
| 26 | } { |
| 27 | t.Run(tc.name, func(t *testing.T) { |
| 28 | var out bytes.Buffer |
| 29 | if err := FormatStream(strings.NewReader(tc.input), &out); err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | for _, want := range tc.want { |
| 33 | if !strings.Contains(out.String(), want) { |
| 34 | t.Fatalf("missing %q in %q", want, out.String()) |
| 35 | } |
| 36 | } |
| 37 | }) |
| 38 | } |
| 39 | } |