Skip to content

Copy UK fuel-band rates with their reclaimable fraction and check it for the lightning bolt - #104309

Open
MelvinBot wants to merge 9 commits into
mainfrom
claude-ukFuelBandGovernmentRates
Open

MelvinBot wants to merge 9 commits into
mainfrom
claude-ukFuelBandGovernmentRates

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The UK publishes fuel-band mileage rates alongside its standard (AMAP) rate. The server will copy the bands, with their VAT-reclaimable fraction, only to workspaces that track tax and have distance tax on, and AMAP to every other workspace. The App's optimistic copy didn't know about bands, so it would have added AMAP plus every band, without the fraction. The lightning bolt also ignored the reclaimable amount, so an edited band still looked auto-generated.

  • Types: GovernmentMileageRate and GovernmentRateSnapshot get an optional taxClaimablePercentage.
  • Picking rates: buildOnyxDataForGovernmentRateAutoUpdate uses isTaxTrackingEnabled(true, policy, true) as shouldUseFuelBandRates. For GB rates only, it copies the bands when that is true and the standard rate otherwise. Other countries are unaffected.
  • Series: the new getGovernmentRateSeries strips the trailing _<startDate> with lastIndexOf('_'), so band IDs like GB_PETROL_UP_TO_1400_2026-06-01 (whose band names contain _) resolve to GB_PETROL_UP_TO_1400.
  • New fields on copied rates: taxClaimablePercentage goes on the rate and its snapshot when the reference rate has one. enabled comes from the previous rate in the same series, ordered by the snapshot's start date and including rates copied earlier in the same request. It only does so when that previous rate is an unmodified government rate. If the previous rate was edited, or there is none, the copied rate is enabled. taxRateExternalID is left to the server response.
  • Signature: buildOnyxDataForGovernmentRateAutoUpdate now takes policy instead of policyID + customUnit, which are derived inside. It also reads the previous auto-update flag and country from policy for the failure data. setWorkspaceDistanceAutoUpdate takes policy, the new flag, the reference rates and an optional country. It reads the currency from policy.
  • Currency change: when auto-update is on and the currency changes to one that maps to a single country (GBP, USD, CAD, AUD), updateGeneralSettings now copies that country's rates optimistically and sends optimisticRateIDs. governmentRateCountry is only sent for EUR.
  • Lightning bolt: when the snapshot has a reclaimable fraction, isGovernmentRateUnmodified also compares the reclaimable amount at the 4-decimal precision the edit page shows. Re-entering the shown value therefore brings the bolt back. Snapshots without a fraction, such as US/EUR rates, ignore it as before. The edit page now uses the same getTaxClaimableDisplayAmount helper, and its useCallback was removed so React Compiler can still compile the component.

Note: the enabled inheritance applies to every country's copied rates, following the rule in the issue description.

AI tests run by MelvinBot: npm run typecheck, npm run lint-changed, npm run fmt, npm run spell-changed, react-compiler-compliance-check on the changed pages, and Jest for DistanceRateTest, PolicyDistanceRatesUtilsTest, PolicyTest, PolicyUtilsTest, WorkspaceOverviewCurrencyPageTest, WorkspaceUpgradeTest, IOURequestStepDistanceRateTest and the distance-rate hook tests (all passed). The full Jest suite and the Storybook smoke test were not run locally.

Fixed Issues

$ #104135
PROPOSAL: #104135 (comment)

Tests

Standard (AMAP) rates — workspace without distance tax

  1. Create a Control workspace and set its default currency to GBP.
  2. Go to Workspace > More features and turn on Distance rates.
  3. Go to Distance rates > Settings and turn on Auto-update government rate.
  4. Go back to Distance rates. Verify the standard Great Britain rates are added (for example £0.45/mile and £0.55/mile), each with the lightning bolt.
  5. Verify no fuel-band rates are added.

Fuel-band rates — workspace with distance tax
These steps need the server to publish GB fuel-band reference rates. Until it does, only the standard rates appear.
6. Create another Control workspace and set its default currency to GBP.
7. Go to Workspace > More features and turn on Distance rates and Taxes.
8. Go to Distance rates > Settings and turn on Track tax.
9. In the same Settings page, turn on Auto-update government rate.
10. Go back to Distance rates. Verify the Great Britain fuel-band rates are added (one rate per fuel type / engine size band), each with the lightning bolt.
11. Verify the standard Great Britain (AMAP) rate is not added.

Lightning bolt and tax reclaimable
12. Open one of the fuel-band rates and note the Tax reclaimable on amount.
13. Change the Tax reclaimable on amount to a different value and save.
14. Verify the lightning bolt no longer shows for that rate.
15. Open the same rate, set Tax reclaimable on back to the amount from step 12, and save.
16. Verify the lightning bolt shows again for that rate.

Turning on tax after auto-update
17. On the workspace from step 1, go to More features and turn on Taxes. Then go to Distance rates > Settings and turn on Track tax.
18. Go back to Distance rates. Verify the existing Great Britain (AMAP) rates are unchanged and still show the lightning bolt. Adding fuel-band rates at this point is out of scope here and tracked in [HOLD #104135] Optimistic UK fuel-band rates when turning on tax.
19. Open one of these AMAP rates, set a tax rate, change its Tax reclaimable on amount, and save. Verify the lightning bolt still shows (AMAP rates ignore the reclaimable amount).

  • Verify that no errors appear in the JS console

Offline tests

QA Steps

Standard (AMAP) rates — workspace without distance tax

  1. Create a Control workspace and set its default currency to GBP.
  2. Go to Workspace > More features and turn on Distance rates.
  3. Go to Distance rates > Settings and turn on Auto-update government rate.
  4. Go back to Distance rates. Verify the standard Great Britain rates are added, each with the lightning bolt.
  5. Verify no fuel-band rates are added.

Fuel-band rates — workspace with distance tax
These steps need the server to publish GB fuel-band reference rates. Until it does, only the standard rates appear.
6. Create another Control workspace and set its default currency to GBP.
7. Go to Workspace > More features and turn on Distance rates and Taxes.
8. Go to Distance rates > Settings and turn on Track tax.
9. In the same Settings page, turn on Auto-update government rate.
10. Go back to Distance rates. Verify the Great Britain fuel-band rates are added (one rate per fuel type / engine size band), each with the lightning bolt.
11. Verify the standard Great Britain (AMAP) rate is not added.

Lightning bolt and tax reclaimable
12. Open one of the fuel-band rates and note the Tax reclaimable on amount.
13. Change the Tax reclaimable on amount to a different value and save.
14. Verify the lightning bolt no longer shows for that rate.
15. Open the same rate, set Tax reclaimable on back to the amount from step 12, and save.
16. Verify the lightning bolt shows again for that rate.

Turning on tax after auto-update
17. On the workspace from step 1, go to More features and turn on Taxes. Then go to Distance rates > Settings and turn on Track tax.
18. Go back to Distance rates. Verify the existing Great Britain (AMAP) rates are unchanged and still show the lightning bolt.
19. Open one of these AMAP rates, set a tax rate, change its Tax reclaimable on amount, and save. Verify the lightning bolt still shows.

Regression — other countries
20. Create a Control workspace in USD, turn on Distance rates, and turn on Auto-update government rate.
21. Verify the United States government rates are added with the lightning bolt, as before.

  • 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 verified any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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

…t for the lightning bolt

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team October 18, 2026 10:44
@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 Oct 18, 2026
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I created this PR from an upstream branch since I don't have push access to your fork.

To take ownership of this branch and be able to push updates, run:

git remote add upstream https://github.com/Expensify/App.git
git fetch upstream claude-ukFuelBandGovernmentRates
git checkout -b claude-ukFuelBandGovernmentRates upstream/claude-ukFuelBandGovernmentRates
git push -u origin claude-ukFuelBandGovernmentRates

Then you can close this PR and open a new one from your fork.

@codecov

codecov Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Coverage Δ
src/CONST/index.ts 95.90% <ø> (ø)
src/libs/actions/Policy/DistanceRate.ts 67.39% <100.00%> (ø)
...c/pages/workspace/upgrade/WorkspaceUpgradePage.tsx 61.61% <100.00%> (+3.33%) ⬆️
src/libs/PolicyDistanceRatesUtils.ts 75.51% <97.82%> (+4.23%) ⬆️
src/libs/actions/Policy/Policy.ts 73.29% <0.00%> (+0.90%) ⬆️
...es/PolicyDistanceRateGovernmentRateCountryPage.tsx 0.00% <0.00%> (ø)
...Rates/PolicyDistanceRateTaxReclaimableEditPage.tsx 0.00% <0.00%> (ø)
.../distanceRates/PolicyDistanceRatesSettingsPage.tsx 0.00% <0.00%> (ø)
... and 4608 files with indirect coverage changes

@MelvinBot

MelvinBot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ⚠️ partial

The PR's only documented test step is "Verify that no errors appear in the JS console", so I ran it across the changed distance-rate flows on a GBP Control workspace: no errors or broken UI appeared. Two gaps: this dev backend returned only the standard GB (AMAP) rate, so fuel-band rows never appeared, and the web tool cannot read raw console output, so the console check relies on no visible errors.
Bolt retained after reverting to 0

Step Status
Turning on government rate auto-update for a GBP workspace adds government rates with the lightning boltAuto-update on, currency set to GBP. The list showed 4/6/11 - 4/5/26 Great Britain (expired, £0.45/mile) and 4/6/26 Great Britain (active, £0.55/mile), both marked auto-generated with the bolt.
GB rates with lightning bolt
Auto-update government rate on
✅
With Taxes and distance Track tax on, regenerating GB rates updates the list without errors (AMAP vs fuel bands)Toggling auto-update off and on left existing rates unchanged, as the UI states. After deleting the GB rates and switching USD→GBP with tax tracking on, the new rates were still AMAP (£0.45 / £0.55), with no reclaimable amount prefilled. The dev backend appears to have no GB fuel-band reference rates, so the fuel-band path could not be seen in the UI.
Auto-update re-enabled with Track tax on
Regenerated GB rates are AMAP
⚠️
Editing a government rate's tax reclaimable amount and restoring it works without errorsOn the active GB rate, Tax Rate 1 (5%) was set and the reclaimable amount was changed from £0 to £0.10, then back to 0. The bolt stayed both times. This is expected for an AMAP snapshot with no percentage, which skips the new reclaimable check. Validation correctly rejected £20 ("The reclaimable portion must be less than the distance rate amount").
Tax reclaimable set to 0.10
Bolt retained after edit
Bolt retained after reverting to 0
✅
Verify that no errors appear in the JS consoleNo error toasts, crash screens, blank panels, or broken layouts appeared during the session. The web device tool has no console-capture command, so raw console output was not read.
⚠️

view run · view recording

@MelvinBot

MelvinBot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ✅ pass

On Android, GB government rates were auto-generated with the lightning bolt, and turning on Track tax and regenerating the rates caused no errors. The bolt stayed through every Tax reclaimable edit, and no JS errors or redboxes appeared. As on Web, only the standard GB (AMAP) rates appeared, never fuel bands, and logs weren't streamed, so the console check relies on no visible errors.
Bolt kept after reverting to 0.11

Step Status
Turning on Auto-update government rate for a GBP workspace adds GB rates with the lightning boltTwo GB rates were created: 4/6/11 - 4/5/26 Great Britain (£0.45/mile, expired) and 4/6/26 Great Britain (£0.55/mile, active). Both were marked "This rate is auto-generated" and showed the bolt.
GB AMAP rates with lightning bolt
✅
With Taxes and Track tax on, toggling auto-update and regenerating GB rates updates the list without errorsToggling auto-update off and on left existing rates unchanged, as the UI states. After deleting the GB rates and switching GBP → USD → GBP, the same standard AMAP rates (£0.45 / £0.55) came back with the bolt. No fuel-band rates appeared, even with Taxes and Track tax on.
Track tax enabled
GB rates regenerated, still AMAP
✅
Editing and restoring the Tax reclaimable amount on an auto-generated GB rate works without errorsSetting Tax Rate 1 (5%) showed "Tax reclaimable on". Saving £0.11, then £0.22, then £0.11 again kept the bolt each time. This is expected for an AMAP snapshot with no reclaimable percentage, which skips the new check.
Tax rate set, Tax reclaimable on shown
Bolt kept after saving 0.11
Bolt kept after changing to 0.22
Bolt kept after reverting to 0.11
✅
Verify that no errors appear in the JS consoleNo redboxes, crashes, or error banners appeared during onboarding, workspace setup, currency changes, toggles, rate regeneration, or tax edits. An unrelated "Add payment card" billing reminder appeared and was closed. Log streaming was off, so logcat wasn't searched.
✅

view run · view recording

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please replace all [ ] by [x] in PR description. Also fill out testing steps for Tests and QA Tests. Then open PR for review

@MelvinBot
MelvinBot marked this pull request as ready for review October 19, 2026 16:09
@MelvinBot
MelvinBot requested a review from a team as a code owner October 19, 2026 16:09
@melvin-bot
melvin-bot Bot requested review from thelullabyy and removed request for a team October 19, 2026 16:09
@melvin-bot

melvin-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

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

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Done. I updated the PR description and marked the PR ready for review.

  • Checkboxes: all 38 are now [x]; none remain unchecked.
  • Tests: added numbered steps for three flows: standard (AMAP) rates on a GBP workspace without distance tax, fuel-band rates with Taxes and Track tax on, and the lightning bolt hiding and returning when you change and restore Tax reclaimable on. I removed the TODO placeholders.
  • QA Steps: the same flows for staging, plus a USD workspace check that other countries are unaffected.

Earlier dev-environment runs showed only AMAP rates, so you may need staging to see the fuel-band rows. I left Offline tests and Screenshots/Videos empty for you to fill in.


view run

@melvin-bot
melvin-bot Bot requested review from garrettmknight and removed request for a team October 19, 2026 16:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T16:15:04.331228Z 7c90d4d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@thelullabyy

thelullabyy commented Oct 19, 2026 •

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 any copy / text that was added to the app 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 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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
Screen.Recording.2026-10-20.at.00.13.18.mov
Screen.Recording.2026-10-20.at.00.16.20.mov

@thelullabyy thelullabyy 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.

Overall the logic looks good to me. A few comments inline.

One small thing in the PR description: Tests step 17 says to set a tax rate on a Great Britain rate on the AMAP workspace from step 1, but that workspace has Taxes / Track tax off, so the tax rate and Tax reclaimable on fields aren't available there. Can you update that step (e.g. turn on Taxes but leave Track tax off, or remove it)?

Comment thread src/libs/PolicyDistanceRatesUtils.ts Outdated

if (shouldAutoUpdateGovernmentDistanceRates && customUnit) {
const copiedSourceRateIDs = new Set(Object.values(customUnit.rates ?? {}).map((rate) => rate.attributes?.governmentRate?.sourceRateID));
const shouldUseFuelBandRates = isTaxTrackingEnabled(true, policy, true);

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.

This is only evaluated when auto-update is turned on. What happens if a GBP workspace already has auto-update on with the AMAP rates and the admin then turns on Track tax (or turns it off on a workspace that has the bands)? enableDistanceRequestTax doesn't touch the rates, so optimistically nothing changes.

Does the server swap AMAP <-> fuel bands when distance tax is toggled? If it does, we should mirror that optimistically in enableDistanceRequestTax (and the policy Taxes toggle). If it doesn't, the workspace stays on AMAP after enabling tax, which seems to go against the goal here. Either way, can we add a test step covering this order (auto-update first, Track tax second)?

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.

Good catch. The server does handle this order, but this PR doesn't mirror it optimistically, on purpose.

  • Turning tax on: when turning on distance tax (or turning tax tracking back on) makes a GBP auto-update workspace eligible, the server adds the missing fuel-band rates. It doesn't remove the existing AMAP rates. Mirroring that in enableDistanceRequestTax and enablePolicyTaxes is the follow-up [HOLD #104135] Optimistic UK fuel-band rates when turning on tax, which is on hold for this PR and reuses buildOnyxDataForGovernmentRateAutoUpdate.
  • Turning tax off: nothing is swapped. Existing fuel-band rates stay, the same way auto-update never modifies existing rates.

I added a "Turning on tax after auto-update" block to Tests and QA (steps 17–19): on the AMAP workspace, turn on Taxes and Track tax, then check the AMAP rates are unchanged and keep the bolt. That also fixes the old step 17, which set a tax rate while tax was off.


view run

Comment thread src/libs/PolicyDistanceRatesUtils.ts Outdated

/** Whether a government rate is a UK fuel band, whose series carries the band after the country code. */
function isFuelBandGovernmentRate(sourceRateID: string): boolean {
return getGovernmentRateSeries(sourceRateID) !== sourceRateID.split('_').at(0);

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.

NAB: this computes the series and splits the ID again just to check whether there is a segment between the country and the date. Could be simpler and easier to read:

return sourceRateID.split('_').length > 2;

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.

Done in edc5108: isFuelBandGovernmentRate now returns sourceRateID.split('_').length > 2. Results don't change: GB_2026-04-06 has 2 parts and band IDs have more.


view run

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please update your PR based on above reviews

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team as a code owner October 19, 2026 16:35
@melvin-bot
melvin-bot Bot requested review from neil-marcellini and thelullabyy and removed request for a team October 19, 2026 16:35
@melvin-bot

melvin-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown

@thelullabyy @neil-marcellini One of you needs to 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]

@MelvinBot

Copy link
Copy Markdown
Contributor Author

I updated the PR based on your review.

  • Simplified fuel-band check: I pushed edc5108. isFuelBandGovernmentRate now uses sourceRateID.split('_').length > 2.
  • Turning tax on after auto-update: this PR leaves the existing AMAP rates unchanged. The server adds the missing fuel-band rates. The optimistic copy is tracked in [HOLD #104135] Optimistic UK fuel-band rates when turning on tax. I replied in the thread with details.
  • Test steps: I replaced the old step 17. Steps 17–19 now turn on Taxes and Track tax on the AMAP workspace, then check that the rates are unchanged and keep the lightning bolt. Tests and QA both include this. I also noted that the fuel-band steps need the server to publish GB fuel-band reference rates.

Typecheck, ESLint on the changed file, and 309 Jest tests in PolicyDistanceRatesUtilsTest, DistanceRateTest and PolicyTest pass.


view run

@neil-marcellini

Copy link
Copy Markdown
Contributor

I reviewed part of the changes here, then found that issue. Once you get it fixed, I'll review again.

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please check and fix

#104309 (comment)
#104309 (review)

… are published

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

The failing checks are unrelated to this PR, so I didn't push a fix.

  • test (job 5) failed on a timing check. The test tests/unit/findUnusedStylesTest.ts:360 expects a run under 5000 ms and got 6494 ms on the CI runner. This PR doesn't touch that test or the style tooling it covers.
  • PR Reviewer Checklist and Check independent approval need a reviewer action, not a code change.

All other checks pass. To clear the Jest failure, rerun the failed job in GitHub Actions.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

The failing checks are still unrelated to this PR, so I didn't push a fix. Nothing has changed since my earlier comment.

  • test (job 5) fails on a timing limit in tests/unit/findUnusedStylesTest.ts:360. The CI runner took 6494 ms against a 5000 ms limit. This PR doesn't touch that test or the code it covers.
  • PR Reviewer Checklist and Check independent approval need a reviewer, not a code change.

I can't rerun jobs. To clear the Jest failure, open the Jest run and select Re-run failed jobs.

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please merge main

…rnmentRates

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Merged main into this branch in d6692eb. There were no conflicts.

Typecheck passes, and so do DistanceRateTest, PolicyTest and PolicyDistanceRatesUtilsTest (313 tests).


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

⚠️ MelvinBot CI Fix Loop Detected

MelvinBot has made 5 consecutive commits trying to fix CI failures. Automatic CI fix dispatches are now paused for this PR.

Next steps: A human should review the recent commits and resolve the conflicting CI errors manually.

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Please merge main, resolve conflicts, and add fix for comments in PR if needed

…rnmentRates

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>

# Conflicts:
#	tests/unit/DistanceRateTest.ts
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I merged main into this branch in 78aa342 and resolved the one conflict. No review comments needed new fixes; every earlier comment already has a fix and a reply.

  • Conflict in tests/unit/DistanceRateTest.ts: main moved getPolicyFromOnyx to the top of the file and added a getDistanceCustomUnit helper for the old setWorkspaceDistanceAutoUpdate(policyID, customUnit, …) signature. This PR passes policy instead, so I removed both helpers from the setWorkspaceDistanceAutoUpdate block. The tests now use the shared top-level getPolicyFromOnyx.
  • Callers from main: every setWorkspaceDistanceAutoUpdate and buildOnyxDataForGovernmentRateAutoUpdate caller uses the new signature.

Typecheck, ESLint on the changed file, and DistanceRateTest, PolicyDistanceRatesUtilsTest and PolicyTest (324 tests) pass.


view run

@thelullabyy

Copy link
Copy Markdown
Contributor

@neil-marcellini Could you please do another review?

@neil-marcellini neil-marcellini 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.

A few NABs and one thing to fix.

Comment on lines 174 to 182
setWorkspaceDistanceAutoUpdate(
policyID,
customUnit,
policy,
isOn,
governmentMileageRates ?? [],
policy?.outputCurrency,
policy.outputCurrency,
isOn && isSharedCurrency ? autoUpdateCountry : undefined,
!!policy?.shouldAutoUpdateGovernmentDistanceRates,
!!policy.shouldAutoUpdateGovernmentDistanceRates,
isSharedCurrency ? autoUpdateCountry : undefined,
);

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.

NAB: We can remove the parameters that come directly from the policy and set them up within the function.

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.

Done in 59957bb. setWorkspaceDistanceAutoUpdate now takes (policy, isOn, governmentMileageRates, countryCode?). It reads the currency, the previous flag and the previous country from policy. All three callers and the tests are updated.

buildOnyxDataForGovernmentRateAutoUpdate keeps those parameters, because updateGeneralSettings passes the new currency, not the policy's current one.


view run

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.

Okay, I guess it makes sense that "Build Onyx data for government rate auto update" does keep a separate currency parameter, but the "should auto update government distance rates" parameter should be removed.

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.

Done in e01722a. The previous auto-update flag (and previous country) parameters are removed from buildOnyxDataForGovernmentRateAutoUpdate, which now reads them from policy. The currency parameter stays.

Comment thread tests/unit/DistanceRateTest.ts Outdated
Comment thread tests/actions/PolicyTest.ts Outdated
Comment on lines +2700 to +2703
// Then no rates are copied optimistically, because the server copies the fuel bands and its response adds them
const apiCallArgs = apiWriteSpy.mock.calls.find((call) => call.at(0) === WRITE_COMMANDS.UPDATE_WORKSPACE_GENERAL_SETTINGS);
const params = requireRecord(requireCallArgument(apiCallArgs, 1));
expect(params.optimisticRateIDs).toBeUndefined();

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.

This is a problem. The governmentRateCountry is only meant to be used when a user has to pick which country they want to use with the EUR currency. For other currencies like GBP it doesn't apply because we know the country based on the currency. So governmentRateCountry should not be passed and the AFR rates should still be added optimistically.

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.

Fixed in 59957bb.

  • Copy on currency change: updateGeneralSettings now copies the rates optimistically when auto-update is on and the currency changes to one that maps to a single country (GBP, USD, CAD, AUD). The builder filters the rates by currency, so no country is needed.
  • Params: governmentRateCountry is only sent for EUR. optimisticRateIDs is sent whenever rates are copied.
  • Tests: the GBP tests no longer pass a country. They check that an eligible workspace gets only the fuel bands, a workspace without tax tracking gets the standard rate, and auto-update off copies nothing.

Please confirm one thing on the server side. Does UpdateWorkspaceGeneralSettings read optimisticRateIDs when governmentRateCountry is absent? Until now the App only sent them together. If the server ignores the IDs, its rates won't match the optimistic ones.


view run

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot could you please check and resolve comments above

…es and derive auto-update state from the policy

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I fixed all three of neil-marcellini's comments in 59957bb and replied in each thread.

  • GBP currency change (blocking): changing the currency to GBP, USD, CAD or AUD with auto-update on now copies that country's rates optimistically. governmentRateCountry is only sent for EUR. The tests no longer pass a country for GBP.
  • setWorkspaceDistanceAutoUpdate parameters: it now reads the currency, previous flag and previous country from policy.
  • Never-happens test: removed.

One open question for Neil: does the server read optimisticRateIDs when governmentRateCountry is absent? If not, the server's rate IDs won't match the optimistic ones.

The 324 tests in DistanceRateTest, PolicyTest and PolicyDistanceRatesUtilsTest pass, and typecheck passes. ESLint ran on the changed source files and showed only existing errors on lines this PR doesn't touch. ESLint ran out of memory on the test files, and I couldn't run the formatter here, so CI will cover both.


view run

@thelullabyy

Copy link
Copy Markdown
Contributor

@neil-marcellini could you please recheck, the PR is updated. I also re-tested the PR, it works well

@melvin-bot
melvin-bot Bot requested a review from neil-marcellini October 28, 2026 16:14

@neil-marcellini neil-marcellini 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.

Looking really close, requesting changes to align the proper optimistic behavior.

Comment thread src/libs/actions/Policy/DistanceRate.ts Outdated
Comment on lines +1160 to +1167
const {optimisticRateIDs, onyxData} = buildOnyxDataForGovernmentRateAutoUpdate(
policy,
shouldAutoUpdateGovernmentDistanceRates,
governmentMileageRates,
outputCurrency,
policy.outputCurrency,
countryCode,
previousAutoUpdateEnabled,
previousCountryCode,
!!policy.shouldAutoUpdateGovernmentDistanceRates,
policy.autoUpdateGovernmentRateCountry,

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.

NAB: I have the same non-blocking comment now on this function instead of set workspace distance auto update. If we can get the parameter from the policy object directly, there's no need to pass it separately. You can fix this in a follow-up.

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.

Done in e01722a. buildOnyxDataForGovernmentRateAutoUpdate no longer takes previousAutoUpdateEnabled or previousCountryCode. It reads both from policy for the failure data. It keeps the currency parameter, since the currency change passes the new currency.

Comment on lines 174 to 182
setWorkspaceDistanceAutoUpdate(
policyID,
customUnit,
policy,
isOn,
governmentMileageRates ?? [],
policy?.outputCurrency,
policy.outputCurrency,
isOn && isSharedCurrency ? autoUpdateCountry : undefined,
!!policy?.shouldAutoUpdateGovernmentDistanceRates,
!!policy.shouldAutoUpdateGovernmentDistanceRates,
isSharedCurrency ? autoUpdateCountry : undefined,
);

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.

Okay, I guess it makes sense that "Build Onyx data for government rate auto update" does keep a separate currency parameter, but the "should auto update government distance rates" parameter should be removed.

Comment thread src/libs/PolicyDistanceRatesUtils.ts Outdated
for (const rate of Object.values(customUnit.rates ?? {})) {
const sourceRateID = rate.attributes?.governmentRate?.sourceRateID;
if (sourceRateID) {
addSeriesRate(sourceRateID, rate.startDate ?? rate.attributes?.governmentRate?.startDate, rate.enabled);

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.

(Neil's AI agent, human reviewed)

I noticed the server and the App disagreed on when a copied rate inherits enabled. So I updated the issue description (and the backend spec) with a clearer rule. We're aligning the backend (Auth #25931) and the frontend on it.

The behavior we want:

  • A copied rate takes enabled from the previous rate in its series, in every country. An admin who disables a government rate opts out of it from then on. This part already works.
  • It only does so when that previous rate is still an unmodified government rate. A rate the admin edited is their own, so its enabled state shouldn't decide the next government rate. If the latest previous rate was edited, the new rate is enabled, even if an older period was disabled.
  • "Previous" goes by the government start date in the snapshot, not the rate's own dates, which the admin can edit.

Example for one band:

  • March: unmodified, disabled. June: edited by the admin. September: copied now, so it should be enabled.
  • If June were unmodified and disabled, September should be disabled.

Today, an admin who edits GB_PETROL_UP_TO_1400_2026-06-01 to their own amount and disables it gets the September band added disabled, even though they never opted out of the government rate.

Please also update the builder's doc comment ("matching the server's copy") and the note in the PR description.

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.

Fixed in e01722a (from thelullabyy's draft). A copied rate now takes enabled from the previous rate in its series only when that rate is an unmodified government rate. If the previous rate was edited, or there is none, the copied rate is enabled. "Previous" is ordered by the snapshot's start date. I updated the builder's doc comment and the PR description note.

expect(rates).toHaveLength(2);
});

it('should keep a disabled fuel band disabled for every later rate of its series in the same request', async () => {

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.

(Neil's AI agent, human reviewed)

Please extend this test for the "unmodified only" rule from the comment on the builder: add an existing diesel rate (for example GB_DIESEL_UP_TO_1600_2026-03-01) whose amount the admin edited and which they disabled. Then assert that the copied September diesel band is enabled.

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.

Done in e01722a. The test now adds an edited, disabled GB_DIESEL_UP_TO_1600_2026-03-01 rate and asserts that the copied September diesel band is enabled.

@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot I draft a solution for above comments/suggestions here thelullabyy@3396940

Please check and bring it here

…ad previous auto-update state from the policy

Applies thelullabyy's draft (thelullabyy/App@3396940).

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@thelullabyy

Copy link
Copy Markdown
Contributor

@MelvinBot Deep review and fix issues (pipelines,...)

@MelvinBot

Copy link
Copy Markdown
Contributor Author

I brought your draft into this PR unchanged in e01722a, with you as co-author. It matches the rule in the issue description, so I didn't change any logic.

  • enabled rule: a copied rate takes enabled from the previous rate only when that rate is unmodified. Otherwise the copied rate is enabled. "Previous" is ordered by the snapshot's start date.
  • Parameters: buildOnyxDataForGovernmentRateAutoUpdate reads the previous flag and country from policy.
  • Test: an edited, disabled diesel rate no longer disables the September diesel band.

I updated the PR description and replied in Neil's four threads.

Typecheck passes, and so do 324 tests in DistanceRateTest, PolicyDistanceRatesUtilsTest and PolicyTest. ESLint shows only 2 existing errors on lines this PR doesn't touch. I couldn't run the formatter check here, so CI will cover it.

@thelullabyy

Copy link
Copy Markdown
Contributor

…d test the latest-edited-rate rule

Co-authored-by: thelullabyy <thelullabyy@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I fixed the two failing checks and two small issues from a deep review in 20b8873.

  • Oxfmt check: my last commit left one call in DistanceRate.ts over the line limit. It is now wrapped.
  • spellcheck: the test rate ID EDITEDDIESEL1 failed cspell. It is now a hex ID like the others.
  • Duplicate reference rates: if the reference list held the same rate twice, the App copied it twice and left one orphaned. It now copies it once, and a new test covers this.
  • Neil's example: a new test covers March unmodified and disabled, June edited, and September copied. September is enabled.

All other checks passed on the previous commit. Check independent approval clears after review.

The review found no other logic bugs. One question for Neil is still open: does UpdateWorkspaceGeneralSettings use optimisticRateIDs when the request has no governmentRateCountry? If not, GBP, USD, CAD and AUD currency changes will show duplicate rates until the policy reloads.

Typecheck, cspell, Oxfmt and 326 tests in DistanceRateTest, PolicyDistanceRatesUtilsTest and PolicyTest pass.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Both checks are already fixed in 20b8873, and both now pass on the latest run. My previous commit caused both failures.

  • Spellcheck: cspell rejected the test ID EDITEDDIESEL1. It's now a hex ID (5A1D3C8E9F0B2), like the other rate IDs in the test.
  • Oxfmt: the one-line buildOnyxDataForGovernmentRateAutoUpdate call in DistanceRate.ts is now split across lines.

That commit also has two extra changes:

  • The builder now skips a reference rate that appears twice in the same request.
  • A new test covers the rule that only the latest previous rate counts.

The 326 tests in DistanceRateTest, PolicyDistanceRatesUtilsTest and PolicyTest pass locally. The Jest and perf jobs are still running in CI. Check independent approval needs a reviewer, not a code change.

This branch has not been deployed

No deployments
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.

3 participants