Repository navigation
feat(DW-1668): extract a pure cache→live handoff/empty-view policy and unit test it - #1694
abaranouski wants to merge 4 commits into
Conversation
…d unit test it WalletTransactionsFragment decided the cache→live adapter swap, the loading overlay and the empty view inline inside its loadStateFlow collector, as a function of several independently-arriving inputs (cache commit, Pager load state, transactionsLoaded, isBuildingCache, cacheAdapterAttached). The module has no Fragment/Robolectric harness, so none of that had tests beyond the Appium filter test (#1666, follow-up DW-1668). Extract transactionsListPolicy as a pure function of those inputs plus liveAdapter.itemCount and whether the header is empty, returning the swap/loading/empty decision. The Fragment now applies the result instead of computing it inline. Unit tests cover the four handoff sequences from the ticket (startup swap to an empty result, a late cache commit after detach, view recreation after an empty result settled, clearing the filter) plus two edge cases for the header and cache-rebuild overlay. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
✅ Final review complete — no blockers (commit f78aad7) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The extraction preserves the existing cache-to-live handoff and loading/empty decisions; no behavioral regression was identified. One non-blocking test-coverage suggestion remains for a reachable rebuild state where loading and empty outputs overlap. Current build and check jobs pass; the automated review remains pending, and no local builds or tests were run.
🟡 1 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
lowbygpt-6.1-sol(effort low) — This is a contained extraction of existing transaction-list display decisions into a pure function with focused unit tests, without changing critical surfaces or external contracts. - Phase 1 reviewers:
glm-5.3-flash— general (completed, effort high); agentphase1-reviewer - Phase 1 model:
glm-5.3-flash— zai quota: 5h 99% left, weekly 87% left; passed overgemini-3.8-flash-high(antigravity quota lookup failed) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort medium); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `wallet/test/de/schildbach/wallet/ui/main/TransactionsListPolicyTest.kt`:
- [SUGGESTION] wallet/test/de/schildbach/wallet/ui/main/TransactionsListPolicyTest.kt:156-158: Cover rebuilding after transactionsLoaded has already latched true
The rebuild test only exercises transactionsLoaded=false. TxDisplayCacheService never resets that latch, but a later known-zero rebuild sets isBuildingCache=true again. With a settled refresh, no visible rows, and an empty header, the extracted policy therefore returns both isLoading=true and isEmpty=true. This preserves the existing behavior: showEmptyView() independently checks !isBuildingCache before displaying the empty text. Add a test for this overlapping output and document the sink's guard so the new policy coverage records that these flags are intentionally not mutually exclusive. This is a coverage improvement, not a behavioral regression.
| assertEquals(false, rebuildingWithCacheRowsVisible.isLoading) | ||
| } | ||
| } |
There was a problem hiding this comment.
✅ Resolved at
f78aad75; see the replies below.
🟡 Suggestion: Cover rebuilding after transactionsLoaded has already latched true
The rebuild test only exercises transactionsLoaded=false. TxDisplayCacheService never resets that latch, but a later known-zero rebuild sets isBuildingCache=true again. With a settled refresh, no visible rows, and an empty header, the extracted policy therefore returns both isLoading=true and isEmpty=true. This preserves the existing behavior: showEmptyView() independently checks !isBuildingCache before displaying the empty text. Add a test for this overlapping output and document the sink's guard so the new policy coverage records that these flags are intentionally not mutually exclusive. This is a coverage improvement, not a behavioral regression.
| assertEquals(false, rebuildingWithCacheRowsVisible.isLoading) | |
| } | |
| } | |
| assertEquals(false, rebuildingWithCacheRowsVisible.isLoading) | |
| } | |
| @Test | |
| fun `a later rebuild can request loading and empty handling together`() { | |
| // transactionsLoaded remains true across later rebuilds. showEmptyView() | |
| // separately suppresses the empty text while isBuildingCache is true. | |
| val laterRebuild = transactionsListPolicy( | |
| cacheAdapterAttached = true, | |
| cacheHasRows = false, | |
| refreshState = settled, | |
| transactionsLoaded = true, | |
| isBuildingCache = true, | |
| liveItemCount = 0, | |
| headerIsEmpty = true | |
| ) | |
| assertEquals(TransactionsListPolicy(swapToLive = true, isLoading = true, isEmpty = true), laterRebuild) | |
| } | |
| } |
source: glm-5.3-flash (phase1-reviewer: general)
There was a problem hiding this comment.
claude: @thepastaclaw Done — added the overlapping-latch test (a later rebuild can request loading and empty handling together) in ed0daacdb. Two further Fragment-wiring bugs turned up in local pre-review after that commit and are also fixed on this push: 9a1a31bcf made the isBuildingCache observer apply transactionsListPolicy's isLoading/isEmpty instead of its own formula (it never called showEmptyView()/showTransactionList()), and f78aad754 resets the new lastRefreshState field in onViewCreated so a recreated view can't read a stale value from the previous one. All 8 TransactionsListPolicyTest cases pass on the build host at current head f78aad754.
There was a problem hiding this comment.
Thanks for the update. reviewsys handles this finding and will respond in this thread and re-review on push once the draft PR is marked ready for review.
There was a problem hiding this comment.
Resolved (re-reviewed at f78aad75): Your added overlapping-latch test asserts all three policy outputs for transactionsLoaded=true during a later rebuild and documents the separate empty-text guard, which remains present in showEmptyView(). I also verified the observer visibility updates and onViewCreated refresh-state reset you described.
…true thepastaclaw (PR #1694) flagged that the rebuild test only exercised transactionsLoaded=false. Add the overlapping case: a later known-zero rebuild with the latch already true returns isLoading=true and isEmpty=true together, which showEmptyView() independently guards via !isBuildingCache. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…bserver The isBuildingCache.observe callback computed its own spinner-only hasRows formula and never called showEmptyView()/showTransactionList(). A rebuild that completes without a fresh loadStateFlow emission (e.g. replaceAll(emptyList()) over an already-empty cache, which triggers no Room invalidation) left the screen at whatever loading/empty state the prior emission last set — a blank history screen instead of the empty view. Capture the live Pager's last-seen refresh LoadState in a Fragment-scoped var and re-run transactionsListPolicy from the isBuildingCache callback, applying its full loading/empty result, so this path uses the same single source of truth as loadStateFlow's own collector. Co-Authored-By: Claude Sonnet 5 <[email protected]>
onViewCreated already resets cacheAdapterAttached/cacheHasRows for the documented case where this Fragment's view is torn down and rebuilt while the Fragment instance survives (e.g. a bottom-nav tab swap), but left lastRefreshState holding the previous view's settled LoadState. isBuildingCache's observer now feeds that stale value into transactionsListPolicy, so a redelivered StateFlow value arriving before the new view's own loadStateFlow emission could show the empty view over a wallet that has history. Reset it to LoadState.Loading alongside its siblings, for the same reason. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
@abaranouski on it — I've queued this as job |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
At f78aad7, the rebuild observer now updates loading/empty visibility and view recreation resets the saved refresh state; no blocking regression was found. One non-blocking consolidation suggestion remains because the two callers apply different subsets of the extracted policy. This was a static review: current CI build and check jobs pass, the review check is pending, and the eight policy-test results remain author-reported rather than independently executed.
🟡 1 suggestion(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.1-sol(effort low) — The change extracts and rewires transaction-list loading, adapter handoff, and empty-state decisions across lifecycle observers with sequence tests, requiring ordinary behavioral review but touching no critical surface. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `wallet/src/de/schildbach/wallet/ui/main/WalletTransactionsFragment.kt`:
- [SUGGESTION] wallet/src/de/schildbach/wallet/ui/main/WalletTransactionsFragment.kt:488-489: Apply the complete policy through one Fragment-local renderer
The building observer applies isLoading and isEmpty but ignores swapToLive, while the loadStateFlow collector applies all three outputs. These outputs are coupled: transactionsListPolicy excludes cached rows from its visibility calculations whenever swapToLive is true, assuming that the adapter swap is also performed. The collector currently updates lastRefreshState and swaps synchronously without suspension, so this is a consistency improvement rather than a demonstrated behavioral regression. Extract a Fragment-local applyPolicy function that performs the guarded adapter swap before updating visibility, and call it from both observers. This keeps adapter ownership in the Fragment and makes both callers honor the policy's complete contract.
| binding.loading.isVisible = policy.isLoading | ||
| if (policy.isEmpty) showEmptyView() else showTransactionList() |
There was a problem hiding this comment.
🟡 Suggestion: Apply the complete policy through one Fragment-local renderer
The building observer applies isLoading and isEmpty but ignores swapToLive, while the loadStateFlow collector applies all three outputs. These outputs are coupled: transactionsListPolicy excludes cached rows from its visibility calculations whenever swapToLive is true, assuming that the adapter swap is also performed. The collector currently updates lastRefreshState and swaps synchronously without suspension, so this is a consistency improvement rather than a demonstrated behavioral regression. Extract a Fragment-local applyPolicy function that performs the guarded adapter swap before updating visibility, and call it from both observers. This keeps adapter ownership in the Fragment and makes both callers honor the policy's complete contract.
source: muse-spark-1.3-contributor (phase1-reviewer: general); gpt-6.1-sol (phase2-reviewer: general)
There was a problem hiding this comment.
claude: @thepastaclaw Thanks — and this matches our own local pre-review finding on the same gap (06b-prereview.md). We traced it the same way: it confirms this is not a demonstrated behavioural regression, just a consistency improvement, since the collector updates lastRefreshState and performs the adapter swap synchronously with no suspension point in between. We're keeping this PR scoped to the transactionsListPolicy extraction and the two wiring fixes (9a1a31bcf, f78aad754); the Fragment-local applyPolicy consolidation you describe goes with the next change to this Fragment rather than into this PR.
QA — run 50, build 12000301 (12.0.3-qa01): no regression seen, but no targeted stream eitherStating this one precisely, because "it was in the build and nothing broke" is weaker evidence than a pass and should not be read as one. Commit under test: What it gotThis PR was in the build for every device stream and was exercised incidentally by every restore, rescan, Reset Wallet and in-place upgrade in the run — on wallets of 4, 11 and 3,294 transactions, including a restore of the large reference wallet and a full Reset-and-restore cycle. No empty-list flash and no stuck list was observed in any of them. What it did not getThe run did not construct the cases this PR's own unit tests cover — view recreation resetting If a targeted stream would be useful — rotation or process death during Build provenanceBuild: The SDK pin does not move — int36, the same pin 12.0.2 shipped with, and checked rather than assumed: APK: versionCode Run: QA run 50, testnet, 2026-11-19. Five Android 16 devices plus one at API 29. Unit tests on the merged tree: 5,007 passing, 0 failures. |
QA run 52 — carried forward unchanged, plus upgrade and unit-test coverageThis PR is in builds 12000303 and 12000304 at commit What run 52 adds for this PR specifically:
No new finding against this PR. How this was testedBuilds. Devices. Android 16 (API 36) emulators, testnet, release-signed builds. Platform protocol 14. Unit tests on 12000304: 4,779 tests across 330 classes, 0 failures, 0 errors, 1 skipped. Both SDK native libraries are byte-identical in size across the two builds, so differences between them come from the PRs and not from the SDK underneath. Full report: https://github.com/HashEngineering/dash-wallet-qa-report — run 52. |
QA run 56 — PASS on a 7,459-transaction walletTested where a handoff gap would actually show: a wallet of 7,459 transactions, cold start, sampling the History view every ~2 s for 24 samples.
The cached rows render immediately and "no transactions to display" never appears during the cache → live handoff. A correction I owe youMy first attempt at this measurement reported 0 empty views and 0 rows, which reads like a pass but was simply blind: the probe matched row labels QA run 56, 2026-11-30. Build 12000305 (12.0.3-qa05), branch |
Known gaps
DW-1668/poc/artifacts/05-junit.md): the new Appiumclass
TransactionHistoryEmptyFilterTest(in the linked tests PR) has 2/5 failures(
testEmptyFilterSurvivesViewRecreation,testEmptyFilterSurvivesCacheRebuild). Both werere-run against the pre-fix base commit (
fc6400ebb) on the same device and failed identically —a real, pre-existing stale-row defect this test newly documents, not a regression this PR
introduced. The pre-existing defect is filed as Transaction history: stale filtered row resurfaces after view recreation or manual cache rebuild #1699; the two tests stay in the tests PR unchanged
to document it. The QA-analysis stage (
06-analysis.md) concludes the ticket's own ask is doneand verified, so this PR is ready for review.
isBuildingCacheobserver computespolicy.swapToLivebut never applies it (pre-reviewsuggestion, non-blocking — see «Самопроверка» below): safe today because of a coroutine-ordering
invariant, not because the code's structure guarantees it. Not fixed this round; flagged for a
future consolidation if the reviewer wants it.
TransactionsListPolicyTestcovers the extracted pure function only — it cannot catch aregression in the Fragment's observer wiring itself (needs a Robolectric/instrumented-Fragment
harness this module doesn't have). Accepted as-is; the linked tests PR's new Appium class is the
mitigation available without that infrastructure.
Тикет: DW-1668
WalletTransactionsFragmentdecided inline, insideloadStateFlow.collectLatest, when to swap thecache adapter for the live one, when to show the loading overlay, and when to show the empty view —
five inputs combined ad hoc, with no unit coverage (the module has no Fragment/Robolectric harness).
Extracted the decision into a pure top-level function,
transactionsListPolicy(...), returning aTransactionsListPolicy(swapToLive, isLoading, isEmpty)data class; both call sites(
loadStateFlow's collector and theisBuildingCacheobserver) now call it and apply its resultinstead of computing their own booleans.
Проверка
isBuildingCacheobserver used its own narrower formula and never calledshowEmptyView()/showTransactionList()at all.TransactionsListPolicyTest(8 cases) covers the four ticket-named sequences plus tworeview-driven edge cases, hand-verified against the function's algebra and run on the build host:
ktlintCheck :wallet:compile_testNet3DebugKotlin test_testNet3DebugUnitTest→exit 0,
tests="8" skipped="0" failures="0" errors="0". Device-level coverage for theFragment-wiring sequences these unit tests cannot reach is in the linked tests PR; its one red
signal is a pre-existing defect confirmed identical on base and fix (see Known gaps).
Риск мержа
git revert, тестовый код и чистая экстракция без изменения внешнегоповедения.
WalletTransactionsFragment) — внешнийконтракт (БД, сеть, другие экраны) не менялся.
Критерии приёмки
cacheHasRows,loadStates.refresh,transactionsLoaded,isBuildingCache,cacheAdapterAttached,liveAdapter.itemCount, header-emptytransactionsListPolicy(...),WalletTransactionsFragment.ktloadStateFlow.collectLatestиisBuildingCache.observeTransactionsListPolicyTest.ktcachedRowsemission после detach → без повторного attach, empty view не меняетсяTransactionsListPolicyTest.ktTransactionsListPolicyTest.kt+ линкованный Appium-тест (красный — см. Known gaps)TransactionsListPolicyTest.ktВне задачи: нет.
Самопроверка: pre-review (3 раунда,
06b-prereview.md) нашла и это привело к исправлению 2блокирующих находок (round 2:
isBuildingCacheobserver не вызывалshowEmptyView()/showTransactionList(); round 3:lastRefreshStateне сбрасывался вonViewCreated). Финальныйраунд (SUGGESTIONS, 0 blocking) оставил 2 некритичных замечания открытыми: (1)
isBuildingCacheobserver не применяет
policy.swapToLive— безопасно сегодня по коррутин-инварианту, не поструктуре кода; (2) тест покрывает только чистую функцию, не Fragment-wiring — нужна инфраструктура
(Robolectric), которой в модуле нет.
Tests PR: abaranouski/dashwallet-auto#27
Summary by CodeRabbit