From 02999848e5d01234bcb501fef726107b31941373 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 17:31:58 +0100 Subject: [PATCH 1/2] [AI-3613] Test a failing call-events and floor-checks read A voice call's decisions and floor checks come from the shared Redis. No test made either read fail, so a change that swallowed the read error or dropped the floor-check ERROR line passed every suite. The test swaps the suite store's CallEvents for one built on a closed Redis client and asserts what each read answers: the timeline still answers 200 without checks and logs the ERROR line, the decisions answer 500. Co-Authored-By: Claude Sonnet 5.5 --- acceleration/internal/api/calls_test.go | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/acceleration/internal/api/calls_test.go b/acceleration/internal/api/calls_test.go index 3f7edc8d98..4a67e5d293 100644 --- a/acceleration/internal/api/calls_test.go +++ b/acceleration/internal/api/calls_test.go @@ -7,6 +7,7 @@ import ( "context" "encoding/json" "net/http" + "os" "strings" "testing" "time" @@ -842,6 +843,60 @@ func (s *CallsSuite) TestAVoiceCallsTimelineStillCarriesItsFloorChecks() { s.Empty(s.errorsAbout(call.ID)) } +func (s *CallsSuite) TestAVoiceCallsTimelineIsAnsweredWithoutFloorChecksWhenTheirReadFails() { + ctx := context.Background() + call := s.started(store.Call{StartedAt: time.Now().UTC().Truncate(time.Millisecond).Add(-time.Minute)}) + at := call.StartedAt.Add(time.Second) + s.Require().NoError(s.store.Turns.Insert(ctx, store.Turn{CustomerID: s.customerID(), AgentID: call.AgentID, + CallID: call.CallID, TurnID: "turn-1", StartedAt: at})) + check := floorChecked("turn-1", pauseFloorCheck(at.Add(-500*time.Millisecond))) + check.CustomerID, check.CallID, check.AgentID = s.customerID(), call.CallID, call.AgentID + s.Require().NoError(s.store.CallEvents.InsertMany(ctx, []store.CallEvent{check})) + s.callEventsOnClosedRedis() + + var timeline []TimelineEntry + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodGet, + "/v1/agents/calls/"+call.ID+"/timeline", nil, &timeline), "the checks are not worth failing the timeline over") + + s.Require().Len(timeline, 1, "the turns are still read") + s.Equal("turn-1", timeline[0].TurnId) + s.Nil(timeline[0].FloorChecks, "the checks the read could not return are not shown") + s.Require().Len(s.errorsAbout(call.ID), 1) + s.Contains(s.errorsAbout(call.ID)[0], `msg="could not read the floor checks for a timeline"`) + s.Contains(s.errorsAbout(call.ID)[0], "store: floor checks") +} + +func (s *CallsSuite) TestAVoiceCallsDecisionsAreNotAnEmptyListWhenTheirReadFails() { + // The decisions are the whole of this answer, so a read that failed is no call that decided + // nothing: the caller is told something went wrong, and the access line is an ERROR. + call := s.started(store.Call{StartedAt: time.Now().Add(-time.Minute)}) + s.Require().NoError(s.store.CallEvents.InsertMany(context.Background(), []store.CallEvent{{ + CustomerID: s.customerID(), CallID: call.CallID, AgentID: call.AgentID, + At: time.Now(), Kind: "answer", Reason: "a complete thought", + }})) + s.callEventsOnClosedRedis() + + response := s.serverClient.raw(http.MethodGet, "/v1/agents/calls/"+call.ID+"/events", nil) + s.Equal(http.StatusInternalServerError, response.StatusCode) + requestID := response.Header.Get(RequestIDHeader) + s.Require().NotEmpty(requestID) + served := func() string { return lineWith(s.logged, `msg="served a request"`, " request_id="+requestID) } + s.Require().Eventually(func() bool { return served() != "" }, 5*time.Second, 20*time.Millisecond, s.logged.String()) + s.Contains(served(), "level=ERROR") +} + +// callEventsOnClosedRedis has the decisions and floor checks every read of the suite's store +// makes come from a Redis that is closed, as an unreachable one is. The test's end puts them back. +func (s *CallsSuite) callEventsOnClosedRedis() { + closed, err := store.OpenShards(store.Options{DSN: testDatabase(s.T(), os.Getenv("ROUTER_POSTGRES_DSN")), + Redis: store.Redis{Address: s.redisAddr}}) + s.Require().NoError(err) + s.Require().NoError(closed.Close()) + original := s.store.CallEvents + s.store.CallEvents = closed.CallEvents + s.T().Cleanup(func() { s.store.CallEvents = original }) +} + // errorsAbout is the ERROR lines the router logged about the call with this row id. func (s *CallsSuite) errorsAbout(id string) []string { var errors []string From 869929e565af436f835fe66e701422cd79881762 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 17:41:35 +0100 Subject: [PATCH 2/2] AI-3613: assert the store error in the decisions 500 test The test's 500 and ERROR access line also hold for any other handler failure. Assert the access line names the failed read, as the floor-check test does. Co-Authored-By: Claude Haiku 5.5 --- acceleration/internal/api/calls_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/acceleration/internal/api/calls_test.go b/acceleration/internal/api/calls_test.go index 4a67e5d293..5044df78bb 100644 --- a/acceleration/internal/api/calls_test.go +++ b/acceleration/internal/api/calls_test.go @@ -883,6 +883,7 @@ func (s *CallsSuite) TestAVoiceCallsDecisionsAreNotAnEmptyListWhenTheirReadFails served := func() string { return lineWith(s.logged, `msg="served a request"`, " request_id="+requestID) } s.Require().Eventually(func() bool { return served() != "" }, 5*time.Second, 20*time.Millisecond, s.logged.String()) s.Contains(served(), "level=ERROR") + s.Contains(served(), "store: call events") } // callEventsOnClosedRedis has the decisions and floor checks every read of the suite's store