Revert "shop: browse from the R2 catalog when offline"
- Commit
4be93b4e3edf6dca5a66e0a92abbc1ab4f97ff88- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-25 23:47 UTC (10 days ago)
- Parents
d92806d
This reverts commit d92806dda5b438451ffb579adbe0c7a977b1c500.
Diff
shop/AGENTS.md
diff --git a/shop/AGENTS.md b/shop/AGENTS.mdindex 79e082c544..0754c34501 100644--- a/shop/AGENTS.md+++ b/shop/AGENTS.md@@ -9,12 +9,10 @@ Entry types: MainActivity, Route, Navigation. Navigation remains a root-only gra - The `network/` package holds only the thin `ShopBackend` interface + DTOs over `library:network`. Dated discovery, REST/MCP transport, versioning, SSRF guards, wire limits, and the idempotency ledger live server-side. - Anonymous catalog and checkout preparation using supported UCP 2026-08-25 and 2026-04-08 profiles, resolved server-side. The server selects one complete advertised profile and exact capability/service versions; it never merges releases. - Server error codes mirror the client `UcpError` (`transport | rate_limited | http | malformed | rpc | unsupported | uncertain`, plus `retryAfterMs`): `unsupported` routes to the merchant website, anything else on a write is uncertain and never auto-retried on either side.-- Offline catalog: the server publishes `shop/v1/catalog.json` (schema 1) to the static R2 bucket hourly (`CatalogStore` downloads/caches it in app-private storage, replacing only on a newer `generated_at`). Its merchant list is the complete directory and is browsable/searchable offline; its products are a capped seed-query snapshot, not a full enumeration (UCP has no browse/list endpoint, so stores without a sampled product are live-search-only — `coverage.search_only_stores` counts them). Product images keep the proxied `/shop/v1/image?url=` URLs; no images are bulk-copied to R2, and the image cache renders them offline after first view. When the live search fails, `ShopViewModel.search` falls back to the local snapshot and `SearchContent` labels results "Offline catalog · prices as of <generated_at> · confirmed at checkout". Offline product detail is seeded from the snapshot but cart actions still require the live detail verification in `ProductScreen`. - Every search is a full search: the server embeds directory merchants (name + description), picks the few closest to the query, and searches them alongside the Global Catalog. There is no merchant directory tab or domain field; a merchant-scoped search only comes from an opened merchant link and is dismissible. - Directory merchant links open in the app via an unverified intent-filter generated into `AndroidManifest.xml` by `scripts/shop/generate_merchant_links.py` (rerun per release). Product URLs (`/products/<handle>`) open the product; other URLs open a scoped search. A one-time card sends the user to "Open by default" to approve the hosts. - The buyer profile (first name, last name, email, phone required; delivery address optional) is stored only in the module's SQLCipher Room database (`ProfileRepository`). The app is locked behind the profile form until the required fields validate; the Profile tab edits it. - Checkout takes no buyer input: every session field comes from the saved profile (`ProfileCheckout`). Merchant shipping-option choices remain selectable. Merchant totals and legal links are authoritative.-- Checkout always revalidates prices live: cart prices are add-time snapshots, the merchant session created by `checkoutStore` is authoritative, and `ShopCatalog.priceRevalidationNote` surfaces a message in Cart when the live subtotal differs from the snapshot. Nothing in the offline catalog is used by checkout, orders, or order-status calls, which keep using `ShopBackend` unchanged. - Checkout is one tap (a per-store Checkout button in Cart, or Buy now): `ShopViewModel.checkoutStore` creates a fresh session carrying the whole profile (name, contact, address) with a stable idempotency key, then opens the merchant's `continue_url` (from the session or a rejection) in Embedded Checkout. There is no in-app review screen. Never replay an uncertain mutation automatically. - Preserve cart lines through partial failures and browser handoffs. A session or browser return is not a paid order. - Delivery tracking comes from UCP order webhooks received server-side (`POST /shop/v1/order-webhooks`: RFC 9421 from generic UCP businesses via the platform profile's `webhook_url`, or Shopify HMAC once a partner manager has registered the URL) and from UCP `get_order`. The server identifies the platform the spec-native way, with no API keys: when `SHOP_SIGNING_KEY` is set it signs every merchant request (RFC 9421, ES256) and publishes the public JWK in `/.well-known/ucp` (`keys[]`; plus `signing_keys[]` in 2026-04-08). A 401 from a business retries once unsigned. Checkout creation returns an opaque `trackingToken`; the app stores it on the pending record, and `ec.complete` updates that same record (adding the merchant `orderId`) rather than adding a new one. The Orders tab and an hourly `OrderTrackingWorker` (scheduled only while a placed order is undelivered) poll `POST /shop/v1/orders/status` with `{token, orderId}`; the server reads `get_order` at most every 10 minutes per order and accepts a result only if its `checkout_id` matches that token's checkout. Status changes post "Delivery updates" notifications. Tracking records are PII-free (no destinations or buyer data); the merchant's `permalink_url` stays the authoritative order page.@@ -28,7 +26,6 @@ Entry types: MainActivity, Route, Navigation. Navigation remains a root-only gra ## Responsibilities - `ShopBackend` owns the five server calls (search/product/checkout/merchants/order status) plus error-envelope mapping. It never talks to merchant hosts.-- `CatalogStore` (network/) owns the R2 catalog download/cache; `ShopCatalog` (data/) owns its pure local search, freshness, and price-revalidation logic. (search/product/checkout/merchants/order status) plus error-envelope mapping. It never talks to merchant hosts. - ShopViewModel owns the cart, profile and the in-flight one-tap checkout. Buyer PII must never enter logs or persisted history; the encrypted profile database is its only store. - Local stores retain pending checkout records for browser recovery plus placed orders with their server tracking projection. - UI uses shared app scaffolds and controls; one public composable per file. Metadata previews are class members with PreviewTest and Preview.
shop/src/main/java/com/vayunmathur/shop/data/ShopCatalog.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/data/ShopCatalog.kt b/shop/src/main/java/com/vayunmathur/shop/data/ShopCatalog.ktdeleted file mode 100644index d61410552b..0000000000--- a/shop/src/main/java/com/vayunmathur/shop/data/ShopCatalog.kt+++ /dev/null@@ -1,117 +0,0 @@-package com.vayunmathur.shop.data--import com.vayunmathur.shop.network.ShopProduct-import kotlinx.serialization.SerialName-import kotlinx.serialization.Serializable-import java.time.Instant--/**- * Offline catalog published by the server to R2- * (`https://static.maproj.org/shop/v1/catalog.json`, schema 1).- *- * Coverage is honest by construction: [merchants] is the complete- * directory, [products] is a capped seed-query snapshot — UCP has no- * browse/list endpoint, so stores without a sampled product are- * search-only via the live API. Prices/availability are as of- * [generatedAt] and are always revalidated at checkout (the merchant- * session totals are authoritative; see [priceRevalidationNote]).- */-@Serializable-data class ShopCatalogFile(- val schema: Int = 0,- @SerialName("generated_at") val generatedAt: String = "",- val coverage: CatalogCoverage = CatalogCoverage(),- val merchants: List<CatalogMerchantEntry> = emptyList(),- val products: List<ShopProduct> = emptyList(),-)--/** Immutable value describing catalog coverage. */-@Serializable-data class CatalogCoverage(- @SerialName("directory_merchants") val directoryMerchants: Int = 0,- @SerialName("merchants_included") val merchantsIncluded: Int = 0,- @SerialName("product_count") val productCount: Int = 0,- @SerialName("stores_with_products") val storesWithProducts: Int = 0,- @SerialName("search_only_stores") val searchOnlyStores: Int = 0,- val note: String = "",-)--/** Immutable value describing catalog merchant entry. */-@Serializable-data class CatalogMerchantEntry(- val name: String = "",- val domain: String = "",- val description: String = "",-)--/** Pure offline-catalog logic: local search, lookup, freshness, price checks. */-object ShopCatalog {- const val SCHEMA = 1-- /** Catalogs older than this are shown as stale; checkout never trusts them either way. */- const val STALE_AFTER_MS = 26 * 60 * 60 * 1000L-- fun generatedAtMs(catalog: ShopCatalogFile): Long =- runCatching { Instant.parse(catalog.generatedAt).toEpochMilli() }.getOrDefault(0L)-- fun isStale(catalog: ShopCatalogFile, nowMs: Long): Boolean =- generatedAtMs(catalog).let { it == 0L || nowMs - it > STALE_AFTER_MS }-- /** Accept only the schema this build understands; anything else stays live-only. */- fun isUsable(catalog: ShopCatalogFile): Boolean = catalog.schema == SCHEMA-- /**- * Offline search over the snapshot: every query token must appear in- * title/description/store/domain. Scoped when [shop] is set. This is- * a substring sample search, not the server's ranked full search.- */- fun search(catalog: ShopCatalogFile, query: String, shop: String? = null, limit: Int = 40): List<ShopProduct> {- val tokens = query.lowercase().split(Regex("\\s+")).filter { it.isNotBlank() }- if (tokens.isEmpty() || !isUsable(catalog)) return emptyList()- return catalog.products.filter { product ->- (shop.isNullOrBlank() || product.shopDomain.equals(shop, ignoreCase = true)) &&- tokens.all { token ->- product.title.lowercase().contains(token) ||- product.description.lowercase().contains(token) ||- product.storeName.lowercase().contains(token) ||- product.shopDomain.lowercase().contains(token)- }- }.take(limit.coerceIn(1, 50))- }-- /** Offline merchant browse: token match over name/domain/description. */- fun searchMerchants(catalog: ShopCatalogFile, query: String, limit: Int = 40): List<CatalogMerchantEntry> {- val tokens = query.lowercase().split(Regex("\\s+")).filter { it.isNotBlank() }- if (!isUsable(catalog)) return emptyList()- if (tokens.isEmpty()) return catalog.merchants.take(limit.coerceIn(1, 50))- return catalog.merchants.filter { merchant ->- tokens.all { token ->- merchant.name.lowercase().contains(token) ||- merchant.domain.lowercase().contains(token) ||- merchant.description.lowercase().contains(token)- }- }.take(limit.coerceIn(1, 50))- }-- fun productByVariant(catalog: ShopCatalogFile, variantId: String): ShopProduct? =- catalog.products.firstOrNull { product -> product.variants.any { it.id == variantId } }-- /**- * Honest checkout UX: when the live merchant subtotal differs from- * the cart's snapshot (catalog or earlier search) prices, say so.- * Returns null when they agree (per currency). The live total the- * merchant charges is never overridden by the snapshot.- */- fun priceRevalidationNote(lines: List<CartLine>, liveSubtotal: Money): String? {- if (lines.isEmpty()) return null- if (lines.any { it.unitPrice.currency != liveSubtotal.currency }) {- return "Prices were confirmed with the store at checkout and may differ from the prices shown earlier."- }- val snapshot = lines.sumOf { it.unitPrice.amount * it.quantity }- return if (snapshot != liveSubtotal.amount) {- "The store updated its prices at checkout. The checkout total is the price you will pay."- } else {- null- }- }-}
shop/src/main/java/com/vayunmathur/shop/network/CatalogStore.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/network/CatalogStore.kt b/shop/src/main/java/com/vayunmathur/shop/network/CatalogStore.ktdeleted file mode 100644index 71c5eb817a..0000000000--- a/shop/src/main/java/com/vayunmathur/shop/network/CatalogStore.kt+++ /dev/null@@ -1,61 +0,0 @@-package com.vayunmathur.shop.network--import android.content.Context-import com.vayunmathur.library.network.NetworkClient-import com.vayunmathur.shop.data.ShopCatalog-import com.vayunmathur.shop.data.ShopCatalogFile-import kotlinx.coroutines.withTimeout-import kotlinx.serialization.decodeFromString-import kotlinx.serialization.json.Json-import java.io.File--/**- * Downloads and caches the R2 offline catalog- * (`static.maproj.org/shop/v1/catalog.json`). The file lives in- * app-private storage; a refresh replaces it only when the server's- * `generated_at` is newer, so offline browsing survives with no- * network and costs one conditional download per app run at most.- * Checkout never reads this: it stays on [ShopBackend]'s live calls.- */-object CatalogStore {- const val CATALOG_URL = "https://static.maproj.org/shop/v1/catalog.json"- private const val FILE_NAME = "shop-catalog.json"- private val json = Json { ignoreUnknownKeys = true }-- /** Injectable for tests; the production fetcher uses the shared stack. */- internal var fetch: suspend (String) -> String? = { url ->- runCatching {- withTimeout(30_000) {- NetworkClient.execute(- url, "GET",- headers = mapOf("Accept" to "application/json"),- followRedirects = true,- connectTimeoutMs = 10_000,- readTimeoutMs = 20_000,- )- }.takeIf { it.status in 200..299 }?.text- }.getOrNull()- }-- fun parse(body: String): ShopCatalogFile? =- runCatching { json.decodeFromString<ShopCatalogFile>(body) }- .getOrNull()- ?.takeIf(ShopCatalog::isUsable)-- fun cached(context: Context): ShopCatalogFile? =- runCatching { parse(File(context.filesDir, FILE_NAME).readText()) }.getOrNull()-- /** Newer-catalog-wins merge decision, pure for testing. */- fun shouldReplace(current: ShopCatalogFile?, incoming: ShopCatalogFile): Boolean =- current == null ||- ShopCatalog.generatedAtMs(incoming) > ShopCatalog.generatedAtMs(current)-- suspend fun refresh(context: Context): ShopCatalogFile? {- val current = cached(context)- val body = fetch(CATALOG_URL) ?: return current- val incoming = parse(body) ?: return current- if (!shouldReplace(current, incoming)) return current- runCatching { File(context.filesDir, FILE_NAME).writeText(body) }- return incoming- }-}
shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt b/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.ktindex b2596ad523..babbced3d0 100644--- a/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt+++ b/shop/src/main/java/com/vayunmathur/shop/platform/ShopViewModel.kt@@ -32,11 +32,7 @@ import com.vayunmathur.shop.domain.OrderTrackingUpdates import com.vayunmathur.shop.domain.ProfileCheckout import com.vayunmathur.shop.network.ShopBackend import com.vayunmathur.shop.network.ShopBackendException-import com.vayunmathur.shop.network.CatalogStore-import com.vayunmathur.shop.data.ShopCatalog-import com.vayunmathur.shop.data.ShopCatalogFile import com.vayunmathur.shop.network.ShopHttpBackend-import com.vayunmathur.shop.network.toModel import kotlinx.coroutines.launch private const val MAX_QUANTITY = 99@@ -66,17 +62,6 @@ class ShopViewModel( private set var results by mutableStateOf<List<UcpProduct>>(emptyList()) private set- /** True when [results] came from the offline R2 catalog, not the live API. */- var resultsFromCatalog by mutableStateOf(false)- private set- /** `generated_at` of the catalog in use, for the freshness label. */- var catalogGeneratedAt by mutableStateOf<String?>(null)- private set- /** Set at checkout when live merchant prices differ from cart snapshot prices. */- var checkoutPriceNote by mutableStateOf<String?>(null)- private set- var catalog: ShopCatalogFile? = null- private set var searching by mutableStateOf(false) private set var searchError by mutableStateOf<String?>(null)@@ -174,9 +159,6 @@ class ShopViewModel( nativeCheckout.forget(platformId, shop) submitFromProfile(platformId, shop, lines, sink) val state = nativeCheckout.snapshot.firstOrNull { it.platformId == platformId && it.shopDomain == shop }- checkoutPriceNote = state?.checkout?.totals?.subtotal?.let {- ShopCatalog.priceRevalidationNote(lines, it)- } val url = (state?.checkout?.continueUrl?.let(MerchantUrls::httpsUrl)) ?: state?.handoffUrl if (url != null && openEmbeddedCheckout(platformId, shop, url, dark)) { onReady()@@ -302,24 +284,6 @@ class ShopViewModel( } } - /** Download/refresh the R2 catalog once; failures keep any cached copy. */- fun loadCatalog(context: Context) {- if (catalog != null) return- catalog = CatalogStore.cached(context)- catalog?.let { catalogGeneratedAt = it.generatedAt }- viewModelScope.launch {- AppInit.awaitReady()- CatalogStore.refresh(context)?.let {- catalog = it- catalogGeneratedAt = it.generatedAt- }- }- }-- /** Offline product copy for detail fallback; live detail still verifies before cart actions. */- fun catalogProduct(variantId: String): UcpProduct? =- catalog?.let { ShopCatalog.productByVariant(it, variantId) }?.toModel()- fun search() { val q = query.trim() if (q.isEmpty() || searching) return@@ -332,18 +296,8 @@ class ShopViewModel( try { AppInit.awaitReady() backend.search(q, shop, limit = SEARCH_LIMIT).fold(- onSuccess = { results = it; resultsFromCatalog = false },- onFailure = { error ->- val offline = catalog?.let { ShopCatalog.search(it, q, shop, SEARCH_LIMIT) }- ?.map { it.toModel() }- if (!offline.isNullOrEmpty()) {- results = offline- resultsFromCatalog = true- searchError = null- } else {- searchError = error.toBackendMessage()- }- },+ onSuccess = { results = it },+ onFailure = { searchError = it.toBackendMessage() }, ) } finally { searching = false
shop/src/main/java/com/vayunmathur/shop/ui/CartScreen.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/CartScreen.kt b/shop/src/main/java/com/vayunmathur/shop/ui/CartScreen.ktindex ae20061fd1..e46c763092 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/CartScreen.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/CartScreen.kt@@ -61,10 +61,7 @@ fun CartScreen( onCheckoutStore = { platformId, shop -> viewModel.checkoutStore( platformId, shop, context, dark,- onReady = {- viewModel.checkoutPriceNote?.let(messenger::show)- onPayInApp(platformId, shop)- },+ onReady = { onPayInApp(platformId, shop) }, onError = messenger::show, ) },
shop/src/main/java/com/vayunmathur/shop/ui/ProductScreen.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/ProductScreen.kt b/shop/src/main/java/com/vayunmathur/shop/ui/ProductScreen.ktindex 55c3721073..f943a1e630 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/ProductScreen.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/ProductScreen.kt@@ -76,7 +76,7 @@ fun ProductScreen( val refreshFailedMessage = stringResource(R.string.product_refresh_failed) val addedToCartMessage = stringResource(R.string.added_to_cart) var product by remember(variantId, platformId, shopDomain) {- mutableStateOf((viewModel.results + viewModel.linkedProducts + listOfNotNull(viewModel.catalogProduct(variantId))).firstOrNull { candidate ->+ mutableStateOf((viewModel.results + viewModel.linkedProducts).firstOrNull { candidate -> candidate.platformId == platformId && candidate.variants.any { it.id == variantId && (candidate.shopDomain == shopDomain || it.shopDomain == shopDomain) }
shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt b/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.ktindex f203e87666..66e4bcee4a 100644--- a/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt+++ b/shop/src/main/java/com/vayunmathur/shop/ui/SearchScreen.kt@@ -64,7 +64,6 @@ fun SearchScreen( onProductClick: (variantId: String, platformId: String, shopDomain: String) -> Unit, ) { val context = LocalContext.current- LaunchedEffect(Unit) { viewModel.loadCatalog(context) } var showLinkPrompt by rememberSaveable { mutableStateOf(LinkDefaults.shouldPrompt(context)) } SearchContent( query = viewModel.query,@@ -76,7 +75,6 @@ fun SearchScreen( searchError = viewModel.searchError, searchedQuery = viewModel.searchedQuery, onRetry = viewModel::search,- offlineSince = if (viewModel.resultsFromCatalog) viewModel.catalogGeneratedAt else null, scopeName = viewModel.scopeName, onClearScope = viewModel::clearScope, focusRequest = viewModel.focusSearchRequest,@@ -110,7 +108,6 @@ internal fun SearchContent( searchError: String? = null, searchedQuery: String? = null, onRetry: () -> Unit = onSearch,- offlineSince: String? = null, ) { val focusManager = LocalFocusManager.current val focusRequester = remember { FocusRequester() }@@ -132,13 +129,6 @@ internal fun SearchContent( ), ) { padding -> Column(Modifier.fillMaxSize().padding(padding)) {- offlineSince?.let { since ->- Text(- "Offline catalog \u00b7 prices as of $since \u00b7 confirmed at checkout",- style = MaterialTheme.typography.bodySmall,- modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),- )- } linkPrompt?.let { LinkPromptCard(it) } scopeName?.let { name -> InputChip(
shop/src/test/java/com/vayunmathur/shop/data/ShopCatalogTest.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/data/ShopCatalogTest.kt b/shop/src/test/java/com/vayunmathur/shop/data/ShopCatalogTest.ktdeleted file mode 100644index 607ee5ebaf..0000000000--- a/shop/src/test/java/com/vayunmathur/shop/data/ShopCatalogTest.kt+++ /dev/null@@ -1,99 +0,0 @@-package com.vayunmathur.shop.data--import com.vayunmathur.shop.network.CatalogStore-import com.vayunmathur.shop.network.ShopMoney-import com.vayunmathur.shop.network.ShopProduct-import com.vayunmathur.shop.network.ShopVariant-import org.junit.Assert.assertEquals-import org.junit.Assert.assertFalse-import org.junit.Assert.assertNull-import org.junit.Assert.assertTrue-import org.junit.Test--class ShopCatalogTest {- private fun product(id: String, title: String, domain: String, variant: String) = ShopProduct(- id = id,- title = title,- description = "A $title for everyday use",- shopDomain = domain,- storeName = "Store $domain",- variants = listOf(ShopVariant(id = variant, title = "Default", price = ShopMoney(1_000, "USD"), available = true)),- )-- private fun catalog(products: List<ShopProduct>) = ShopCatalogFile(- schema = 1,- generatedAt = GENERATED_AT,- merchants = listOf(- CatalogMerchantEntry(name = "Shoe Shop", domain = "shoes.example", description = "Footwear"),- CatalogMerchantEntry(name = "Tea House", domain = "tea.example", description = "Loose leaf tea"),- ),- products = products,- )-- @Test- fun localSearchMatchesTokensAndScope() {- val c = catalog(- listOf(- product("1", "Red Shoes", "shoes.example", "v1"),- product("2", "Green Tea", "tea.example", "v2"),- ),- )- assertEquals(listOf("1"), ShopCatalog.search(c, "red shoes").map { it.id })- assertEquals(listOf("2"), ShopCatalog.search(c, "tea", shop = "tea.example").map { it.id })- assertTrue(ShopCatalog.search(c, "tea", shop = "shoes.example").isEmpty())- assertTrue(ShopCatalog.search(c, " ").isEmpty())- }-- @Test- fun merchantBrowseAndVariantLookup() {- val c = catalog(listOf(product("1", "Red Shoes", "shoes.example", "v1")))- assertEquals("tea.example", ShopCatalog.searchMerchants(c, "loose leaf").single().domain)- assertEquals(2, ShopCatalog.searchMerchants(c, "").size)- assertEquals("1", ShopCatalog.productByVariant(c, "v1")?.id)- assertNull(ShopCatalog.productByVariant(c, "missing"))- }-- @Test- fun schemaGateAndFreshness() {- val c = catalog(emptyList())- assertTrue(ShopCatalog.isUsable(c))- assertFalse(ShopCatalog.isUsable(c.copy(schema = 99)))- assertFalse(ShopCatalog.isStale(c, GENERATED_MS + 60_000))- assertTrue(ShopCatalog.isStale(c, GENERATED_MS + ShopCatalog.STALE_AFTER_MS + 1))- assertTrue(ShopCatalog.isStale(c.copy(generatedAt = "junk"), GENERATED_MS))- }-- @Test- fun priceRevalidationOnlyWhenLiveDiffers() {- val lines = listOf(- CartLine(variantId = "v1", unitPrice = Money(1_000, "USD"), quantity = 2, shopDomain = "a.example"),- )- assertNull(ShopCatalog.priceRevalidationNote(lines, Money(2_000, "USD")))- assertTrue(ShopCatalog.priceRevalidationNote(lines, Money(2_500, "USD"))!!.contains("updated"))- assertTrue(ShopCatalog.priceRevalidationNote(lines, Money(2_000, "EUR"))!!.contains("confirmed"))- assertNull(ShopCatalog.priceRevalidationNote(emptyList(), Money(0, "USD")))- }-- @Test- fun parseAndReplaceRules() {- val body = """- {"schema":1,"generated_at":"$GENERATED_AT","coverage":{"product_count":0},- "merchants":[{"name":"A","domain":"a.example","description":""}],- "products":[]}- """.trimIndent()- val parsed = CatalogStore.parse(body)- assertEquals("a.example", parsed?.merchants?.single()?.domain)- assertNull(CatalogStore.parse("""{"schema":99}"""))- assertNull(CatalogStore.parse("not json"))- val newer = parsed!!.copy(generatedAt = "2026-11-26T00:00:00Z")- assertTrue(CatalogStore.shouldReplace(parsed, newer))- assertFalse(CatalogStore.shouldReplace(newer, parsed))- assertTrue(CatalogStore.shouldReplace(null, parsed))- }-- private companion object {- const val GENERATED_AT = "2026-11-25T00:00:00Z"- // 2026-11-25T00:00:00Z- const val GENERATED_MS = 1_795_564_800_000L- }-}
shop/src/test/java/com/vayunmathur/shop/platform/ShopViewModelCoverage2Test.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/platform/ShopViewModelCoverage2Test.kt b/shop/src/test/java/com/vayunmathur/shop/platform/ShopViewModelCoverage2Test.ktindex 829e3e4963..9614ad37fa 100644--- a/shop/src/test/java/com/vayunmathur/shop/platform/ShopViewModelCoverage2Test.kt+++ b/shop/src/test/java/com/vayunmathur/shop/platform/ShopViewModelCoverage2Test.kt@@ -1,7 +1,5 @@ package com.vayunmathur.shop.platform -// FIXTURE RELATIVE-TIME EXCEPTION: timestamps are seeded relative to the wall clock the code under test reads internally, so the fresh/expired/relative-time branch under test keeps its meaning; a fixed past instant would silently change that branch.- import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.work.Configuration
shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensCoverage2Test.kt
diff --git a/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensCoverage2Test.kt b/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensCoverage2Test.ktindex 41e3300595..144d612467 100644--- a/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensCoverage2Test.kt+++ b/shop/src/test/java/com/vayunmathur/shop/ui/ShopScreensCoverage2Test.kt@@ -1,7 +1,5 @@ package com.vayunmathur.shop.ui -// FIXTURE RELATIVE-TIME EXCEPTION: timestamps are seeded relative to the wall clock the code under test reads internally, so the fresh/expired/relative-time branch under test keeps its meaning; a fixed past instant would silently change that branch.- import android.content.Context import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule