From e90c97152e368d92a671bc771f8b3cea7196c020 Mon Sep 17 00:00:00 2001 From: thesyncim Date: Mon, 23 Nov 2026 12:47:12 +0000 Subject: [PATCH 1/6] fix(store): carry opt-outs in a data move, keeping the destination's live ones --- CHANGELOG.md | 3 + acceleration/internal/store/datamove.go | 11 +++ acceleration/internal/store/datamove_test.go | 71 ++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb5ca85eb0..110c1ffd00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -896,6 +896,9 @@ In a channel an agent config answers through `chat_channels`, a call of a tool y ### A connection keeps a rotated token when saving it fails once When a connector's provider rotates the refresh token on a refresh, and the save of the new tokens then fails briefly, for example on a dropped database connection, the router saves them again up to twice in the next 300 ms. Before, the connection stayed `needs_reauthorization` and the person had to reconnect the account. If every save fails, the router logs an error with the connection's id, and the connection still needs a reconnect (AI-3504). +### A moved app keeps who asked not to be reached + +`GET /v1/data/export` and `GET /v1/data/changes` now carry the app's opt-outs, so a recipient who texted STOP is still opted out where the app moved to, and a STOP or START at the source after the copy arrives with the other changes. An opt-out already live at the destination for the same recipient and channel is kept, and an imported revoked opt-out lifts only the row it was copied from (AI-3489). ### An SMS reply sets its price aside before it is sent diff --git a/acceleration/internal/store/datamove.go b/acceleration/internal/store/datamove.go index e9b1a2e881..bf8887579b 100644 --- a/acceleration/internal/store/datamove.go +++ b/acceleration/internal/store/datamove.go @@ -132,6 +132,8 @@ var dataTables = []dataTable{ {name: "users", customer: "customer_id", vouched: []string{"minted"}}, {name: "scheduled_tasks", customer: "customer_id"}, {name: "scheduled_task_runs", customer: "customer_id"}, + // Who asked not to be reached: STOP and START at the source carry on here through the changes. + {name: "opt_outs", customer: "customer_id"}, {name: "recordings", customer: "customer_id", shard: true}, {name: "agent_sessions", customer: "customer_id", shard: true}, {name: "agent_session_tools", parent: "agent_sessions", parentColumn: "session_id", shard: true}, @@ -805,6 +807,15 @@ func (s *Store) importRow(ctx context.Context, db bun.IDB, customerID, table str if spec.copied != "" { where = " WHERE NOT " + spec.copiedBefore(shape, columns) } + if table == "opt_outs" { + // An opt-out live here under another id is this deployment's, and stays: the row arriving + // would break the one-live-row index, and dropping the live one would let the person be + // reached again. A revoked row is history beside it, and revokes only the row of its own id, + // so a START replayed from the source lifts only what the source sent. Two writes of one + // live opt-out here at the same moment can still fail the statement on that index. + where = " WHERE NOT (r.revoked_at IS NULL AND EXISTS (SELECT 1 FROM opt_outs AS h WHERE h.customer_id = r.customer_id" + + " AND h.recipient = r.recipient AND h.channel = r.channel AND h.revoked_at IS NULL AND h.id <> r.id))" + } args := []any{string(row), customerID} if table == "requests" { // The organization a request counts against is the app's here, whatever the row says. diff --git a/acceleration/internal/store/datamove_test.go b/acceleration/internal/store/datamove_test.go index 26b1e6b99f..2092b94477 100644 --- a/acceleration/internal/store/datamove_test.go +++ b/acceleration/internal/store/datamove_test.go @@ -425,6 +425,77 @@ func (s *DataMoveSuite) TestADeleteIsReplayedToo() { s.Empty(s.exportFrom(s.destination, "acme").of("agent_configs")) } +// Defect: opt_outs left out of what a move carries, so whoever texted STOP is reached again. +func (s *DataMoveSuite) TestAMovedRecipientIsStillOptedOut() { + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550101", Channel: "sms", Source: "keyword"})) + + s.move("acme", "moved") + + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550101", "sms") + s.Require().NoError(err) + s.True(optedOut) +} + +// Defect: a STOP or START at the source after the copy recorded no change, or replayed as +// something else. +func (s *DataMoveSuite) TestAStopAndAStartAfterTheCopyArriveThroughTheChanges() { + s.capture("acme") + cursor := s.move("acme", "moved") + + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550102", Channel: "sms", Source: "keyword"})) + changes, cursor, err := s.source.Changes(s.ctx, "acme", cursor, 100) + s.Require().NoError(err) + s.Require().NoError(s.destination.ApplyChanges(s.ctx, "moved", changes)) + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550102", "sms") + s.Require().NoError(err) + s.True(optedOut, "the STOP") + + s.Require().NoError(s.source.OptOuts.RevokeAll(s.ctx, "acme", "+12025550102", "sms")) + changes, _, err = s.source.Changes(s.ctx, "acme", cursor, 100) + s.Require().NoError(err) + s.Require().NoError(s.destination.ApplyChanges(s.ctx, "moved", changes)) + optedOut, err = s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550102", "sms") + s.Require().NoError(err) + s.False(optedOut, "the START") +} + +// Defect: the source's opt-out for a recipient already opted out here breaks the one-live-row +// index and fails the import, or replaces the one recorded here. +func (s *DataMoveSuite) TestAnImportOverALiveOptOutLeavesIt() { + here := OptOut{CustomerID: "moved", Recipient: "+12025550103", Channel: "sms", Source: "keyword"} + s.Require().NoError(s.destination.OptOuts.Insert(s.ctx, &here)) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550103", Channel: "sms", Source: "api"})) + + s.move("acme", "moved") + + live, err := s.destination.OptOuts.Select(s.ctx, "moved", 10, nil) + s.Require().NoError(err) + s.Require().Len(live, 1) + s.Equal(here.ID, live[0].ID) + s.Equal("keyword", live[0].Source) +} + +// Defect: a START at the source, replayed here, lifts the opt-out recorded here for the same +// recipient. +func (s *DataMoveSuite) TestAnImportedRevokedOptOutDoesNotLiftOneRecordedHere() { + here := OptOut{CustomerID: "moved", Recipient: "+12025550104", Channel: "sms", Source: "keyword"} + s.Require().NoError(s.destination.OptOuts.Insert(s.ctx, &here)) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550104", Channel: "sms", Source: "keyword"})) + s.capture("acme") + cursor := s.move("acme", "moved") + + s.Require().NoError(s.source.OptOuts.RevokeAll(s.ctx, "acme", "+12025550104", "sms")) + changes, _, err := s.source.Changes(s.ctx, "acme", cursor, 100) + s.Require().NoError(err) + s.Require().NotEmpty(changes) + s.Require().NoError(s.destination.ApplyChanges(s.ctx, "moved", changes)) + + live, err := s.destination.OptOuts.Select(s.ctx, "moved", 10, nil) + s.Require().NoError(err) + s.Require().Len(live, 1) + s.Equal(here.ID, live[0].ID) +} + // The columns a move copies are read from the catalog, so the bindings come with the // config without being named anywhere. func (s *DataMoveSuite) TestAConfigsBindingsMoveWithIt() { From dd7f1f41ec56ba6913b92fd75ba0b5af7bc4f9d6 Mon Sep 17 00:00:00 2001 From: thesyncim Date: Mon, 23 Nov 2026 12:58:21 +0000 Subject: [PATCH 2/6] fix(store): export revoked opt-outs before live ones, so a second copy keeps a new STOP --- CHANGELOG.md | 2 +- acceleration/internal/store/datamove.go | 10 +++++++++- acceleration/internal/store/datamove_test.go | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 110c1ffd00..a484f0046b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -898,7 +898,7 @@ In a channel an agent config answers through `chat_channels`, a call of a tool y When a connector's provider rotates the refresh token on a refresh, and the save of the new tokens then fails briefly, for example on a dropped database connection, the router saves them again up to twice in the next 300 ms. Before, the connection stayed `needs_reauthorization` and the person had to reconnect the account. If every save fails, the router logs an error with the connection's id, and the connection still needs a reconnect (AI-3504). ### A moved app keeps who asked not to be reached -`GET /v1/data/export` and `GET /v1/data/changes` now carry the app's opt-outs, so a recipient who texted STOP is still opted out where the app moved to, and a STOP or START at the source after the copy arrives with the other changes. An opt-out already live at the destination for the same recipient and channel is kept, and an imported revoked opt-out lifts only the row it was copied from (AI-3489). +`GET /v1/data/export` and `GET /v1/data/changes` now carry the app's opt-outs, so a recipient who texted STOP is still opted out where the app moved to, and a STOP or START at the source after the copy arrives with the other changes. An opt-out already live at the destination for the same recipient and channel is kept, and an imported revoked opt-out lifts only the row it was copied from. A copy taken again after a START and a new STOP at the source keeps the recipient opted out (AI-3489). ### An SMS reply sets its price aside before it is sent diff --git a/acceleration/internal/store/datamove.go b/acceleration/internal/store/datamove.go index bf8887579b..5e9398f62c 100644 --- a/acceleration/internal/store/datamove.go +++ b/acceleration/internal/store/datamove.go @@ -46,6 +46,9 @@ type dataTable struct { // filter is an extra predicate on an export, for a table that holds more than one // kind of row. filter string + // order is the order an export reads the table's rows in, for a table whose rows must + // arrive in one. + order string // shard is a table kept in the shards rather than the shared database. shard bool // across is the column a row is known by in every deployment, for a table whose primary @@ -133,7 +136,9 @@ var dataTables = []dataTable{ {name: "scheduled_tasks", customer: "customer_id"}, {name: "scheduled_task_runs", customer: "customer_id"}, // Who asked not to be reached: STOP and START at the source carry on here through the changes. - {name: "opt_outs", customer: "customer_id"}, + // Revoked rows go first, so one revoked at the source lifts its copy here before the live + // row that replaced it arrives, rather than after the import skipped that row beside it. + {name: "opt_outs", customer: "customer_id", order: "revoked_at IS NULL"}, {name: "recordings", customer: "customer_id", shard: true}, {name: "agent_sessions", customer: "customer_id", shard: true}, {name: "agent_session_tools", parent: "agent_sessions", parentColumn: "session_id", shard: true}, @@ -661,6 +666,9 @@ func (t dataTable) selectRows(customerID string, secrets []string) (string, []an if t.filter != "" { where += " AND " + t.filter } + if t.order != "" { + where += " ORDER BY " + t.order + } return fmt.Sprintf("SELECT %s FROM %s AS t WHERE %s", subject.String(), t.name, where), []any{customerID} } diff --git a/acceleration/internal/store/datamove_test.go b/acceleration/internal/store/datamove_test.go index 2092b94477..3fb6f27a71 100644 --- a/acceleration/internal/store/datamove_test.go +++ b/acceleration/internal/store/datamove_test.go @@ -475,6 +475,25 @@ func (s *DataMoveSuite) TestAnImportOverALiveOptOutLeavesIt() { s.Equal("keyword", live[0].Source) } +// Defect: a second copy read the source's new live opt-out before the revoked one it replaced, +// so the import skipped it beside the old copy here, and the revoked row then lifted that copy. +func (s *DataMoveSuite) TestASecondCopyAfterAStartAndAStopKeepsTheRecipientOptedOut() { + first := OptOut{CustomerID: "acme", Recipient: "+12025550105", Channel: "sms", Source: "keyword"} + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &first)) + s.move("acme", "moved") + + s.Require().NoError(s.source.OptOuts.RevokeAll(s.ctx, "acme", "+12025550105", "sms")) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550105", Channel: "sms", Source: "keyword"})) + // Store the rows newest first: an export may meet them in any order the table holds them. + _, err := s.source.GlobalDB().ExecContext(s.ctx, "CLUSTER opt_outs USING opt_outs_customer_idx") + s.Require().NoError(err) + s.move("acme", "moved") + + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550105", "sms") + s.Require().NoError(err) + s.True(optedOut) +} + // Defect: a START at the source, replayed here, lifts the opt-out recorded here for the same // recipient. func (s *DataMoveSuite) TestAnImportedRevokedOptOutDoesNotLiftOneRecordedHere() { From b6d630514da22da243aa2fda8ed6b53de3e24e6e Mon Sep 17 00:00:00 2001 From: thesyncim Date: Mon, 23 Nov 2026 13:40:52 +0000 Subject: [PATCH 3/6] fix(store): validate imported opt-outs like the other imported rows --- CHANGELOG.md | 1 + acceleration/internal/store/datamove.go | 1 + acceleration/internal/store/datamove_test.go | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a484f0046b..de1be7c1a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -896,6 +896,7 @@ In a channel an agent config answers through `chat_channels`, a call of a tool y ### A connection keeps a rotated token when saving it fails once When a connector's provider rotates the refresh token on a refresh, and the save of the new tokens then fails briefly, for example on a dropped database connection, the router saves them again up to twice in the next 300 ms. Before, the connection stayed `needs_reauthorization` and the person had to reconnect the account. If every save fails, the router logs an error with the connection's id, and the connection still needs a reconnect (AI-3504). + ### A moved app keeps who asked not to be reached `GET /v1/data/export` and `GET /v1/data/changes` now carry the app's opt-outs, so a recipient who texted STOP is still opted out where the app moved to, and a STOP or START at the source after the copy arrives with the other changes. An opt-out already live at the destination for the same recipient and channel is kept, and an imported revoked opt-out lifts only the row it was copied from. A copy taken again after a START and a new STOP at the source keeps the recipient opted out (AI-3489). diff --git a/acceleration/internal/store/datamove.go b/acceleration/internal/store/datamove.go index 5e9398f62c..1bab9c0703 100644 --- a/acceleration/internal/store/datamove.go +++ b/acceleration/internal/store/datamove.go @@ -914,6 +914,7 @@ var importedModels = map[string]func() validated{ "simulation_cases": func() validated { return &SimulationCase{} }, "scheduled_tasks": func() validated { return &ScheduledTask{} }, "scheduled_task_runs": func() validated { return &ScheduledTaskRun{} }, + "opt_outs": func() validated { return &OptOut{} }, "recordings": func() validated { return &Recording{} }, "agent_sessions": func() validated { return &AgentSession{} }, "agent_session_tools": func() validated { return &agentSessionTools{} }, diff --git a/acceleration/internal/store/datamove_test.go b/acceleration/internal/store/datamove_test.go index 3fb6f27a71..923d44df11 100644 --- a/acceleration/internal/store/datamove_test.go +++ b/acceleration/internal/store/datamove_test.go @@ -515,6 +515,16 @@ func (s *DataMoveSuite) TestAnImportedRevokedOptOutDoesNotLiftOneRecordedHere() s.Equal(here.ID, live[0].ID) } +// Defect: an imported opt-out that names no recipient was stored, one the API refuses. +func (s *DataMoveSuite) TestAnImportedOptOutWithoutARecipientIsRefused() { + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550106", Channel: "sms", Source: "keyword"})) + + err := s.importEdited("opt_outs", "moved", func(row map[string]any) { row["recipient"] = "" }) + + s.ErrorContains(err, "recipient") + s.Empty(s.exportFrom(s.destination, "moved").of("opt_outs")) +} + // The columns a move copies are read from the catalog, so the bindings come with the // config without being named anywhere. func (s *DataMoveSuite) TestAConfigsBindingsMoveWithIt() { From c123de7de54587dbeada894bba69a983fb5a2be3 Mon Sep 17 00:00:00 2001 From: thesyncim Date: Mon, 23 Nov 2026 13:54:20 +0000 Subject: [PATCH 4/6] chore: drop the CHANGELOG entry; pull requests no longer edit it --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de1be7c1a7..bb5ca85eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -897,10 +897,6 @@ In a channel an agent config answers through `chat_channels`, a call of a tool y When a connector's provider rotates the refresh token on a refresh, and the save of the new tokens then fails briefly, for example on a dropped database connection, the router saves them again up to twice in the next 300 ms. Before, the connection stayed `needs_reauthorization` and the person had to reconnect the account. If every save fails, the router logs an error with the connection's id, and the connection still needs a reconnect (AI-3504). -### A moved app keeps who asked not to be reached - -`GET /v1/data/export` and `GET /v1/data/changes` now carry the app's opt-outs, so a recipient who texted STOP is still opted out where the app moved to, and a STOP or START at the source after the copy arrives with the other changes. An opt-out already live at the destination for the same recipient and channel is kept, and an imported revoked opt-out lifts only the row it was copied from. A copy taken again after a START and a new STOP at the source keeps the recipient opted out (AI-3489). - ### An SMS reply sets its price aside before it is sent A text is priced by its direction and destination country, and its reservation is now priced with them too, as its billed row is. An SMS reply or notice sets aside what Telnyx will bill for it, its link and each MMS of up to ten files included, before Telnyx is asked, and one the organization's credit cannot cover is refused there, with no send and no row; before, it reserved nothing and was sent (AI-3182). From ec7029733387c0548f32d23eb8816b2828dc0a1e Mon Sep 17 00:00:00 2001 From: thesyncim Date: Mon, 23 Nov 2026 14:42:06 +0000 Subject: [PATCH 5/6] fix(store): an app holding only opt-outs imports without full, and an imported row keeps an opt-out here on its recipient --- acceleration/internal/api/datamove_test.go | 14 +++++ acceleration/internal/store/datamove.go | 11 +++- acceleration/internal/store/datamove_test.go | 60 ++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/acceleration/internal/api/datamove_test.go b/acceleration/internal/api/datamove_test.go index 7fe376d302..69fdebe198 100644 --- a/acceleration/internal/api/datamove_test.go +++ b/acceleration/internal/api/datamove_test.go @@ -242,6 +242,20 @@ func (s *DataMoveSuite) TestAnExportIsNotWrittenOverAnAppThatHoldsDataWhenFullIs s.Equal("edited here", s.instructionsOf(agent.Id)) } +// Defect: an app whose only rows here are opt-outs had an import refused without full. +func (s *DataMoveSuite) TestAnAppHoldingOnlyAnOptOutImportsWithoutFull() { + s.Require().NoError(s.store.OptOuts.Insert(context.Background(), &store.OptOut{ + CustomerID: s.customerID(), Recipient: "+15550001112", Channel: "sms", Source: "keyword", + })) + exported := s.export() + + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodPost, "/v1/data/import", ndjson(exported), nil)) + + optedOut, err := s.store.OptOuts.OptedOut(context.Background(), s.customerID(), "+15550001112", "sms") + s.Require().NoError(err) + s.True(optedOut) +} + // A lookup that fails is not an answer that the app holds nothing: the export is not written. func (s *DataMoveSuite) TestAnExportIsNotWrittenWhenWhatTheAppHoldsCannotBeRead() { agent := s.data.createAgentConfig() diff --git a/acceleration/internal/store/datamove.go b/acceleration/internal/store/datamove.go index 1bab9c0703..5a2cf75a9d 100644 --- a/acceleration/internal/store/datamove.go +++ b/acceleration/internal/store/datamove.go @@ -870,6 +870,11 @@ func (s *Store) importRow(ctx context.Context, db bun.IDB, customerID, table str if table == "phone_numbers" { conflict += " AND NOT " + boughtHere("phone_numbers") } + // An opt-out here stays on the recipient and channel it was recorded for: a row arriving + // under its id for another one neither moves nor lifts it. + if table == "opt_outs" { + conflict += " AND opt_outs.recipient = EXCLUDED.recipient AND opt_outs.channel = EXCLUDED.channel" + } // Every writer of a log draws its id under its customer's lock (AgentLogs.Insert), so ids // commit in order and a reader resuming after one misses none. The row is read through the @@ -1971,10 +1976,12 @@ func dataTableByName(name string) (dataTable, bool) { // shared database, empty when none does. A table kept in the shards is left out: it holds the // customer's own traffic here, and a shard's pod reads only its own shard, so counting it would // make the answer depend on which pod runs. A table that belongs to a customer through a parent -// is left out too: its rows are written only under a parent of the customer's. +// is left out too: its rows are written only under a parent of the customer's. So are opt-outs: +// an import keeps one recorded here live (importRow), so an app holding only those holds nothing +// an export would write over. func (s *Store) HoldingTable(ctx context.Context, customerID string) (string, error) { for _, table := range dataTables { - if table.customer == "" || table.shard { + if table.customer == "" || table.shard || table.name == "opt_outs" { continue } where := table.customer + " = ?" diff --git a/acceleration/internal/store/datamove_test.go b/acceleration/internal/store/datamove_test.go index 923d44df11..5c8b2e51ab 100644 --- a/acceleration/internal/store/datamove_test.go +++ b/acceleration/internal/store/datamove_test.go @@ -513,6 +513,66 @@ func (s *DataMoveSuite) TestAnImportedRevokedOptOutDoesNotLiftOneRecordedHere() s.Require().NoError(err) s.Require().Len(live, 1) s.Equal(here.ID, live[0].ID) + s.Len(s.exportFrom(s.destination, "moved").of("opt_outs"), 2, "the revoked copy is kept beside it as history") +} + +// Defect: a live opt-out here on another channel kept the source's one out. +func (s *DataMoveSuite) TestAnOptOutHereOnAnotherChannelDoesNotKeepOneOut() { + s.Require().NoError(s.destination.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "moved", Recipient: "+12025550107", Channel: "voice", Source: "keyword"})) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550107", Channel: "sms", Source: "keyword"})) + + s.move("acme", "moved") + + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550107", "sms") + s.Require().NoError(err) + s.True(optedOut) +} + +// Defect: a live opt-out here for another recipient kept the source's one out. +func (s *DataMoveSuite) TestAnOptOutHereForAnotherRecipientDoesNotKeepOneOut() { + s.Require().NoError(s.destination.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "moved", Recipient: "+12025550108", Channel: "sms", Source: "keyword"})) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550109", Channel: "sms", Source: "keyword"})) + + s.move("acme", "moved") + + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550109", "sms") + s.Require().NoError(err) + s.True(optedOut) +} + +// Defect: another app's live opt-out here for the same recipient kept the source's one out. +func (s *DataMoveSuite) TestAnotherAppsOptOutHereDoesNotKeepOneOut() { + s.Require().NoError(s.destination.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "other", Recipient: "+12025550110", Channel: "sms", Source: "keyword"})) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550110", Channel: "sms", Source: "keyword"})) + + s.move("acme", "moved") + + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550110", "sms") + s.Require().NoError(err) + s.True(optedOut) +} + +// Defect: an imported row under the id of an opt-out recorded here, for another recipient or +// channel, moved that opt-out off what it was recorded for, or lifted it. +func (s *DataMoveSuite) TestAnImportedRowUnderTheIdOfAnOptOutHereLeavesItsRecipientOptedOut() { + here := OptOut{CustomerID: "moved", Recipient: "+12025550111", Channel: "sms", Source: "keyword"} + s.Require().NoError(s.destination.OptOuts.Insert(s.ctx, &here)) + s.Require().NoError(s.source.OptOuts.Insert(s.ctx, &OptOut{CustomerID: "acme", Recipient: "+12025550112", Channel: "sms", Source: "keyword"})) + + s.Require().NoError(s.importEdited("opt_outs", "moved", func(row map[string]any) { row["id"] = here.ID })) + optedOut, err := s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550111", "sms") + s.Require().NoError(err) + s.True(optedOut, "a live row for another recipient") + + s.Require().NoError(s.importEdited("opt_outs", "moved", func(row map[string]any) { + row["id"] = here.ID + row["recipient"] = here.Recipient + row["channel"] = "voice" + row["revoked_at"] = time.Now().UTC().Format(time.RFC3339Nano) + })) + optedOut, err = s.destination.OptOuts.OptedOut(s.ctx, "moved", "+12025550111", "sms") + s.Require().NoError(err) + s.True(optedOut, "a revoked row for another channel") } // Defect: an imported opt-out that names no recipient was stored, one the API refuses. From cb3f59ff0f689506e9349fe0d9a84bab1ffcddd2 Mon Sep 17 00:00:00 2001 From: thesyncim Date: Mon, 23 Nov 2026 15:18:21 +0000 Subject: [PATCH 6/6] test(api): import an app's opt-outs into a fresh app, so no activity row makes it held --- acceleration/internal/api/datamove_test.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/acceleration/internal/api/datamove_test.go b/acceleration/internal/api/datamove_test.go index 69fdebe198..5898ab87a7 100644 --- a/acceleration/internal/api/datamove_test.go +++ b/acceleration/internal/api/datamove_test.go @@ -244,16 +244,24 @@ func (s *DataMoveSuite) TestAnExportIsNotWrittenOverAnAppThatHoldsDataWhenFullIs // Defect: an app whose only rows here are opt-outs had an import refused without full. func (s *DataMoveSuite) TestAnAppHoldingOnlyAnOptOutImportsWithoutFull() { - s.Require().NoError(s.store.OptOuts.Insert(context.Background(), &store.OptOut{ - CustomerID: s.customerID(), Recipient: "+15550001112", Channel: "sms", Source: "keyword", - })) + ctx := context.Background() + s.Require().NoError(s.store.OptOuts.Insert(ctx, &store.OptOut{CustomerID: s.customerID(), Recipient: "+15550001112", Channel: "sms", Source: "keyword"})) exported := s.export() + for i, line := range exported { + if line.Table == "opt_outs" { + exported[i].Row = s.withID(line.Row, store.NewID()) + } + } + s.useApp(s.data.createApp()) // has made no request, so no activity row + s.Require().NoError(s.store.OptOuts.Insert(ctx, &store.OptOut{CustomerID: s.customerID(), Recipient: "+15550001113", Channel: "sms", Source: "keyword"})) s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodPost, "/v1/data/import", ndjson(exported), nil)) - optedOut, err := s.store.OptOuts.OptedOut(context.Background(), s.customerID(), "+15550001112", "sms") - s.Require().NoError(err) - s.True(optedOut) + for _, recipient := range []string{"+15550001112", "+15550001113"} { + optedOut, err := s.store.OptOuts.OptedOut(ctx, s.customerID(), recipient, "sms") + s.Require().NoError(err) + s.True(optedOut, recipient) + } } // A lookup that fails is not an answer that the app holds nothing: the export is not written.