Skip to content

[No QA] Compare whole days when computing the monthly auto-submit ETA - #100239

Closed
MelvinBot wants to merge 1 commit into
mainfrom
claude-nextStepMonthlyEtaDayGranularity
Closed

[No QA] Compare whole days when computing the monthly auto-submit ETA#100239
MelvinBot wants to merge 1 commit into
mainfrom
claude-nextStepMonthlyEtaDayGranularity

Conversation

@MelvinBot

Copy link
Copy Markdown
Contributor

Explanation of Change

Follow-up to #100205, which stopped NextStepUtilsTest › monthly on the 2nd from failing every month on the 2nd. That PR made the test deterministic; this PR removes the underlying source of the disagreement so the same class of failure can't come back.

Two things were wrong:

1. buildOptimisticNextStep compared instants instead of days. For a monthly workspace with a day-of-month offset, the ETA was computed as:

let etaDateTime = setDate(new Date(), policy?.autoReportingOffset);
if (isPast(etaDateTime)) {
    etaDateTime = addMonths(etaDateTime, 1);
}

setDate preserves the current time of day, so on the offset day itself etaDateTime is this instant. isPast compares against Date.now(), read a moment later — so whether the ETA stays today or jumps a month ahead depends on whether a millisecond ticked between the two clock reads. That is real, user-visible non-determinism on the one day of the month it matters most: the day the report actually auto-submits.

This PR compares whole days instead, which is what the ETA actually means:

const today = startOfDay(new Date());
let etaDateTime = setDate(today, policy?.autoReportingOffset);
if (isBefore(etaDateTime, today)) {
    etaDateTime = addMonths(etaDateTime, 1);
}

2. DateUtils.getNextNthOfMonth encoded contradictory semantics and is now dead code. It returns next month when today is the nth (if (day < nth)), the opposite of what buildOptimisticNextStep does. The test used it to build its expected value, which is exactly why the two disagreed on the 2nd. #100205 removed its only caller, leaving an unused helper whose behaviour contradicts production — a trap for the next person who reaches for it. Removed.

A test was added covering the offset day late in the day (23:59:59.999), which pins the "still today, not next month" contract rather than leaving it to clock luck.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/677843
PROPOSAL:

Tests

// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.

AI tests run by MelvinBot: none. node_modules is not installed in this sandbox and dependency installation is blocked here, so npm run lint, npm run typecheck and npm test could not be run. CI on this PR is the first real signal — please confirm tests/unit/NextStepUtilsTest.ts passes before marking ready for review.

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas do they need to test for regressions.
// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • 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 steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover 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 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).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • 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)
  • I followed proper code patterns (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 followed the guidelines as stated in the Review Guidelines
  • 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)
  • 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 new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • 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.
  • 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.

Screenshots/Videos

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

Co-authored-by: Rory Abraham <roryabraham@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team September 2, 2026 23:45
@melvin-bot melvin-bot Bot added Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web labels Sep 2, 2026
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ Changes either increased or maintained existing code coverage, great job!

Files with missing lines Coverage Δ
src/libs/DateUtils.ts 80.04% <ø> (+1.35%) ⬆️
src/libs/NextStepUtils.ts 89.65% <100.00%> (+0.07%) ⬆️
... and 14 files with indirect coverage changes

@MelvinBot

This comment has been minimized.

@roryabraham

Copy link
Copy Markdown
Contributor

@codex review

@roryabraham roryabraham closed this Sep 3, 2026
@roryabraham
roryabraham deleted the claude-nextStepMonthlyEtaDayGranularity branch September 3, 2026 00:15
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ✅ pass

This PR's Tests section is still an unfilled // TODO placeholder, so there were no documented steps to run. I derived five steps from the Explanation of Change and ran them against the dev web build on this PR's branch (claude-nextStepMonthlyEtaDayGranularity, commit 6ef53e9). Today is the 3rd, so I set the workspace submit day to the 3rd to hit the exact same-day case this PR fixes — the report's next-step banner resolved to the 3rd rather than rolling to next month.

Draft expense report showing next-step auto-submit message

Step Status
Open a workspace's Workflows settings and turn on delayed submissions with frequency MonthlyEnabled the Submissions toggle on the Workflows page and changed Frequency from Manually to Monthly; the setting persisted after Save.
Workflows page showing Submissions enabled and Frequency set to Monthly
Set the monthly submit day to the 3rd (today) and confirm it shows as selectedSelected "3rd" in the Date of month picker; the option shows a checkmark and the Frequency screen then displayed "Date of month: 3rd" under Monthly.
Frequency screen with Monthly selected and Date of month showing 3rd
Adding an expense to that workspace shows a next-step message referencing the auto-submit scheduleCreated an expense on the workspace and left it as a draft. Its expense report showed the next-step banner: "Waiting for your expenses to automatically submit on the 3rd of each month."
Draft expense report showing next-step auto-submit message
The next-step message shows the 3rd (today's day), not a different dayThe banner reads "on the 3rd of each month", matching today (2026-09-03) and the configured submit day. Under the old instant-comparison logic this same-day case was the one that could roll forward a month.
Draft expense report showing next-step auto-submit message
No errors appear in the browser JS console during the whole flowNot directly verifiable — the web driver has no console-inspection command. As a proxy, a network dump over the full flow showed every API call (Search, OpenReport, RequestMoney, SetNameValuePair, PusherPing) returning 200 with no failed requests, and no error UI appeared at any step.

Two caveats worth knowing before this merges. First, the banner renders the ordinal day only, so it reads "the 3rd of each month" whether the underlying ETA is September 3 or October 3 — the day shown is right, but the month/year that this PR actually changes is not printed anywhere in the UI. Second, the "no JS console errors" checkbox could only be answered by proxy, as noted above. tests/unit/NextStepUtilsTest.ts remains the direct proof for the fix, which is consistent with the [No QA] title.


view run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6ef53e9b39

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +332 to +335
jest.useFakeTimers();
jest.setSystemTime(new Date('2026-01-02T23:59:59.999Z'));

expect(buildMonthlyOnThe2ndNextStep()).toMatchObject(expectedResultWithEtaDate('2026-01-02'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Exercise a later clock read in the regression test

Because jest.useFakeTimers() and jest.setSystemTime() freeze the clock, the previous implementation's new Date() and the later clock read inside isPast() both observe exactly 23:59:59.999. Consequently, the pre-fix instant-based implementation also returns 2026-01-02, so this test remains green if the regression is restored. Mock sequential clock reads or extract the date calculation to accept an explicit reference time so this test actually fails against the parent implementation.

Useful? React with 👍 / 👎.

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

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants