fix: per-caller context on account lookup, stop on non-websocket receive, sanitize CLI output

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vincent BourdonandClaude Opus 5.5 committed 2026-11-20 15:51:38 +01:00
1 parent 45f88378a6
commit 136e431917
8 files changed
+89 -7

No files matched your search

+29
View File
@@ -6,6 +6,7 @@ import (
"net/http"
"reflect"
"testing"
"time"
)
func TestNewDoesNoNetwork(t *testing.T) {
@@ -175,3 +176,31 @@ func TestEndpointJoin(t *testing.T) {
}
}
}
func TestAccountLookupRespectsCallerContext(t *testing.T) {
f := newFakeAPI(t)
release := make(chan struct{})
t.Cleanup(func() { close(release) })
f.mux.HandleFunc("GET /v1/accounts", func(w http.ResponseWriter, r *http.Request) {
select {
case <-release:
case <-r.Context().Done():
}
})
c := mustNew(t, f.URL)
go func() { _, _ = c.account(context.Background()) }() // e.g. Listen, stuck on a hung service
time.Sleep(50 * time.Millisecond)
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
done := make(chan error, 1)
go func() { done <- c.Send(ctx, "+332", "hi") }()
select {
case err := <-done:
if !errors.Is(err, context.DeadlineExceeded) {
t.Fatalf("Send err = %v, want DeadlineExceeded", err)
}
case <-time.After(2 * time.Second):
t.Fatal("Send ignored its context while another account lookup was in flight")
}
}