Skip to content

[WIP] Network Stack#2

Closed
jeiting wants to merge 43 commits into
masterfrom
feature/network-stack
Closed

[WIP] Network Stack#2
jeiting wants to merge 43 commits into
masterfrom
feature/network-stack

Conversation

@jeiting

@jeiting jeiting commented Mar 31, 2018

Copy link
Copy Markdown
Contributor

No description provided.

@jeiting jeiting changed the base branch from feature/ci to master March 31, 2018 00:17
@jeiting jeiting force-pushed the feature/network-stack branch from bd3bd26 to 47ac25e Compare March 31, 2018 00:18
jeiting added a commit that referenced this pull request May 1, 2018
[FINAL] Anonymous IDs and Finishing Touches
@jeiting jeiting closed this May 1, 2018
@vegaro vegaro deleted the feature/network-stack branch January 15, 2019 18:38
@vegaro vegaro mentioned this pull request Aug 27, 2020
facumenzella added a commit that referenced this pull request Jun 22, 2026
…ries current step

Adds a regression test for withCurrentWorkflowMetadata covering the
review finding #2 (CLOSE/EXIT_OFFER after a same-fingerprint step change).

Both workflow steps render the same screen so the presentation fingerprint
is identical and the impression is de-duped, forcing the code through the
withCurrentWorkflowMetadata branch (asserted via "no new impression"). The
exit offer event then must carry the updated step id.

Verified RED -> GREEN: with withCurrentWorkflowMetadata neutralized the test
fails; with it restored it passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011qCKrb3h5JJyBvgP9sw11m
vegaro pushed a commit that referenced this pull request Jun 23, 2026
…3636)

### Motivation

Follow-up to #3603 (cc @vegaro). That PR threads `presented_workflow_id`
/ `presented_step_id` through the post-receipt pipeline. While reviewing
it I found two coverage gaps, one of which is significant. This PR
**targets the #3603 branch** so the tests land with the feature.

### Changes

**1. `PostReceiptHelper` resolution coverage** (`PostReceiptHelperTest`)

The new resolution logic in `PostReceiptHelper` was only exercised
indirectly (`BackendTest` covers the wire format given explicit
metadata; `PaywallViewModelWorkflowTest` covers event creation). Added:

- resolves workflow metadata from the live presented paywall event
- omits workflow metadata when the presented event has no workflow (pins
the "both-or-neither" rule of `WorkflowMetadata.from`)
- replays cached workflow metadata on unsynced retry
(`postRemainingCachedTransactionMetadata`)

Supporting: `mockPostReceiptSuccess` now matches `workflowMetadata =
any()` (an omitted defaulted arg in MockK binds `eq(null)`), so the
success path can post non-null workflow metadata. Existing tests
unaffected.

**2. Fixed a vacuous re-presentation test + added EXIT_OFFER coverage**
(`PaywallViewModelWorkflowTest`)

The feature's own regression test, `purchase initiated after same
paywall workflow re-presentation carries current step metadata`, did
**not** actually exercise `withCurrentWorkflowMetadata`. Its two steps
pointed at different screens (`screen-1` vs `screen-2`), producing
different presentation fingerprints, so the second impression took the
**else** branch and recreated fresh event data, reading the live step.
The test passed even with `withCurrentWorkflowMetadata` removed.

- Reworked that test so both steps render the **same screen** (identical
fingerprint → de-dup branch is taken), with a "no new impression"
assertion proving the branch was reached.
- Added a sibling test for `EXIT_OFFER` after the same-fingerprint
re-presentation.
- Both verified **RED → GREEN**: with `withCurrentWorkflowMetadata`
neutralized they fail (`expected "step-2" but was "step-1"`); restored,
they pass.

### Validation

- `./gradlew :purchases:testDefaultsBc8DebugUnitTest --tests
"com.revenuecat.purchases.PostReceiptHelperTest"` , 86 tests, 0
failures.
- `./gradlew :ui:revenuecatui:testDefaultsBc8DebugUnitTest --tests
"com.revenuecat.purchases.ui.revenuecatui.data.PaywallViewModelWorkflowTest"`
, 0 failures.
- RED→GREEN proof captured by neutralizing the
`withCurrentWorkflowMetadata` line (run under JDK 21).

> [!IMPORTANT]
> Before #3603 merges: its `withCurrentWorkflowMetadata` change had no
test that exercised it (the existing regression test was vacuous). This
PR closes that gap. Recommend not approving #3603 until these tests are
in.

<details>
<summary>AI session context</summary>

# AI Context

## Metadata

- PR: this PR (base: `cesar/receipt-presented-paywall-workflow-ids`, the
#3603 branch)
- Branch: `facu/pr3603-postreceipt-workflow-tests`
- Author / human owner: facumenzella
- Agent(s): Claude Code, Opus 4.8 (1M context)
- Session source: current conversation
- Generated: 2026-06-22
- Context document version: 2

## Goal

Close test-coverage gaps found while reviewing #3603: (a)
`PostReceiptHelper`-layer workflow-metadata resolution, and (b) the
`withCurrentWorkflowMetadata` re-presentation behavior, whose existing
regression test turned out to be vacuous.

## Initial Prompt

Review #3603. The review surfaced coverage gaps; follow-ups were "write
a test for 1", "open a draft targeting this pr and mention this", then
"write it [finding #2] and put it in the same pr".

## Important Follow-up Prompts

- "Can you write a test for 1" , PostReceiptHelper coverage.
- "open a draft targetting this pr and mention this" , open this PR
against the #3603 branch.
- "write it and put it in the same pr" , add the finding #2
(CLOSE/EXIT_OFFER) test.
- Decision: "Fix it in my PR" , rework vegaro's vacuous
PURCHASE_INITIATED test here rather than only flagging it.

## Agent Contribution

- Added 3 `PostReceiptHelperTest` tests + made `mockPostReceiptSuccess`
workflow-agnostic.
- Added an `EXIT_OFFER` re-presentation test in
`PaywallViewModelWorkflowTest`.
- Discovered (via a neutralize + sentinel experiment) that the existing
PURCHASE_INITIATED re-presentation test never reached the
`withCurrentWorkflowMetadata` branch; reworked it to share one screen
and added a "no new impression" guard.
- Verified RED→GREEN for both UI tests by neutralizing the production
line.

## Human Decisions

- Open a separate branch / draft PR against the #3603 feature branch
rather than pushing onto @vegaro's branch.
- Fix the vacuous existing test inside this PR.

## Key Implementation Decisions

- Decision: force the same presentation fingerprint by pointing both
workflow steps at the same `screenId`.
- Rationale: the de-dup branch (where `withCurrentWorkflowMetadata`
lives) only runs when fingerprints match; different screens silently
routed the test through fresh re-creation.
- Rejected: leaving the original different-screen fixture (it does not
test the fix).
- Decision: assert "no new IMPRESSION" after the re-presentation.
- Rationale: proves the de-dup branch was taken; this is the guard that
distinguishes a real test from a vacuous one.
- Decision: `mockPostReceiptSuccess` uses `workflowMetadata = any()`.
  - Rationale: omitted defaulted MockK arg binds `eq(null)`.

## Files / Symbols Touched

-
`purchases/src/test/java/com/revenuecat/purchases/PostReceiptHelperTest.kt`
  - Why: PostReceiptHelper-layer resolution coverage.
- Symbols: `mockPostReceiptSuccess`, new `@Test`s (presented-paywall
resolution, no-workflow omission,
`postRemainingCachedTransactionMetadata`).
-
`ui/revenuecatui/src/test/kotlin/com/revenuecat/purchases/ui/revenuecatui/data/PaywallViewModelWorkflowTest.kt`
- Why: make the re-presentation test exercise
`withCurrentWorkflowMetadata`; add EXIT_OFFER coverage.
- Symbols: `purchase initiated after same paywall workflow
re-presentation...`, `exit offer after same paywall workflow
re-presentation...`.

## Dependencies / Config / Migrations

- None.

## Validation

- Commands run:
- `:purchases:testDefaultsBc8DebugUnitTest --tests
"...PostReceiptHelperTest"`: 86 tests, 0 failures.
- `:ui:revenuecatui:testDefaultsBc8DebugUnitTest --tests
"...PaywallViewModelWorkflowTest"`: 0 failures.
- RED check: with `withCurrentWorkflowMetadata` neutralized, both
re-presentation tests fail (`expected "step-2" but was "step-1"`);
restored, they pass.
- Manual verification: Not run (test-only change).
- CI: Not captured at time of writing.

## Validation Gaps

- The cached-vs-live precedence in `PostReceiptHelper` is exercised via
the live and retry paths but not via a dedicated synchronous-purchase
test where `getLocalTransactionMetadata` returns metadata.
- Local runs required JDK 21 (project `.sdkmanrc` pins `21.0.6-librca`);
default daemon here was JDK 17, which Robolectric rejects for Android
SDK 36.

## Review Focus

- Confirm the "no new impression" assertion correctly captures the
de-dup branch for both UI tests.
- Confirm `mockPostReceiptSuccess`'s `workflowMetadata = any()`
relaxation does not weaken the negative-case test (`...has no
workflow`), which asserts `workflowMetadata = null` explicitly.

## Risks / Reviewer Notes

- Risk: test-only change; no production behavior altered.
- Evidence: diff touches only `*Test.kt` files (the PaywallViewModel
edit during RED→GREEN was reverted; prod tree confirmed clean).
  - Mitigation: none needed.

## Non-goals / Out of Scope

- No production code changes; `withCurrentWorkflowMetadata` itself is
unchanged.

## Omitted Context

- Raw transcript, unrelated exploration, sensitive details, repetitive
attempts, and chain-of-thought-style content were omitted.

</details>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant