| 1 | package tinyclient |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "net/http/httptest" |
| 7 | "strings" |
| 8 | "testing" |
| 9 | ) |
| 10 | |
| 11 | type remoteTypedBackend struct{ typedRoomsBackend } |
| 12 | |
| 13 | func (remoteTypedBackend) Query(context.Context, string, []json.RawMessage, string) (any, error) { |
| 14 | return nil, nil |
| 15 | } |
| 16 | func (remoteTypedBackend) ReadChatActivity(context.Context, string, string, string) (any, error) { |
| 17 | return map[string]any{"jobs" : []any{map[string]any{"id" : strings.Repeat("b" , 64), "content" : "A visible agent task" , "kind" : 5000, "created_at" : 1}}}, nil |
| 18 | } |
| 19 | |
| 20 | func TestRemotePreservesTypedRoomAndActivityRendering(t *testing.T) { |
| 21 | backend := remoteTypedBackend{typedRoomsBackend{fakeBackend: fakeBackend{policy: DefaultPolicy(strings.Repeat("a" , 64))}}} |
| 22 | app, err := New(&backend, Options{}) |
| 23 | if err != nil { |
| 24 | t.Fatal(err) |
| 25 | } |
| 26 | upstream := httptest.NewServer(app) |
| 27 | defer upstream.Close() |
| 28 | remote, err := NewRemote(RemoteOptions{BackendURL: upstream.URL, PublicURL: backend.URL()}) |
| 29 | if err != nil { |
| 30 | t.Fatal(err) |
| 31 | } |
| 32 | for _, path := range []string{"/chat" , "/rooms/build" , "/rooms/build/thread/" + strings.Repeat("b" , 64), "/chat/activity?room=build" } { |
| 33 | want, got := httptest.NewRecorder(), httptest.NewRecorder() |
| 34 | app.ServeHTTP(want, httptest.NewRequest("GET" , path, nil)) |
| 35 | remote.ServeHTTP(got, httptest.NewRequest("GET" , backend.URL()+path, nil)) |
| 36 | if want.Code != got.Code || want.Body.String() != got.Body.String() { |
| 37 | t.Fatalf("typed parity %s: got status %d want %d\n%s" , path, got.Code, want.Code, got.Body.String()) |
| 38 | } |
| 39 | } |
| 40 | } |