tinyrelayfile
tinyrelay/tinyclient/remote_rooms_test.go/

tinyclient/remote_rooms_test.go raw
1package tinyclient
2
3import (
4 "context"
5 "encoding/json"
6 "net/http/httptest"
7 "strings"
8 "testing"
9)
10
11type remoteTypedBackend struct{ typedRoomsBackend }
12
13func (remoteTypedBackend) Query(context.Context, string, []json.RawMessage, string) (any, error) {
14 return nil, nil
15}
16func (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
20func 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}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs