Skip to content

[No QA] Reduce unsafe type assertions in SplitDistanceMessage tests - #95938

Merged
blimpich merged 5 commits into
Expensify:mainfrom
KJ21-ENG:sbf/job6-94739-splitdistancemessage-test
Jul 14, 2026
Merged

blimpich merged 5 commits into
Expensify:mainfrom
KJ21-ENG:sbf/job6-94739-splitdistancemessage-test

Conversation

@KJ21-ENG

@KJ21-ENG KJ21-ENG commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

This is a test-only TypeScript cleanup for SplitDistanceMessage coverage. It removes the remaining unsafe type assertions tied to @typescript-eslint/no-unsafe-type-assertion while preserving the existing test scenarios and expectations.

What changed:

  • Typed the test fixture objects directly as Transaction and Report values so the compiler validates their shape without trailing assertions.
  • Added typed Onyx update aliases based on UpdateMoneyRequestDataKeys and OnyxUpdate.
  • Replaced repeated Partial assertions with small runtime guards that narrow unknown Onyx entry values before reading transaction fields.
  • Updated optimistic and failure-data entry lookups to rely on typed predicates, keeping the same assertions for self-DM split and split-distance behavior.

Why this approach is safe:

  • Only tests/actions/IOUTest/SplitDistanceMessageTest.ts changed, so production runtime behavior is untouched.
  • The cleanup preserves the same setup data, getUpdateMoneyRequestParams inputs, and expectations.
  • The new guards only affect how the test identifies matching Onyx entries; they do not alter the function under test.
  • QA classification remains No QA: test-only cleanup.

Reviewer focus:

  1. Check that the new type guards accurately distinguish the selfDM-specific optimistic and failure entries from the normal transaction updates.
  2. Confirm the OnyxUpdate typing matches the data returned by getUpdateMoneyRequestParams.
  3. Verify that removing the fixture assertions does not weaken the intended test data shape.

Safety checks:

  • Typecheck, targeted lint, eslint-report, and formatting commands are covered by the server-rendered verification section.
  • No offline tests, screenshots, platform QA, or high-traffic testing are applicable for this test-only cleanup.

Fixed Issues

$ #94739
PROPOSAL:
$ #94739 by tightening the test helper typing in tests/actions/IOUTest/SplitDistanceMessageTest.ts instead of casting Onyx entries at each assertion site.

Count change

Current baseline source:

  • config/eslint/eslint.seatbelt.tsv
  • Target files: tests/actions/IOUTest/SplitDistanceMessageTest.ts
  • Target Rule: @typescript-eslint/no-unsafe-type-assertion

Before:

  • Target before warnings: 12
  • Before warnings: 5295

After:

  • Target after warnings: 0
  • After warnings: 5283

Net reduction:

  • Target warning reduction: 12
  • Net warning reduction: 12

TSV evidence:

  • OSBotify note: TSV row deletions were restored before commit because OSBotify tightens the baseline.

Exact verification commands:

  • npm run typecheck
  • npm run lint -- --no-cache --show-warnings tests/actions/IOUTest/SplitDistanceMessageTest.ts
  • npm run eslint-report
  • npm run fmt -- tests/actions/IOUTest/SplitDistanceMessageTest.ts

Tests

  1. Run:

      npm run typecheck
    

    Verify the command succeeds and produces the expected evidence.

  2. Run:

      npm run lint -- --no-cache --show-warnings tests/actions/IOUTest/SplitDistanceMessageTest.ts
    

    Verify the command succeeds and produces the expected evidence.

  3. Run:

      npm run eslint-report
    

    Verify the command succeeds and produces the expected evidence.

  4. Run:

      npm run fmt -- tests/actions/IOUTest/SplitDistanceMessageTest.ts
    

    Verify the command succeeds and produces the expected evidence.

  5. Verify the target count decreased from 12 to 0, and total warnings decreased from 5295 to 5283.

Offline tests

Not applicable: this cleanup changes only a TypeScript test file and has no network-dependent runtime behavior.

QA Steps

[No QA]

Not applicable: this is a test-only cleanup with no staging UI or production workflow change.

PR Author Checklist

For checklist items that are not applicable to this cleanup, checked means the item was considered and determined not applicable.

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline tests section — Not applicable to this test-only cleanup.
    • I added steps for Staging and/or Production testing in the QA steps section — Not applicable to this test-only cleanup.
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct) — Not applicable to this test-only cleanup.
    • 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) — Not applicable to this test-only cleanup.
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability). — Not applicable to this test-only cleanup.
  • I included screenshots or videos for tests on all platforms — Not applicable to this test-only cleanup.
  • I ran the tests on all platforms & verified they passed on: — Not applicable to this test-only cleanup.
    • Android: Native — Not applicable to this test-only cleanup.
    • Android: mWeb Chrome — Not applicable to this test-only cleanup.
    • iOS: Native — Not applicable to this test-only cleanup.
    • iOS: mWeb Safari — Not applicable to this test-only cleanup.
    • MacOS: Chrome / Safari — Not applicable to this test-only cleanup.
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed) — Not applicable to this test-only cleanup.
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory — Not applicable to this test-only cleanup.
    • 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. — Not applicable to this test-only cleanup.
    • 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) — Not applicable to this test-only cleanup.
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers — Not applicable to this test-only cleanup.
  • I followed the guidelines as stated in the Review Guidelines — Not applicable to this test-only cleanup.
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected) — Not applicable to this test-only cleanup.
  • If a new CSS style is added I verified that: — Not applicable to this test-only cleanup.
    • A similar style doesn't already exist — Not applicable to this test-only cleanup.
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)) — Not applicable to this test-only cleanup.
  • If new assets were added or existing ones were modified, I verified that: — Not applicable to this test-only cleanup.
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg) — Not applicable to this test-only cleanup.
    • The assets load correctly across all supported platforms. — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.
  • 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 Avatar is modified, I verified that Avatar is working as expected in all cases) — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.
  • 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. — Not applicable to this test-only cleanup.
  • 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: — Not applicable to this test-only cleanup.
    • I verified that all the inputs inside a form are aligned with each other. — Not applicable to this test-only cleanup.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes. — Not applicable to this test-only cleanup.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps. — Not applicable to this test-only cleanup.

Screenshots/Videos

Not applicable: no UI or visual behavior changed.

Target rule: @typescript-eslint/no-unsafe-type-assertion
Target files: tests/actions/IOUTest/SplitDistanceMessageTest.ts
Verification: completed
Generated TSV restored: yes
@KJ21-ENG
KJ21-ENG marked this pull request as ready for review July 13, 2026 11:41
@KJ21-ENG
KJ21-ENG requested a review from a team as a code owner July 13, 2026 11:41
@melvin-bot
melvin-bot Bot requested a review from blimpich July 13, 2026 11:41
@melvin-bot

melvin-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

@blimpich 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]

Comment on lines +133 to +143
function isObject(value: unknown): value is Record<PropertyKey, unknown> {
return value !== null && typeof value === 'object';
}

function hasDefinedProperty(value: unknown, property: PropertyKey) {
return isObject(value) && property in value && value[property] !== undefined;
}

function hasDefinedAmount(value: unknown): value is Partial<Transaction> & Pick<Transaction, 'amount'> {
return isObject(value) && typeof value.amount === 'number';
}

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.

These are all fairly generic methods. And they are named that way as well. Would it not make sense to extract them out into some util or helper file, or even their own dedicated files like we did with tests/utils/createMock.ts so that they can be reused?

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.

Agreed. I’ll extract the generic isObject and defined-property checks into tests/utils/typeGuards.ts, then reuse them from the related test PRs. I’ll keep hasDefinedAmount local because it is specific to the split-distance fixture and is not a general-purpose guard.

@blimpich
blimpich self-requested a review July 13, 2026 21:23
@codecov

codecov Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 11 files with indirect coverage changes

@blimpich

Copy link
Copy Markdown
Contributor

failing js test 😢

@KJ21-ENG

Copy link
Copy Markdown
Contributor Author

Thanks for flagging this. The failing Jest test was caused by an existing main branch issue in ExportOnyxStateTest, where companyCardsLoadingState_ was missing from the safe Onyx keys. The latest main includes that fix, and I merged it into this PR.

@blimpich

Copy link
Copy Markdown
Contributor

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 Issues section 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 Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • 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 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 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)
  • 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 using Avatar have 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
    • 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
    • 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 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 Avatar is modified, I verified that Avatar is 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 Design label and/or tagged @Expensify/design so 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 main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
iOS: mWeb Safari
MacOS: Chrome / Safari

@blimpich
blimpich merged commit 2790fa4 into Expensify:main Jul 14, 2026
28 checks passed
@OSBotify OSBotify mentioned this pull request Jul 16, 2026
94 tasks done
@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/blimpich in version: 9.4.35-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/jasperhuangg in version: 9.4.35-6 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants