Skip to content

test(caching): cover workflow metadata disk round-trip#3640

Merged
vegaro merged 1 commit into
cesar/receipt-presented-paywall-workflow-idsfrom
facu/pr3603-localtxn-workflow-roundtrip
Jun 23, 2026
Merged

test(caching): cover workflow metadata disk round-trip#3640
vegaro merged 1 commit into
cesar/receipt-presented-paywall-workflow-idsfrom
facu/pr3603-localtxn-workflow-roundtrip

Conversation

@facumenzella

@facumenzella facumenzella commented Jun 23, 2026

Copy link
Copy Markdown
Member

Motivation

Follow-up test coverage for #3603. That PR's refactor commit (b2bfd86) fixed a bug where workflowId/stepId were @Transient on the cached transaction metadata and were lost on the disk round-trip, so presented_workflow_id / presented_step_id would be sent as null on retry or unsynced replay. The field was promoted to a first-class workflowMetadata on LocalTransactionMetadata with @SerialName("workflow_metadata"), but there was no regression test asserting it actually survives serialization.

What this adds

One test in LocalTransactionMetadataStoreTest, cacheLocalTransactionMetadata round-trips workflow metadata, mirroring the existing handles paywall data test. The JSON written to SharedPreferences is captured and fed back to getLocalTransactionMetadata, so the real JsonTools.json encode/decode runs (only SharedPreferences I/O is mocked).

Verification (RED → GREEN)

  • RED: with workflowMetadata marked @Transient, the test fails at the assertion (retrieved?.workflowMetadata is null).
  • GREEN: with @SerialName("workflow_metadata") (current state), it passes.

Ran :purchases:testDefaultsBc8DebugUnitTest --tests "...LocalTransactionMetadataStoreTest" locally (JDK 21).

Companion to #3636 (which covers the PostReceiptHelper threading and replay paths). Together they close the two test gaps identified in review of #3603.

AI session context

Task: Review #3603 ("is anything missing?"), then close the identified test gaps.

Findings from review of #3603:

  1. (important) Disk round-trip of workflowMetadata untested, the exact bug b2bfd86 fixed. LocalTransactionMetadataStoreTest had the analogous handles paywall data round-trip test but nothing for workflowMetadata.
  2. (important) PostReceiptHelper threading untested (only an any() count bumped). → covered by test(receipts): cover PostReceiptHelper workflow metadata resolution #3636.

This PR addresses finding #1.

Decisions:

  • Reused the existing capture-the-written-JSON pattern so the test exercises real serialization, not a mock, which is what makes it a genuine guard for the @Transient regression.
  • Based on cesar/receipt-presented-paywall-workflow-ids because the workflowMetadata field only exists there, not on main.

Verified: RED→GREEN as described above. Production code (LocalTransactionMetadata.kt) left unchanged; only the test file is added.

Not done: The remaining review items on #3603 were questions, not test gaps (all-or-nothing WorkflowMetadata.from, impression/purchase step-id divergence under dedup, pr:other vs pr:fix label). Not addressed here.

🤖 Generated with Claude Code


Note

Low Risk
Test-only change with no runtime behavior modifications.

Overview
Adds a regression test in LocalTransactionMetadataStoreTest so workflowMetadata on cached local transaction metadata survives the same SharedPreferences JSON encode/decode path used in production.

The test mirrors the existing paywall round-trip pattern: capture the JSON written on cache, feed it back on read, and assert workflowId / stepId are unchanged. It is meant to catch a prior failure mode where workflow fields were not persisted (e.g. @Transient), which would drop presented_workflow_id / presented_step_id on retry or replay.

No production code changes in this PR—test coverage only.

Reviewed by Cursor Bugbot for commit 87b6234. Bugbot is set up for automated code reviews on this repo. Configure here.

Adds a serialization round-trip test for LocalTransactionMetadata.workflowMetadata,
mirroring the existing `handles paywall data` test: the JSON written to
SharedPreferences is captured and fed back to getLocalTransactionMetadata, so the
real encode/decode runs (only SharedPreferences I/O is mocked).

This guards the fix in b2bfd86, where workflowId/stepId were @transient and lost
on the disk round-trip. Verified RED->GREEN: with the field marked @transient the
test fails at the assertion; with @SerialName("workflow_metadata") it passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YT7tYKySCS7wAHEmXjQEaf
@vegaro vegaro marked this pull request as ready for review June 23, 2026 12:27
@vegaro vegaro requested a review from a team as a code owner June 23, 2026 12:27
@vegaro vegaro merged commit 9dd8610 into cesar/receipt-presented-paywall-workflow-ids Jun 23, 2026
33 of 34 checks passed
@vegaro vegaro deleted the facu/pr3603-localtxn-workflow-roundtrip branch June 23, 2026 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants