Repository navigation
[NoQA] Log the reason for every sign-out - #101882
Conversation
Three gaps made a copilot sign-out incident unreadable straight from the logs. This closes all three. No behaviour changes: no control flow, condition, order, clear list, or guard moved. signOutAndRedirectToSignIn puts the signOutReason it already receives into the Log.info payload. The sentence stays word for word so existing queries keep matching, and the reason is now what identifies which of its many callers ran. Both sites that sign the current user out for a transition link now log one line each, with its own prefix, carrying the session email against the link's email and delegatorEmail plus the authTokenType. Those are the values the decision compares, so one row answers which account the link named and how it differed from the session. A read-only SessionUtils helper reads the two params the same way isLoggingInAsNewUser does, so no token value and no full URL can reach a log payload. The missing-credentials branch of reauthenticate reports through trackAuthenticationError, as the two branches below it already do. It only ever logged, so a session that had lost its credentials left no Sentry event and the 407s that followed it looked unexplained. It reuses the reason string that branch already passes to redirectToSignIn. Sentry events also carry an auth_token_type tag, set where the user context is set and cleared with the session, so copilot and supportal failures are findable by that tag instead of only by role. Tests cover the two contracts that are cheap to pin: the sign-out log payload carries the reason, and the missing-credentials branch reports. The helper that feeds the transition log lines is covered directly, including that it never returns a credential. Issue: callstack-internal/expensify-issues#2991
AuthScreensInitHandlerTest mocks SessionUtils with a hand-written factory, and that factory did not know about getTransitionLinkEmailParams, so the new transition log line threw a TypeError inside the mount effect and the sign-out test failed. The mock now provides the function, with a beforeEach default that matches the other mocked lookups. Running only the two suites I first touched missed this, because the failure sits in a test for the file I consumed rather than the file I edited. That test now also asserts the payload of the new decision line, which is the only coverage proving the transition log carries the session email against the link's email and delegatorEmail. The exported TransitionLinkEmailParams type had no importer, so knip counted a new unused export. The type stays in the module as the function's return annotation. Oxfmt wrapped two long lines I had added, in SessionUtils and its test, so the fmt diff check CI runs comes out clean.
The comments added with this work explained the diff to a reader rather than the code, so they are gone. What stays is the Given/When/Then lines the repository test guide asks for, and one JSDoc on getTransitionLinkEmailParams, which records that URLSearchParams mangles the first query key of a full URL and that the raw lookup is the fallback. That is a quirk of external code, not a note about this change. The transition-link reader lost five table rows that only restated what URLSearchParams does, and its assertions name the fields now instead of comparing the whole returned object. Every kept test was checked against a mutation of the line it covers: dropping the raw-value fallback, returning the link token next to the accounts, reading the email from an unrelated param, dropping signOutReason from the log payload, deleting the missing-credentials report, and deleting the transition log line. All six went red, and the suites went green again with the lines restored.
clearStorageAndRedirect now logs the signOutReason it receives. Every sign-out passes through it, so one line names the caller for all of them. The two places that sign a user out because of a transition link each log whether the link named a delegator, whether the current session is a copilot session, and whether it is a support session. The line carries no email, URL or token. This replaces the earlier changes on this branch. The Sentry report, the auth token type tag, the transition link helper and their tests are gone.
The change only adds log lines, so it ships without a new test. The existing suites for the touched screens still run.
|
@parasharrajat Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
parasharrajat
left a comment
There was a problem hiding this comment.
Reviewer Checklist
- I have verified the author checklist is complete (all boxes are checked off).
- I verified the correct issue is linked in the
### Fixed Issuessection above - I verified testing steps are clear and they cover the changes made in this PR
- I verified the steps for local testing are in the
Testssection - I verified the steps for Staging and/or Production testing are in the
QA stepssection - I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
- I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
- I verified the steps for local testing are in the
- I checked that screenshots or videos are included for tests on all platforms
- I included screenshots or videos for tests on all platforms
- I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
- I verified tests pass on all platforms & I tested again on:
- Android: HybridApp
- Android: mWeb Chrome
- iOS: HybridApp
- iOS: mWeb Safari
- MacOS: Chrome / Safari
- If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
- I verified proper code patterns were followed (see Reviewing the code)
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
toggleReportand notonIconClick). - I verified that comments were added to code that is not self explanatory
- I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
- I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
- I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e.
- If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
- I verified that this PR follows the guidelines as stated in the Review Guidelines
- I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like
Avatar, I verified the components usingAvatarhave been tested & I retested again) - If a new component is created I verified that:
- A similar component doesn't exist in the codebase
- All props are defined accurately and each prop has a
/** comment above it */ - The file is named correctly
- The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
- The only data being stored in the state is data necessary for rendering and nothing else
- For Class Components, any internal methods passed to components event handlers are bound to
thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor) - Any internal methods bound to
thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick) - All JSX used for rendering exists in the render method
- The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
- If any new file was added I verified that:
- The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
- If a new CSS style is added I verified that:
- A similar style doesn't already exist
- The style can't be created with an existing StyleUtils function (i.e.
StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
- If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
- If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avataris modified, I verified thatAvataris working as expected in all cases) - If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
- If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
- If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
- I verified that all the inputs inside a form are aligned with each other.
- I added
Designlabel and/or tagged@Expensify/designso the design team can review the changes.
- For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
- If the
mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps. - I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.
🎀 👀 🎀 C+ reviewed
|
🚧 mountiny has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.94-0 🚀
|
|
No help site changes are needed for this PR, so I didn't create a docs PR. This PR only adds internal log lines that record why a sign-out happened. It doesn't change any screen, button, label, setting, or sign-out behavior. Nothing in What changed
|
|
🚀 Deployed to production by https://github.com/Julesssss in version: 9.4.94-0 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Every sign-out used to log the same generic line whatever caused it. Now each one logs its reason, so the logs tell these apart (and all future cases too):
Fixed Issues
$ #102131
PROPOSAL: N/A
Tests
This change only adds log lines, so it has no new test. The existing suites for the touched screens still pass.
npx jest tests/ui/AuthScreensInitHandlerTest.tsx tests/ui/SessionTest.tsx.Verify that no errors appear in the JS console
No manual UI testing was done. The change adds three log lines and changes no behavior.
Offline tests
No offline behavior changes. The new log lines sit in code that already runs offline.
QA Steps
No QA steps apply. Nothing changes on screen.
Verify that no errors appear in the JS console
No build was made for this change, so nothing was checked on a device.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari