[PR #6165] [MERGED] Fix flaky merkle test by enforcing deterministic key ordering #48184

Closed
opened 2026-04-26 10:07:32 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/actualbudget/actual/pull/6165
Author: @MatissJanis
Created: 11/16/2025
Status: Merged
Merged: 11/19/2025
Merged by: @MatissJanis

Base: masterHead: matiss/fix-merkle-test-flakiness


📝 Commits (5)

  • ba927cb Fix flaky merkle test by enforcing deterministic key ordering
  • c3c73fa Update type
  • 10839c9 Merge branch 'master' into matiss/fix-merkle-test-flakiness
  • 7a04eab Update VRT screenshots
  • da7b4c9 Merge branch 'master' into matiss/fix-merkle-test-flakiness

📊 Changes

3 files changed (+65 additions, -9 deletions)

View changed files

📝 packages/crdt/src/crdt/merkle.ts (+59 -9)
📝 packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png (+0 -0)
upcoming-release-notes/6165.md (+6 -0)

📄 Description

This is a relatively risky change. Please review carefully.

The intention is to fix the flaky merkle unit tests: https://github.com/actualbudget/actual/actions/runs/19399343424/job/55504247699?pr=6142


Problem

The adding an item works test in merkle.test.ts was flaky due to non-deterministic object key ordering. When Object.assign() was used to create trie nodes, the order of numeric string keys ('0', '1', '2') could vary, causing snapshot mismatches when Vitest serialized the trie structure.

Solution

  • Added a createTrieNode() helper function that ensures keys are always created in deterministic sorted order:
    • Numeric keys ('0', '1', '2') first, in that order
    • 'hash' key last
  • Updated all trie creation functions to use createTrieNode():
    • emptyTrie() - Creates empty tries with consistent ordering
    • insert() - Updates hash with consistent ordering
    • insertKey() - Recursively builds tries with consistent ordering
    • prune() - Prunes tries while maintaining consistent ordering

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/actualbudget/actual/pull/6165 **Author:** [@MatissJanis](https://github.com/MatissJanis) **Created:** 11/16/2025 **Status:** ✅ Merged **Merged:** 11/19/2025 **Merged by:** [@MatissJanis](https://github.com/MatissJanis) **Base:** `master` ← **Head:** `matiss/fix-merkle-test-flakiness` --- ### 📝 Commits (5) - [`ba927cb`](https://github.com/actualbudget/actual/commit/ba927cbf4e1f27b55325eab0e12b76f2e527db2a) Fix flaky merkle test by enforcing deterministic key ordering - [`c3c73fa`](https://github.com/actualbudget/actual/commit/c3c73fa89b2d449e8ad341c69a02d3a1bddd2ba1) Update type - [`10839c9`](https://github.com/actualbudget/actual/commit/10839c97df799b1d97e6610db1351a129ddb835a) Merge branch 'master' into matiss/fix-merkle-test-flakiness - [`7a04eab`](https://github.com/actualbudget/actual/commit/7a04eabd7c4677cd7c35382b16535a48d362c110) Update VRT screenshots - [`da7b4c9`](https://github.com/actualbudget/actual/commit/da7b4c9a2615e042dfeaf4fd9fa18dcc59c26e28) Merge branch 'master' into matiss/fix-merkle-test-flakiness ### 📊 Changes **3 files changed** (+65 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/crdt/src/crdt/merkle.ts` (+59 -9) 📝 `packages/desktop-client/e2e/reports.test.ts-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png` (+0 -0) ➕ `upcoming-release-notes/6165.md` (+6 -0) </details> ### 📄 Description This is a relatively risky change. Please review carefully. The intention is to fix the flaky merkle unit tests: https://github.com/actualbudget/actual/actions/runs/19399343424/job/55504247699?pr=6142 --- ## Problem The `adding an item works` test in `merkle.test.ts` was flaky due to non-deterministic object key ordering. When `Object.assign()` was used to create trie nodes, the order of numeric string keys ('0', '1', '2') could vary, causing snapshot mismatches when Vitest serialized the trie structure. ## Solution - Added a `createTrieNode()` helper function that ensures keys are always created in deterministic sorted order: - Numeric keys ('0', '1', '2') first, in that order - 'hash' key last - Updated all trie creation functions to use `createTrieNode()`: - `emptyTrie()` - Creates empty tries with consistent ordering - `insert()` - Updates hash with consistent ordering - `insertKey()` - Recursively builds tries with consistent ordering - `prune()` - Prunes tries while maintaining consistent ordering --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-26 10:07:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/actual#48184