Skip to content

Keep Other Accounts order stable during sync#33

Open
SHAREN wants to merge 2 commits intoLampese:mainfrom
SHAREN:codex/stable-other-accounts-order
Open

Keep Other Accounts order stable during sync#33
SHAREN wants to merge 2 commits intoLampese:mainfrom
SHAREN:codex/stable-other-accounts-order

Conversation

@SHAREN
Copy link
Copy Markdown
Contributor

@SHAREN SHAREN commented Mar 27, 2026

Summary

This PR keeps the Other Accounts list in a stable order across repeated sync and refresh cycles.

What changed

  • preserved backend refresh_all_usage result order instead of returning accounts in completion order
  • extracted Other Accounts sort rules into a shared helper that compares the same minute-level buckets the UI actually renders
  • kept the current card order across refreshes and only rebuilt membership when accounts were added or removed
  • added regression coverage for the helper ordering rules and an API smoke check entrypoint

Why

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 build
  • cargo build --manifest-path src-tauri/Cargo.toml
  • node --test tests/otherAccountsOrder.test.ts
  • node --test tests/syncOrder.api.test.ts (skips cleanly when no backend is running)

SHAREN added 2 commits March 27, 2026 16:38
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
Copy link
Copy Markdown
Owner

@Lampese Lampese left a comment

Choose a reason for hiding this comment

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

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.

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.

2 participants