Keep Other Accounts order stable during sync#33
Conversation
What changed: - extracted the Other Accounts sort rules into a dedicated helper that compares visible reset buckets instead of second-level jitter - preserved backend refresh_all_usage result order instead of returning accounts in completion order - updated the app to keep the current Other Accounts order across refresh cycles and only rebuild membership when the list shape changes - added unit, API, and UI regression tests for the repeated-sync ordering bug Why: - refreshing usage could reshuffle cards even when the user had not changed the sort mode, especially because reset timestamps drifted by seconds while the UI only showed minute precision Impact: - Other Accounts no longer jump around during sync for the same visible sort values - the repo now has regression coverage for the original ordering bug Validation: - tests were added in this commit, but not executed during this split
What changed: - added explicit .ts ESM import paths in the sync-order test files - pointed type imports at src/types/index.ts so Node 24 can resolve the modules during node:test runs Why: - the order regression tests were written as ESM TypeScript, but bare local specifiers do not resolve under the direct Node test runner used for validation here Impact: - the helper regression test can now run directly with node --test - the API smoke test still skips cleanly when no backend is running Validation: - node --test tests/otherAccountsOrder.test.ts - node --test tests/syncOrder.api.test.ts
Lampese
left a comment
There was a problem hiding this comment.
Requesting changes for one behavioral issue:
The new otherAccountsOrder state effectively freezes the Other Accounts ordering after the initial sort. After the first ordering pass, the list is only recomputed when the selected sort mode changes or when the list starts empty. If usage values later change in a way that should legitimately reorder the cards, the current code keeps the previous order instead of recalculating from the latest data. New accounts are also appended to the retained order rather than being inserted according to the active sort rule.
That means this does more than remove jitter: it can leave the rendered order out of sync with the actual current sort values. I think this should be resolved before merging so the UI remains stable without becoming stale.
Summary
This PR keeps the
Other Accountslist in a stable order across repeated sync and refresh cycles.What changed
refresh_all_usageresult order instead of returning accounts in completion orderOther Accountssort rules into a shared helper that compares the same minute-level buckets the UI actually rendersWhy
The list could reshuffle between refreshes even when the visible sort values had not meaningfully changed. Second-level jitter in reset timestamps and out-of-order async backend responses made the cards appear to jump around.
Validation
pnpm buildcargo build --manifest-path src-tauri/Cargo.tomlnode --test tests/otherAccountsOrder.test.tsnode --test tests/syncOrder.api.test.ts(skips cleanly when no backend is running)