Skip to content

fix: stop using broken addTeamMemberInternal in testCreateOne2OneWith - #5420

Merged
blackheaven merged 6 commits into
developfrom
gdifolco/fix-flaky-tests-conversation-binding
Aug 7, 2026
Merged

fix: stop using broken addTeamMemberInternal in testCreateOne2OneWith#5420
blackheaven merged 6 commits into
developfrom
gdifolco/fix-flaky-tests-conversation-binding

Conversation

@blackheaven

Copy link
Copy Markdown
Contributor

Checklist

  • Add a new entry in an appropriate subdirectory of changelog.d
  • Read and follow the PR guidelines

…Members

The test intermittently failed with a 500 from galley's internal
POST i/teams/:tid/members endpoint (uncheckedAddTeamMember), reached
via the addTeamMemberInternal helper. That helper is documented as
broken (SQSERVICES-471): it force-adds an existing user through a
path that fans out synchronous brig RPCs (getSize/getUser/
getAppIdsForTeam) plus Cassandra writes and SQS journaling, any of
which can transiently exhaust its retries and surface as an unhandled
500 server-error.

Switch to addUserToTeamWithRole, the proper brig invitation flow that
updates both brig and galley and is used by every sibling test in this
file. The member-join event is now asserted on the owner's WebSocket
(the invitee is created inside the call and cannot have a
pre-established connection), matching the testAddTeamConvWithRole
precedent (Teams.hs:679-680). Also corrects the misleading doc-comment
on the role parameter.
@blackheaven
blackheaven requested a review from a team as a code owner August 5, 2026 10:29
@zebot zebot added the ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist label Aug 5, 2026

@battermann battermann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If addTeamMemberInternal is broken, can we remove it from Util, too?

Also could this test be migrated to the integration package, and be removed here all together?

Addresses @battermann's review on #5420.

1. Remove the broken `Util.addTeamMemberInternal` helper (SQSERVICES-471).
   All 14 call sites migrate to the proper invitation flow:
   - standard-role sites -> `addUserToTeamWithRole`
   - custom-permission sites -> `addUserToTeamWithRole` + new
     `updateTeamMemberPermissions` (public PUT /teams/:tid/members)
   - `testAddTeamMemberInternal` keeps inlined coverage of the internal
     add-member endpoint (its purpose; the invite flow cannot reproduce
     the member-websocket event assertion)
   - `testAddTeamMemberToConv` and `testCannotCreateLegalHoldDeviceOldAPI`
     restructured to mint members via the invitation flow. In
     `testAddTeamMemberToConv` the same-team members are no longer passed
     to `connectUsers` (same-binding-team connection requests are rejected
     with 403; those assertions are satisfied by the same-team condition).

2. Port `testCreateOne2OneWithMembers` and
   `testCreateOne2OneFailForNonTeamMembers` to the Testlib /integration
   package (`Test.One2OneTeamConv`) and remove them from galley. The
   galley-specific `assertTeamUpdate` (SQS queue) is replaced by a
   member-count check plus the real-time member-join websocket event.

Cleanup: collapse `makeOwner` onto `updateTeamMemberPermissions`; delete
the now-dead `createOne2OneTeamConv` helper.

Compile-verified (exe:galley-integration + integration); runtime deferred
to CI. `testAddTeamMemberToConv` was restructured and is the most
behaviour-sensitive change.
@blackheaven
blackheaven requested a review from battermann August 5, 2026 11:49
@blackheaven

Copy link
Copy Markdown
Contributor Author

I have migrated everything

@battermann battermann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve because these are just tests, but please still consider my comments.

Comment thread integration/test/Test/One2OneTeamConv.hs
Comment thread integration/test/Test/One2OneTeamConv.hs Outdated
Comment on lines +445 to +451
g <- viewGalley
post
( g
. paths ["i", "teams", toByteString' tid, "members"]
. json (Member.mkNewTeamMember (mem1 ^. userId) (mem1 ^. permissions) (mem1 ^. invitation))
)
!!! const 200 === statusCode

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a bit weird that the function is removed from Util but is inlined here. Is there a forcing reason for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, testAddTeamMemberInternal is the test for the internal POST /i/teams/:tid/members endpoint (formerly Util.addTeamMemberInternal), so it has to hit it directly. The helper was removed from Util precisely because it's a footgun: it bypasses the invitation flow (SQSERVICES-471), so re-exposing it as a reusable helper would tempt other tests to reach for it. I added a comment recording the reasoning next to the call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But do we need to test it still? can we remove the endpoint all together even?

…d internal endpoint

Follow-up to ad1336f addressing remaining review comments on #5420.

1. In testCreateOne2OneWithMembers, replace the manual Control.Retry.retrying
   block with the idiomatic `eventually (... >>= assertStatus 201)`, which
   retries on AssertionFailure every 100ms up to the suite timeout - the same
   "retry until 201" semantics in one line. Drop the now-dead Control.Retry
   import.

2. In testAddTeamMemberInternal, add a comment explaining why the internal
   POST /i/teams/:tid/members call is inlined rather than re-exposed as a
   helper: that endpoint bypasses the invitation flow and must not be reused by
   other tests (SQSERVICES-471).

Compile-verified (integration + exe:galley-integration) under -Werror;
runtime deferred to CI.
@blackheaven
blackheaven merged commit 27bb127 into develop Aug 7, 2026
9 checks passed
@blackheaven
blackheaven deleted the gdifolco/fix-flaky-tests-conversation-binding branch August 7, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ok-to-test Approved for running tests in CI, overrides not-ok-to-test if both labels exist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants