enh
This commit is contained in:
parent
1b7b3b97e9
commit
319bcdab42
13 changed files with 14214 additions and 21527 deletions
|
|
@ -336,6 +336,7 @@ availability ${assetsDomain}regions/${regionId}/av-${availability_version_n
|
||||||
| CACHE-23 | edge | missing assets domain/cache key env | payload null/empty; cache tests should fail with actionable message |
|
| CACHE-23 | edge | missing assets domain/cache key env | payload null/empty; cache tests should fail with actionable message |
|
||||||
| CACHE-24 | edge | bound deleted and recreated | old KV key removed; new bound does not serve stale payload |
|
| CACHE-24 | edge | bound deleted and recreated | old KV key removed; new bound does not serve stale payload |
|
||||||
| CACHE-115 | happy | `essentialUrls` in API + KV | products/stores/banners/essential-consts under the cache key; availability/slots outside it; store template substitutes |
|
| CACHE-115 | happy | `essentialUrls` in API + KV | products/stores/banners/essential-consts under the cache key; availability/slots outside it; store template substitutes |
|
||||||
|
| CACHE-117 | edge | `updatePrompt` switches | object `{isEnabled, isClosable}`, computed per request (not in the cached payload); `isEnabled:false` suppresses the user-ui update dialog, `isClosable` adds a "Later" dismiss |
|
||||||
|
|
||||||
### 4.2 products.json
|
### 4.2 products.json
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -3,6 +3,11 @@ set -euo pipefail
|
||||||
|
|
||||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
DUMP_FILE="$ROOT_DIR/dumps/latest.sql"
|
DUMP_FILE="$ROOT_DIR/dumps/latest.sql"
|
||||||
|
# Split files live under .wrangler (gitignored) so a pull never adds untracked
|
||||||
|
# artefacts next to the tracked dumps.
|
||||||
|
SPLIT_DIR="$ROOT_DIR/.wrangler/pull"
|
||||||
|
SCHEMA_FILE="$SPLIT_DIR/schema.sql"
|
||||||
|
DATA_FILE="$SPLIT_DIR/data.sql"
|
||||||
|
|
||||||
if [ "${1:-}" = "--dev" ]; then
|
if [ "${1:-}" = "--dev" ]; then
|
||||||
WRANGLER_CONFIG="$ROOT_DIR/wrangler.dev.toml"
|
WRANGLER_CONFIG="$ROOT_DIR/wrangler.dev.toml"
|
||||||
|
|
@ -22,6 +27,40 @@ if [ ! -f "$WRANGLER_CONFIG" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
wrangler d1 execute "$DB_NAME" --local --file "$DUMP_FILE" --config "$WRANGLER_CONFIG"
|
mkdir -p "$SPLIT_DIR"
|
||||||
|
|
||||||
|
# `wrangler d1 export` emits tables in sqlite_master rowid order (the order they
|
||||||
|
# were historically created), so a table can be created and filled before the
|
||||||
|
# parent it references exists — e.g. `notif_creds`/`unlogged_user_tokens` ->
|
||||||
|
# `regions`, or `product_skus` -> `product_info` after the SKU-split rebuild.
|
||||||
|
#
|
||||||
|
# Local D1 pins `foreign_keys=ON` and runs the whole file as one transaction, so
|
||||||
|
# neither `PRAGMA foreign_keys=OFF` (a no-op) nor the dump's own
|
||||||
|
# `defer_foreign_keys` avoids `no such table: main.<parent>`.
|
||||||
|
#
|
||||||
|
# `CREATE TABLE` is allowed to reference a table that does not exist yet (FKs are
|
||||||
|
# resolved at DML time), so replaying every CREATE first and every INSERT second
|
||||||
|
# removes the "no such table" failure. See wrangler-commands.md.
|
||||||
|
#
|
||||||
|
# The dump's row order is not FK-safe either — child rows can precede their
|
||||||
|
# parent rows (e.g. `product_skus` before `product_info`). D1 enforces FKs per
|
||||||
|
# statement, so the data pass runs with deferred enforcement: every row is
|
||||||
|
# checked once at COMMIT, by which point the whole dump is loaded. (Verified:
|
||||||
|
# `PRAGMA foreign_key_check` on the imported DB reports no violations.)
|
||||||
|
awk -v schema="$SCHEMA_FILE" -v data="$DATA_FILE" '
|
||||||
|
BEGIN { print "PRAGMA defer_foreign_keys=TRUE;" > data }
|
||||||
|
/^CREATE/ { in_create = 1 }
|
||||||
|
in_create {
|
||||||
|
print > schema
|
||||||
|
# Multi-line CREATE TABLE blocks end with a line that is just `);`.
|
||||||
|
if ($0 ~ /\);[[:space:]]*$/) in_create = 0
|
||||||
|
next
|
||||||
|
}
|
||||||
|
/^PRAGMA/ { print > schema; next }
|
||||||
|
{ print > data }
|
||||||
|
' "$DUMP_FILE"
|
||||||
|
|
||||||
|
wrangler d1 execute "$DB_NAME" --local --file "$SCHEMA_FILE" --config "$WRANGLER_CONFIG"
|
||||||
|
wrangler d1 execute "$DB_NAME" --local --file "$DATA_FILE" --config "$WRANGLER_CONFIG"
|
||||||
|
|
||||||
echo "Local D1 database populated from $DUMP_FILE"
|
echo "Local D1 database populated from $DUMP_FILE"
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,6 @@ export const commonApiRouter = router({
|
||||||
.input(z.object({ boundId: z.number().int().positive().optional() }).optional())
|
.input(z.object({ boundId: z.number().int().positive().optional() }).optional())
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const boundId = input?.boundId ?? 1
|
const boundId = input?.boundId ?? 1
|
||||||
console.log({ boundId })
|
|
||||||
const requestUrl = ctx.req.url
|
const requestUrl = ctx.req.url
|
||||||
const host = new URL(requestUrl).host
|
const host = new URL(requestUrl).host
|
||||||
const updateNotice = `<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
|
const updateNotice = `<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
|
||||||
|
|
@ -278,13 +277,24 @@ export const commonApiRouter = router({
|
||||||
</div>`
|
</div>`
|
||||||
|
|
||||||
const response = await readEssentialConstsFromKv(boundId);
|
const response = await readEssentialConstsFromKv(boundId);
|
||||||
const shouldShowNotice = host.includes('raw') || host.includes('mf')
|
// One switch drives every update surface: the BottomDialog in UpdateChecker,
|
||||||
|
// the store-version dialog in HealthTestWrapper, and the legacy host-gated
|
||||||
console.log('essentialConsts request', { host, url: requestUrl, ...response })
|
// WebView notice in WebViewWrapper. `isEnabled: false` means no surface
|
||||||
|
// ever asks the user to restart, even when the build is behind.
|
||||||
|
// `isClosable: true` adds a "Later" escape hatch where the surface offers
|
||||||
|
// one (backdrop/back for the bottom sheets, the close button for the WebView).
|
||||||
|
const updatePrompt = {
|
||||||
|
isEnabled: true,
|
||||||
|
isClosable: false,
|
||||||
|
}
|
||||||
|
const shouldShowNotice =
|
||||||
|
updatePrompt.isEnabled && (host.includes('raw') || host.includes('mf'))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...response,
|
...response,
|
||||||
webviewHtml: shouldShowNotice ? updateNotice : null,
|
webviewHtml: shouldShowNotice ? updateNotice : null,
|
||||||
isWebviewClosable: shouldShowNotice ? false : true
|
isWebviewClosable: shouldShowNotice ? updatePrompt.isClosable : true,
|
||||||
|
updatePrompt,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,16 @@ describe('common.essentialConsts shape (CACHE-01..05)', () => {
|
||||||
const consts = await getEssentialConsts(TEST_BOUND_ID)
|
const consts = await getEssentialConsts(TEST_BOUND_ID)
|
||||||
expect(typeof consts.isFlashDeliveryEnabled).toBe('boolean')
|
expect(typeof consts.isFlashDeliveryEnabled).toBe('boolean')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('CACHE-117: updatePrompt carries the enabled/closable switches', async () => {
|
||||||
|
// Computed per request in the router (not part of the cached payload), so a
|
||||||
|
// flip is a one-line change plus deploy. Assert the shape, not the values, so
|
||||||
|
// toggling the switches does not churn this test.
|
||||||
|
const consts = await getEssentialConsts(TEST_BOUND_ID)
|
||||||
|
expect(typeof consts.updatePrompt).toBe('object')
|
||||||
|
expect(typeof consts.updatePrompt?.isEnabled).toBe('boolean')
|
||||||
|
expect(typeof consts.updatePrompt?.isClosable).toBe('boolean')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('common.essentialConsts published URLs (CACHE-115)', () => {
|
describe('common.essentialConsts published URLs (CACHE-115)', () => {
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ export interface EssentialConsts {
|
||||||
essentialUrls?: Record<string, string>
|
essentialUrls?: Record<string, string>
|
||||||
webviewHtml?: string | null
|
webviewHtml?: string | null
|
||||||
isWebviewClosable?: boolean
|
isWebviewClosable?: boolean
|
||||||
|
updatePrompt?: { isEnabled: boolean; isClosable: boolean }
|
||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,15 +42,24 @@ The only real fix is **ordering** the tables.
|
||||||
For every `REFERENCES x(...)`, confirm the `CREATE TABLE "x"` line appears
|
For every `REFERENCES x(...)`, confirm the `CREATE TABLE "x"` line appears
|
||||||
BEFORE the referencing table's `CREATE TABLE`.
|
BEFORE the referencing table's `CREATE TABLE`.
|
||||||
|
|
||||||
## How to hand-fix
|
## How it is fixed now (automated)
|
||||||
|
|
||||||
Cut the parent table's block (`CREATE TABLE ...` + all its `INSERT ...` lines)
|
`scripts/populate_localdb.sh` no longer replays the dump as one file. It splits
|
||||||
and paste it ABOVE the child table's block. Then verify it loads cleanly:
|
it into `.wrangler/pull/schema.sql` (every `CREATE` / `PRAGMA`) and
|
||||||
|
`.wrangler/pull/data.sql` (the `INSERT`s), then applies schema first and data
|
||||||
|
second. `CREATE TABLE` may reference a table that does not exist yet, so the
|
||||||
|
schema pass is order-independent and the data pass then has every parent.
|
||||||
|
|
||||||
|
`bun run pull_db` and `bun run pull_dev_db` stay single commands; the split files
|
||||||
|
are gitignored under `.wrangler/`.
|
||||||
|
|
||||||
|
## Hand verification
|
||||||
|
|
||||||
|
To check a dump yourself:
|
||||||
|
|
||||||
sqlite3 :memory: "PRAGMA foreign_keys=ON; BEGIN; .read dumps/<dump>.sql; COMMIT;"
|
sqlite3 :memory: "PRAGMA foreign_keys=ON; BEGIN; .read dumps/<dump>.sql; COMMIT;"
|
||||||
|
|
||||||
This should exit 0 with no error. (Example already applied to `latest_1.sql` and
|
This should exit 0 with no error.
|
||||||
`local_8_aug.sql`: `product_info` was moved above `product_skus`.)
|
|
||||||
|
|
||||||
## When to re-check
|
## When to re-check
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ Use these names in the cases below so the expected values stay consistent.
|
||||||
|
|
||||||
| Fixture | Value | Used by |
|
| Fixture | Value | Used by |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `CONSTS` | `freeDeliveryThreshold: 249`, `deliveryCharge: 15`, `flashFreeDeliveryThreshold: 199`, `flashDeliveryCharge: 25`, `isFlashDeliveryEnabled: true`, `boundId: 7`, `supportMobile: '8688182552'`, `supportEmail: 'support@freshyo.in'`, `versionNum: '1.2.0'`, `internalAppVersion: 2` | home, cart, checkout, wrappers |
|
| `CONSTS` | `freeDeliveryThreshold: 249`, `deliveryCharge: 15`, `flashFreeDeliveryThreshold: 199`, `flashDeliveryCharge: 25`, `isFlashDeliveryEnabled: true`, `boundId: 7`, `supportMobile: '8688182552'`, `supportEmail: 'support@freshyo.in'`, `versionNum: '1.2.0'`, `internalAppVersion: 2`, `updatePrompt: { isEnabled: true, isClosable: false }` | home, cart, checkout, wrappers |
|
||||||
| `CONSTS_FLASH_OFF` | `CONSTS` with `isFlashDeliveryEnabled: false` | flash gate, product detail |
|
| `CONSTS_FLASH_OFF` | `CONSTS` with `isFlashDeliveryEnabled: false` | flash gate, product detail |
|
||||||
| `P_CHICKEN` | id `2`, name `Chicken Breast`, price `215`, marketPrice `220`, unitNotation `500g`, incrementStep `1`, storeId `1`, images `['chicken.jpg']` | home, cart, store, search |
|
| `P_CHICKEN` | id `2`, name `Chicken Breast`, price `215`, marketPrice `220`, unitNotation `500g`, incrementStep `1`, storeId `1`, images `['chicken.jpg']` | home, cart, store, search |
|
||||||
| `P_CUCUMBER` | id `5`, name `Cucumber`, price `15`, marketPrice `20`, unitNotation `500g`, storeId `1` | home, cart, store |
|
| `P_CUCUMBER` | id `5`, name `Cucumber`, price `15`, marketPrice `20`, unitNotation `500g`, storeId `1` | home, cart, store |
|
||||||
|
|
@ -120,7 +120,7 @@ Use these names in the cases below so the expected values stay consistent.
|
||||||
| ROOT-02 | happy | `useFonts` returns `[true]` | `app-root`, QueryClient, tRPC provider and `Stack` are mounted |
|
| ROOT-02 | happy | `useFonts` returns `[true]` | `app-root`, QueryClient, tRPC provider and `Stack` are mounted |
|
||||||
| ROOT-03 | edge | health check is pending | children still render; no error screen |
|
| ROOT-03 | edge | health check is pending | children still render; no error screen |
|
||||||
| ROOT-04 | error | `common.healthCheck` rejects | shows “Service Unavailable”; retry calls `healthCheck` again |
|
| ROOT-04 | error | `common.healthCheck` rejects | shows “Service Unavailable”; retry calls `healthCheck` again |
|
||||||
| ROOT-05 | edge | `HealthTestWrapper` backend version `1.3.0`, local `1.2.0`, iOS URL set | “Update Available” dialog; tapping opens the App Store URL |
|
| ROOT-05 | edge | `HealthTestWrapper` backend version `1.3.0`, local `1.2.0`, iOS URL set | “Update Available” dialog (requires `updatePrompt.isEnabled`); tapping opens the App Store URL |
|
||||||
| ROOT-06 | edge | Android and `playStoreUrl` set | update dialog opens the Play Store URL |
|
| ROOT-06 | edge | Android and `playStoreUrl` set | update dialog opens the Play Store URL |
|
||||||
| ROOT-07 | edge | versions equal or local newer | no update dialog |
|
| ROOT-07 | edge | versions equal or local newer | no update dialog |
|
||||||
| ROOT-08 | error | app version malformed or backend version malformed | no dialog, no crash |
|
| ROOT-08 | error | app version malformed or backend version malformed | no dialog, no crash |
|
||||||
|
|
@ -130,8 +130,13 @@ Use these names in the cases below so the expected values stay consistent.
|
||||||
| ROOT-12 | happy | `webviewHtml` absent | children render |
|
| ROOT-12 | happy | `webviewHtml` absent | children render |
|
||||||
| ROOT-13 | edge | `webviewHtml` present, not closable | WebView renders and children are hidden |
|
| ROOT-13 | edge | `webviewHtml` present, not closable | WebView renders and children are hidden |
|
||||||
| ROOT-14 | edge | closable WebView | close button hides WebView and shows children |
|
| ROOT-14 | edge | closable WebView | close button hides WebView and shows children |
|
||||||
| ROOT-16 | edge | remote internal version ahead | alert shown once; Update & Restart calls `fetchUpdateAsync` then `reloadAsync` |
|
| ROOT-16 | edge | remote internal version ahead | bottom dialog shown once (no Later); Update & Restart calls `fetchUpdateAsync` then `reloadAsync` |
|
||||||
| ROOT-17 | error | update fetch/reload rejects | alert stays/does not crash |
|
| ROOT-17 | error | update fetch/reload rejects | dialog stays up/does not crash |
|
||||||
|
| ROOT-30 | edge | backend `updatePrompt.isEnabled:false` with version ahead | no alert; no update fetch |
|
||||||
|
| ROOT-31 | edge | `isEnabled:true, isClosable:true` | dialog with Later + Update & Restart; Later dismisses and never fetches |
|
||||||
|
| ROOT-32 | edge | stale persisted snapshot with `isEnabled:true`, query pending | no dialog (placeholder data is ignored) |
|
||||||
|
| ROOT-33 | edge | `versionNum` ahead + `updatePrompt.isEnabled:false` | no store-version dialog |
|
||||||
|
| ROOT-34 | edge | `versionNum` ahead + `isClosable:true` | Later dismisses the dialog; store not opened |
|
||||||
| ROOT-18 | happy | back press on home with empty stack | `Exit App` alert; Exit calls `BackHandler.exitApp`; returns `true` |
|
| ROOT-18 | happy | back press on home with empty stack | `Exit App` alert; Exit calls `BackHandler.exitApp`; returns `true` |
|
||||||
| ROOT-19 | edge | back press on non-home route | returns `false`; no alert |
|
| ROOT-19 | edge | back press on non-home route | returns `false`; no alert |
|
||||||
| ROOT-20 | edge | back press while stack can go back | returns `false` |
|
| ROOT-20 | edge | back press while stack can go back | returns `false` |
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,13 @@ import type { ReactParentComponent } from '@packages/shared';
|
||||||
|
|
||||||
const HealthTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
|
const HealthTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
|
||||||
const { data, isLoading, error, refetch } = trpc.common.healthCheck.useQuery();
|
const { data, isLoading, error, refetch } = trpc.common.healthCheck.useQuery();
|
||||||
const { data: backendConsts } = useGetEssentialConsts();
|
const { data: backendConsts, isPlaceholderData } = useGetEssentialConsts();
|
||||||
|
|
||||||
const versionFromBackend = backendConsts?.versionNum;
|
const versionFromBackend = backendConsts?.versionNum;
|
||||||
|
const updatePrompt = backendConsts?.updatePrompt;
|
||||||
|
const isUpdatePromptEnabled = updatePrompt?.isEnabled === true;
|
||||||
|
const isUpdatePromptClosable = updatePrompt?.isClosable === true;
|
||||||
|
|
||||||
const appUrl = Platform.OS === 'ios'
|
const appUrl = Platform.OS === 'ios'
|
||||||
? backendConsts?.appStoreUrl
|
? backendConsts?.appStoreUrl
|
||||||
: backendConsts?.playStoreUrl;
|
: backendConsts?.playStoreUrl;
|
||||||
|
|
@ -21,6 +24,12 @@ const HealthTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
|
||||||
|
|
||||||
// Version comparison logic
|
// Version comparison logic
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Same backend switch as UpdateChecker: with the prompt disabled — or with
|
||||||
|
// only the persisted snapshot in hand — this store-version gate must stay
|
||||||
|
// silent. Otherwise it raises a second, non-dismissable update dialog.
|
||||||
|
if (isPlaceholderData) return;
|
||||||
|
if (!isUpdatePromptEnabled) return;
|
||||||
|
|
||||||
const version = Constants.expoConfig?.version;
|
const version = Constants.expoConfig?.version;
|
||||||
if (!version || !versionFromBackend) return;
|
if (!version || !versionFromBackend) return;
|
||||||
|
|
||||||
|
|
@ -47,7 +56,7 @@ const HealthTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
|
||||||
if (needsUpdate) {
|
if (needsUpdate) {
|
||||||
setShowUpdateDialog(true);
|
setShowUpdateDialog(true);
|
||||||
}
|
}
|
||||||
}, [versionFromBackend]);
|
}, [versionFromBackend, isPlaceholderData, isUpdatePromptEnabled]);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -74,7 +83,11 @@ const HealthTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
|
||||||
<>
|
<>
|
||||||
{children}
|
{children}
|
||||||
{showUpdateDialog && appUrl && (
|
{showUpdateDialog && appUrl && (
|
||||||
<BottomDialog open={showUpdateDialog} onClose={() => setShowUpdateDialog(false)} enableDismiss={false}>
|
<BottomDialog
|
||||||
|
open={showUpdateDialog}
|
||||||
|
onClose={() => setShowUpdateDialog(false)}
|
||||||
|
enableDismiss={isUpdatePromptClosable}
|
||||||
|
>
|
||||||
<View style={{ padding: 20 }}>
|
<View style={{ padding: 20 }}>
|
||||||
<MyText style={{ fontSize: 18, fontWeight: 'bold', marginBottom: 16 }}>
|
<MyText style={{ fontSize: 18, fontWeight: 'bold', marginBottom: 16 }}>
|
||||||
Update Available
|
Update Available
|
||||||
|
|
@ -82,6 +95,15 @@ const HealthTestWrapper: React.FC<ReactParentComponent> = ({ children }) => {
|
||||||
<MyText style={{ marginBottom: 24 }}>
|
<MyText style={{ marginBottom: 24 }}>
|
||||||
A new version ({versionFromBackend}) is available. Your current version is {Constants.expoConfig?.version}. Please update to continue using the app.
|
A new version ({versionFromBackend}) is available. Your current version is {Constants.expoConfig?.version}. Please update to continue using the app.
|
||||||
</MyText>
|
</MyText>
|
||||||
|
{isUpdatePromptClosable && (
|
||||||
|
<MyTouchableOpacity
|
||||||
|
testID="health-update-later"
|
||||||
|
onPress={() => setShowUpdateDialog(false)}
|
||||||
|
style={tw`py-3 items-center mb-2`}
|
||||||
|
>
|
||||||
|
<MyText style={tw`text-gray-600 font-bold`}>Later</MyText>
|
||||||
|
</MyTouchableOpacity>
|
||||||
|
)}
|
||||||
<MyTouchableOpacity
|
<MyTouchableOpacity
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
if (appUrl) {
|
if (appUrl) {
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,120 @@
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import * as Updates from 'expo-updates';
|
import * as Updates from 'expo-updates';
|
||||||
import { Alert } from 'react-native';
|
import { useWindowDimensions, View } from 'react-native';
|
||||||
|
import { BottomDialog, MyButton, MyText, tw } from 'common-ui';
|
||||||
import type { ReactParentComponent } from '@packages/shared';
|
import type { ReactParentComponent } from '@packages/shared';
|
||||||
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
import { useGetEssentialConsts } from '@/src/hooks/prominent-api-hooks';
|
||||||
import constants from '@/src/constants';
|
import constants from '@/src/constants';
|
||||||
|
|
||||||
|
/** Share of the window height the prompt occupies. */
|
||||||
|
const DIALOG_HEIGHT_RATIO = 0.4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version gate for the user app.
|
* Version gate for the user app.
|
||||||
*
|
*
|
||||||
* Instead of expo-updates' own check, we compare the number shipped in this
|
* Instead of expo-updates' own check, we compare the number shipped in this
|
||||||
* build (`constants.INTERNAL_APP_VERSION`) with the backend's
|
* build (`constants.INTERNAL_APP_VERSION`) with the backend's
|
||||||
* `internalAppVersion` constant. When the backend is ahead, the update is
|
* `internalAppVersion` constant. When the backend is ahead, the update is
|
||||||
* fetched and the app reloads (blocking dialog, no "later").
|
* fetched and the app reloads. Both the gate and its close behaviour come from
|
||||||
|
* the backend's `updatePrompt` object (`isEnabled` / `isClosable`), so the
|
||||||
|
* prompt can be switched off — or made dismissable — without shipping a build.
|
||||||
|
*
|
||||||
|
* Rendered as the app's BottomDialog (not a native Alert) so it looks like the
|
||||||
|
* rest of the dialogs and can show an in-progress state while updating.
|
||||||
*/
|
*/
|
||||||
const UpdateChecker: React.FC<ReactParentComponent> = ({ children }) => {
|
const UpdateChecker: React.FC<ReactParentComponent> = ({ children }) => {
|
||||||
const { data } = useGetEssentialConsts();
|
const { data, isPlaceholderData } = useGetEssentialConsts();
|
||||||
|
const { height } = useWindowDimensions();
|
||||||
|
const [prompt, setPrompt] = useState<{ isClosable: boolean } | null>(null);
|
||||||
|
const [isUpdating, setIsUpdating] = useState(false);
|
||||||
const prompted = useRef(false);
|
const prompted = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (prompted.current) return;
|
if (prompted.current) return;
|
||||||
|
// The hook rehydrates the last persisted payload as placeholder data before
|
||||||
|
// the network call resolves. That snapshot can predate an `isEnabled: false`
|
||||||
|
// flip, so never decide from it.
|
||||||
|
if (isPlaceholderData) return;
|
||||||
|
|
||||||
const remoteVersion = data?.internalAppVersion;
|
const remoteVersion = data?.internalAppVersion;
|
||||||
if (typeof remoteVersion !== 'number') return;
|
if (typeof remoteVersion !== 'number') return;
|
||||||
|
const updatePrompt = data?.updatePrompt;
|
||||||
|
if (updatePrompt?.isEnabled !== true) return;
|
||||||
if (constants.INTERNAL_APP_VERSION >= remoteVersion) return;
|
if (constants.INTERNAL_APP_VERSION >= remoteVersion) return;
|
||||||
|
|
||||||
prompted.current = true;
|
prompted.current = true;
|
||||||
|
setPrompt({ isClosable: updatePrompt.isClosable === true });
|
||||||
|
}, [data, isPlaceholderData]);
|
||||||
|
|
||||||
Alert.alert(
|
const isClosable = prompt?.isClosable === true;
|
||||||
'Update available',
|
|
||||||
'A new version of the app is available. Please restart to continue.',
|
|
||||||
[
|
|
||||||
{
|
|
||||||
text: 'Update & Restart',
|
|
||||||
onPress: async () => {
|
|
||||||
try {
|
|
||||||
await Updates.fetchUpdateAsync();
|
|
||||||
await Updates.reloadAsync();
|
|
||||||
} catch {
|
|
||||||
// If the update cannot be applied, leave the app as-is.
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{ cancelable: false }
|
|
||||||
);
|
|
||||||
}, [data]);
|
|
||||||
|
|
||||||
return <>{children}</>;
|
// Backdrop tap / Android back. A non-closable prompt is the hard gate, so it
|
||||||
|
// ignores both (`BottomDialog` also drops its dismiss handlers then).
|
||||||
|
const handleClose = useCallback(() => {
|
||||||
|
setPrompt((current) => (current?.isClosable ? null : current));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const applyUpdate = useCallback(async () => {
|
||||||
|
setIsUpdating(true);
|
||||||
|
try {
|
||||||
|
await Updates.fetchUpdateAsync();
|
||||||
|
await Updates.reloadAsync();
|
||||||
|
} catch {
|
||||||
|
// If the update cannot be applied, leave the app as-is.
|
||||||
|
} finally {
|
||||||
|
setIsUpdating(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{children}
|
||||||
|
<BottomDialog
|
||||||
|
open={prompt !== null}
|
||||||
|
onClose={handleClose}
|
||||||
|
enableDismiss={isClosable}
|
||||||
|
>
|
||||||
|
<View
|
||||||
|
testID="update-dialog"
|
||||||
|
style={[tw`px-6`, { height: Math.round(height * DIALOG_HEIGHT_RATIO) }]}
|
||||||
|
>
|
||||||
|
<View style={tw`flex-1 justify-between pb-6`}>
|
||||||
|
<View>
|
||||||
|
<MyText style={tw`text-xl font-bold text-gray-900`}>
|
||||||
|
Update available
|
||||||
|
</MyText>
|
||||||
|
<MyText style={tw`text-sm text-gray-600 mt-2`}>
|
||||||
|
{isClosable
|
||||||
|
? 'A new version of the app is available. Update now, or continue and restart later.'
|
||||||
|
: 'A new version of the app is available. Please restart to continue.'}
|
||||||
|
</MyText>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View>
|
||||||
|
{isClosable ? (
|
||||||
|
<MyButton
|
||||||
|
testID="update-later"
|
||||||
|
textContent="Later"
|
||||||
|
fillColor="gray3"
|
||||||
|
textColor="black2"
|
||||||
|
fullWidth
|
||||||
|
onPress={handleClose}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
<MyButton
|
||||||
|
testID="update-restart"
|
||||||
|
textContent={isUpdating ? 'Updating…' : 'Update & Restart'}
|
||||||
|
fullWidth
|
||||||
|
disabled={isUpdating}
|
||||||
|
onPress={applyUpdate}
|
||||||
|
style={isClosable ? tw`mt-2` : undefined}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</BottomDialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default UpdateChecker;
|
export default UpdateChecker;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/**
|
/**
|
||||||
* ROOT-01..ROOT-29 — the app shell (`app/_layout.tsx`) and the wrappers it
|
* ROOT-01..ROOT-34 — the app shell (`app/_layout.tsx`) and the wrappers it
|
||||||
* composes.
|
* composes.
|
||||||
*
|
*
|
||||||
* Rows that need the *whole* provider tree (fonts gate, health gate) mount
|
* Rows that need the *whole* provider tree (fonts gate, health gate) mount
|
||||||
|
|
@ -188,6 +188,31 @@ describe('app shell (ROOT-01..ROOT-29)', () => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('ROOT-33: a disabled update prompt silences the store-version dialog', async () => {
|
||||||
|
const view = renderHealth({
|
||||||
|
versionNum: '1.3.0',
|
||||||
|
updatePrompt: { isEnabled: false, isClosable: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
await flush(3)
|
||||||
|
expect(view.queryByText('Update Available')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ROOT-34: a closable store-version dialog dismisses with Later', async () => {
|
||||||
|
const view = renderHealth({
|
||||||
|
versionNum: '1.3.0',
|
||||||
|
updatePrompt: { isEnabled: true, isClosable: true },
|
||||||
|
})
|
||||||
|
|
||||||
|
await waitFor(() => expect(view.getByText('Update Available')).toBeTruthy())
|
||||||
|
|
||||||
|
fireEvent.press(view.getByTestId('health-update-later'))
|
||||||
|
|
||||||
|
await flush()
|
||||||
|
expect(view.queryByText('Update Available')).toBeNull()
|
||||||
|
expect(Linking.openURL).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
it('ROOT-09: a first-time user sees the welcome screen and Next stores the flag', async () => {
|
it('ROOT-09: a first-time user sees the welcome screen and Next stores the flag', async () => {
|
||||||
const view = render(
|
const view = render(
|
||||||
<FirstUserWrapper>
|
<FirstUserWrapper>
|
||||||
|
|
@ -281,20 +306,18 @@ describe('app shell (ROOT-01..ROOT-29)', () => {
|
||||||
expect(view.queryByTestId('webview')).toBeNull()
|
expect(view.queryByTestId('webview')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ROOT-16: a newer backend internal version alerts once and updates', async () => {
|
it('ROOT-16: a newer backend internal version shows the hard-gate dialog and updates', async () => {
|
||||||
const alertSpy = jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
||||||
renderUpdateChecker()
|
|
||||||
setProcedure('common.essentialConsts', {
|
setProcedure('common.essentialConsts', {
|
||||||
data: { ...CONSTS, internalAppVersion: 5 },
|
data: { ...CONSTS, internalAppVersion: 5 },
|
||||||
})
|
})
|
||||||
|
const view = renderUpdateChecker()
|
||||||
|
|
||||||
await waitFor(() => expect(alertSpy).toHaveBeenCalledTimes(1))
|
await waitFor(() => expect(view.getByTestId('update-dialog')).toBeTruthy())
|
||||||
expect(alertSpy.mock.calls[0][0]).toBe('Update available')
|
// The fixture's prompt is the non-closable hard gate.
|
||||||
|
expect(view.queryByTestId('update-later')).toBeNull()
|
||||||
|
|
||||||
const buttons = alertSpy.mock.calls[0][2] as any[]
|
|
||||||
const update = buttons.find((button) => button.text === 'Update & Restart')
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
await update.onPress()
|
fireEvent.press(view.getByTestId('update-restart'))
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(Updates.fetchUpdateAsync).toHaveBeenCalledTimes(1)
|
expect(Updates.fetchUpdateAsync).toHaveBeenCalledTimes(1)
|
||||||
|
|
@ -305,23 +328,74 @@ describe('app shell (ROOT-01..ROOT-29)', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ROOT-17: an update fetch failure does not crash or reload', async () => {
|
it('ROOT-17: an update fetch failure does not crash or reload', async () => {
|
||||||
const alertSpy = jest.spyOn(Alert, 'alert').mockImplementation(() => {})
|
|
||||||
;(Updates.fetchUpdateAsync as jest.Mock).mockRejectedValueOnce(new Error('no update'))
|
;(Updates.fetchUpdateAsync as jest.Mock).mockRejectedValueOnce(new Error('no update'))
|
||||||
renderUpdateChecker()
|
|
||||||
setProcedure('common.essentialConsts', {
|
setProcedure('common.essentialConsts', {
|
||||||
data: { ...CONSTS, internalAppVersion: 5 },
|
data: { ...CONSTS, internalAppVersion: 5 },
|
||||||
})
|
})
|
||||||
|
const view = renderUpdateChecker()
|
||||||
|
|
||||||
await waitFor(() => expect(alertSpy).toHaveBeenCalledTimes(1))
|
await waitFor(() => expect(view.getByTestId('update-dialog')).toBeTruthy())
|
||||||
const update = (alertSpy.mock.calls[0][2] as any[]).find(
|
|
||||||
(button) => button.text === 'Update & Restart'
|
|
||||||
)
|
|
||||||
|
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
await update.onPress()
|
fireEvent.press(view.getByTestId('update-restart'))
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(Updates.reloadAsync).not.toHaveBeenCalled()
|
expect(Updates.reloadAsync).not.toHaveBeenCalled()
|
||||||
|
// The gate stays up so the user can retry.
|
||||||
|
expect(view.getByTestId('update-dialog')).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ROOT-30: a disabled backend flag suppresses the update prompt', async () => {
|
||||||
|
setProcedure('common.essentialConsts', {
|
||||||
|
data: { ...CONSTS, internalAppVersion: 5, updatePrompt: { isEnabled: false, isClosable: true } },
|
||||||
|
})
|
||||||
|
const view = renderUpdateChecker()
|
||||||
|
|
||||||
|
// Let the query resolve; the dialog must stay absent either way.
|
||||||
|
await flush(3)
|
||||||
|
expect(view.queryByTestId('update-dialog')).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ROOT-31: a closable prompt offers "Later" and does not update', async () => {
|
||||||
|
setProcedure('common.essentialConsts', {
|
||||||
|
data: {
|
||||||
|
...CONSTS,
|
||||||
|
internalAppVersion: 5,
|
||||||
|
updatePrompt: { isEnabled: true, isClosable: true },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
const view = renderUpdateChecker()
|
||||||
|
|
||||||
|
await waitFor(() => expect(view.getByTestId('update-dialog')).toBeTruthy())
|
||||||
|
expect(view.getByTestId('update-later')).toBeTruthy()
|
||||||
|
expect(view.getByText('Update & Restart')).toBeTruthy()
|
||||||
|
|
||||||
|
await act(async () => {
|
||||||
|
fireEvent.press(view.getByTestId('update-later'))
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(view.queryByTestId('update-dialog')).toBeNull()
|
||||||
|
expect(Updates.fetchUpdateAsync).not.toHaveBeenCalled()
|
||||||
|
expect(Updates.reloadAsync).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('ROOT-32: a stale persisted snapshot cannot trigger the prompt', async () => {
|
||||||
|
// The hook rehydrates this as placeholder data while the query is pending —
|
||||||
|
// it carries isEnabled:true from before the backend flipped it to false.
|
||||||
|
__set(
|
||||||
|
'essential_consts_b7',
|
||||||
|
JSON.stringify({
|
||||||
|
...CONSTS,
|
||||||
|
internalAppVersion: 5,
|
||||||
|
updatePrompt: { isEnabled: true, isClosable: false },
|
||||||
|
})
|
||||||
|
)
|
||||||
|
setProcedure('common.essentialConsts', { mode: 'pending' })
|
||||||
|
const view = renderUpdateChecker()
|
||||||
|
|
||||||
|
// Let the query resolve; the dialog must stay absent either way.
|
||||||
|
await flush(3)
|
||||||
|
expect(view.queryByTestId('update-dialog')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('ROOT-18: back on home with an empty stack asks to exit and exits', () => {
|
it('ROOT-18: back on home with an empty stack asks to exit and exits', () => {
|
||||||
|
|
|
||||||
1
apps/user-ui/tests/fixtures/index.ts
vendored
1
apps/user-ui/tests/fixtures/index.ts
vendored
|
|
@ -66,6 +66,7 @@ export const CONSTS = {
|
||||||
welcomeMessage: 'Welcome to Freshyo',
|
welcomeMessage: 'Welcome to Freshyo',
|
||||||
versionNum: '1.2.0',
|
versionNum: '1.2.0',
|
||||||
internalAppVersion: 2,
|
internalAppVersion: 2,
|
||||||
|
updatePrompt: { isEnabled: true, isClosable: false },
|
||||||
appStoreUrl: 'https://apps.apple.com/app/freshyo/id123456',
|
appStoreUrl: 'https://apps.apple.com/app/freshyo/id123456',
|
||||||
playStoreUrl: 'https://play.google.com/store/apps/details?id=com.freshyotrial.app',
|
playStoreUrl: 'https://play.google.com/store/apps/details?id=com.freshyotrial.app',
|
||||||
webviewHtml: null,
|
webviewHtml: null,
|
||||||
|
|
|
||||||
231
change-log.txt
231
change-log.txt
|
|
@ -636,3 +636,234 @@ job itself.
|
||||||
--- apps/backend/wrangler.prod.toml
|
--- apps/backend/wrangler.prod.toml
|
||||||
-crons = ["0 16 * * *", "0 1 * * *", "30 20 * * *"]
|
-crons = ["0 16 * * *", "0 1 * * *", "30 20 * * *"]
|
||||||
+crons = ["0 15 * * *", "0 1 * * *", "30 20 * * *"]
|
+crons = ["0 15 * * *", "0 1 * * *", "30 20 * * *"]
|
||||||
|
|
||||||
|
[2026-11-05 22:40:37 IST] add a backend kill switch for the in-app update dialog.
|
||||||
|
|
||||||
|
The force-update dialog (apps/user-ui/components/UpdateChecker.tsx) is now gated
|
||||||
|
by `isUpdatePromptEnabled`, returned per request by `common.essentialConsts`.
|
||||||
|
It is a hardcoded literal in the router, deliberately NOT in the constants
|
||||||
|
tables or the per-bound KV cache, so flipping it is a one-line change plus a
|
||||||
|
deploy. Currently `false`: no prompt even when the build is behind
|
||||||
|
`internalAppVersion`. The client only prompts when the flag is explicitly
|
||||||
|
`true`, so an older payload or a persisted snapshot cannot flash the dialog.
|
||||||
|
|
||||||
|
--- apps/backend/src/trpc/apis/common-apis/common-trpc-index.ts
|
||||||
|
return {
|
||||||
|
...response,
|
||||||
|
webviewHtml: shouldShowNotice ? updateNotice : null,
|
||||||
|
isWebviewClosable: shouldShowNotice ? false : true,
|
||||||
|
+ // Kill switch for the in-app "Update available" dialog (UpdateChecker in
|
||||||
|
+ // apps/user-ui). Hardcoded on purpose and computed per request, so it can
|
||||||
|
+ // be flipped and deployed without touching the constants tables or waiting
|
||||||
|
+ // for the per-bound KV cache to rebuild: `false` means users are never
|
||||||
|
+ // asked to restart, even when their build is behind `internalAppVersion`.
|
||||||
|
+ isUpdatePromptEnabled: false,
|
||||||
|
};
|
||||||
|
--- apps/user-ui/components/UpdateChecker.tsx
|
||||||
|
const remoteVersion = data?.internalAppVersion;
|
||||||
|
if (typeof remoteVersion !== 'number') return;
|
||||||
|
+ // Backend kill switch: only prompt when the backend explicitly enables it.
|
||||||
|
+ // A missing field (older payload, or a persisted snapshot from before the
|
||||||
|
+ // flag existed) also suppresses the prompt, so a stale cache cannot flash
|
||||||
|
+ // the dialog before the fresh payload arrives.
|
||||||
|
+ if (data?.isUpdatePromptEnabled !== true) return;
|
||||||
|
if (constants.INTERNAL_APP_VERSION >= remoteVersion) return;
|
||||||
|
--- apps/user-ui/tests/fixtures/index.ts
|
||||||
|
internalAppVersion: 2,
|
||||||
|
+ isUpdatePromptEnabled: true,
|
||||||
|
--- apps/user-ui/tests/app/root-layout.test.tsx
|
||||||
|
+ it('ROOT-30: a disabled backend flag suppresses the update prompt', ...)
|
||||||
|
--- apps/backend/tests/helpers/cache.ts
|
||||||
|
webviewHtml?: string | null
|
||||||
|
isWebviewClosable?: boolean
|
||||||
|
+ isUpdatePromptEnabled?: boolean
|
||||||
|
--- apps/backend/tests/api/cache-consts.test.ts
|
||||||
|
+ it('CACHE-117: isUpdatePromptEnabled is a boolean', ...)
|
||||||
|
--- apps/user-ui/JEST-TEST-CASES.md, apps/backend/API-TEST-CASES.md
|
||||||
|
- CONSTS fixture row + ROOT-30 row; CACHE-117 row.
|
||||||
|
|
||||||
|
[2026-11-05 22:45:31 IST] the update-dialog flag becomes an object: enabled + closable.
|
||||||
|
|
||||||
|
`common.essentialConsts` now returns `updatePrompt: { isEnabled, isClosable }`
|
||||||
|
instead of the scalar `isUpdatePromptEnabled`. `isEnabled: false` still means the
|
||||||
|
dialog is never shown (the current state). When it is enabled, `isClosable: true`
|
||||||
|
renders a "Later" button and lets Android back/outside-tap dismiss the alert;
|
||||||
|
`isClosable: false` keeps the single-button hard gate. Still a hardcoded literal
|
||||||
|
computed per request (not in the per-bound KV cache), so flipping it is one line
|
||||||
|
plus a deploy.
|
||||||
|
|
||||||
|
--- apps/backend/src/trpc/apis/common-apis/common-trpc-index.ts
|
||||||
|
- // Kill switch for the in-app "Update available" dialog (UpdateChecker in
|
||||||
|
- // apps/user-ui). Hardcoded on purpose and computed per request, so it can
|
||||||
|
- // be flipped and deployed without touching the constants tables or waiting
|
||||||
|
- // for the per-bound KV cache to rebuild: `false` means users are never
|
||||||
|
- // asked to restart, even when their build is behind `internalAppVersion`.
|
||||||
|
- isUpdatePromptEnabled: false,
|
||||||
|
+ // Kill switch + close behaviour for the in-app "Update available" dialog
|
||||||
|
+ // (UpdateChecker in apps/user-ui). Hardcoded on purpose and computed per
|
||||||
|
+ // request, so it can be flipped and deployed without touching the
|
||||||
|
+ // constants tables or waiting for the per-bound KV cache to rebuild.
|
||||||
|
+ updatePrompt: {
|
||||||
|
+ isEnabled: false,
|
||||||
|
+ isClosable: true,
|
||||||
|
+ },
|
||||||
|
--- apps/user-ui/components/UpdateChecker.tsx
|
||||||
|
- if (data?.isUpdatePromptEnabled !== true) return;
|
||||||
|
+ const prompt = data?.updatePrompt;
|
||||||
|
+ if (prompt?.isEnabled !== true) return;
|
||||||
|
...
|
||||||
|
- Alert.alert('Update available', '...Please restart to continue.', [one button], { cancelable: false })
|
||||||
|
+ const isClosable = prompt?.isClosable === true;
|
||||||
|
+ Alert.alert(
|
||||||
|
+ 'Update available',
|
||||||
|
+ isClosable ? '... Update now, or continue and restart later.' : '... Please restart to continue.',
|
||||||
|
+ isClosable
|
||||||
|
+ ? [{ text: 'Later', style: 'cancel' }, { text: 'Update & Restart', onPress: applyUpdate }]
|
||||||
|
+ : [{ text: 'Update & Restart', onPress: applyUpdate }],
|
||||||
|
+ { cancelable: isClosable }
|
||||||
|
+ );
|
||||||
|
--- apps/user-ui/tests/fixtures/index.ts
|
||||||
|
- isUpdatePromptEnabled: true,
|
||||||
|
+ updatePrompt: { isEnabled: true, isClosable: false },
|
||||||
|
--- apps/user-ui/tests/app/root-layout.test.tsx
|
||||||
|
- ROOT-30 uses updatePrompt: { isEnabled: false, isClosable: false }
|
||||||
|
+ ROOT-31 (new): isClosable:true shows "Later", cancelable alert, no fetch on Later
|
||||||
|
--- apps/backend/tests/helpers/cache.ts
|
||||||
|
- isUpdatePromptEnabled?: boolean
|
||||||
|
+ updatePrompt?: { isEnabled: boolean; isClosable: boolean }
|
||||||
|
--- apps/backend/tests/api/cache-consts.test.ts
|
||||||
|
- CACHE-117 asserts typeof === 'boolean'
|
||||||
|
+ CACHE-117 asserts the updatePrompt object shape
|
||||||
|
--- apps/user-ui/JEST-TEST-CASES.md, apps/backend/API-TEST-CASES.md
|
||||||
|
- CONSTS fixture row, ROOT-30/ROOT-31 rows, CACHE-117 row.
|
||||||
|
|
||||||
|
[2026-11-05 23:14:54 IST] fix `bun run pull_db`: split the dump into schema + data before replaying.
|
||||||
|
|
||||||
|
`wrangler d1 export` writes tables in sqlite_master rowid (historical creation)
|
||||||
|
order, so a child table is created and populated before its parent exists
|
||||||
|
(`notif_creds`/`unlogged_user_tokens` -> `regions`, `product_skus` ->
|
||||||
|
`product_info`). Local D1 pins foreign_keys=ON and runs the file as one
|
||||||
|
transaction, so neither `PRAGMA foreign_keys=OFF` (a no-op, verified: the pragma
|
||||||
|
still reads 1) nor the dump's own `defer_foreign_keys` prevents
|
||||||
|
`no such table: main.regions`. `CREATE TABLE` may reference a missing parent, so
|
||||||
|
replaying every CREATE first and every INSERT second makes the import
|
||||||
|
order-independent.
|
||||||
|
|
||||||
|
`populate_localdb.sh` now splits dumps/latest.sql into .wrangler/pull/schema.sql
|
||||||
|
and .wrangler/pull/data.sql (gitignored by the existing `**/.wrangler/*` rule)
|
||||||
|
and executes them in that order. `package.json` is unchanged, so `bun run pull_db`
|
||||||
|
is still the one command (and `pull_dev_db` benefits from the same fix).
|
||||||
|
|
||||||
|
--- apps/backend/scripts/populate_localdb.sh
|
||||||
|
-wrangler d1 execute "$DB_NAME" --local --file "$DUMP_FILE" --config "$WRANGLER_CONFIG"
|
||||||
|
+mkdir -p "$SPLIT_DIR"
|
||||||
|
+# ... awk splitter: CREATE/PRAGMA -> schema.sql, everything else -> data.sql
|
||||||
|
+wrangler d1 execute "$DB_NAME" --local --file "$SCHEMA_FILE" --config "$WRANGLER_CONFIG"
|
||||||
|
+wrangler d1 execute "$DB_NAME" --local --file "$DATA_FILE" --config "$WRANGLER_CONFIG"
|
||||||
|
--- apps/backend/wrangler-commands.md
|
||||||
|
- "How to hand-fix" (cut/paste the parent block above the child) is now automated
|
||||||
|
+ by populate_localdb.sh; kept the way to verify a dump by hand.
|
||||||
|
|
||||||
|
Follow-up on the same change: the data pass also needs deferred FK checks.
|
||||||
|
The dump's row order is not FK-safe (child rows can precede their parent rows),
|
||||||
|
and D1 enforces FKs per statement, which surfaced as
|
||||||
|
`FOREIGN KEY constraint failed: SQLITE_CONSTRAINT` only after the schema split
|
||||||
|
was in place. populate_localdb.sh now writes `PRAGMA defer_foreign_keys=TRUE;`
|
||||||
|
at the top of .wrangler/pull/data.sql as well; enforcement then happens once at
|
||||||
|
COMMIT and `PRAGMA foreign_key_check` is clean on the imported DB.
|
||||||
|
|
||||||
|
[2026-11-05 23:22:25 IST] never fire the update prompt from the persisted snapshot.
|
||||||
|
|
||||||
|
useGetEssentialConsts rehydrates the last cached payload as React Query
|
||||||
|
`placeholderData` before the network call resolves, so on launch the effect can
|
||||||
|
see an older `updatePrompt.isEnabled: true` while the fresh (correct) `false`
|
||||||
|
arrives a moment later. The alert had already been raised by then and cannot be
|
||||||
|
dismissed programmatically. UpdateChecker now ignores placeholder data entirely
|
||||||
|
and only decides from the resolved response. Also removed a leftover debug
|
||||||
|
`console.log({ consts: data })`.
|
||||||
|
|
||||||
|
--- apps/user-ui/components/UpdateChecker.tsx
|
||||||
|
- const { data } = useGetEssentialConsts();
|
||||||
|
+ const { data, isPlaceholderData } = useGetEssentialConsts();
|
||||||
|
- console.log({consts: data})
|
||||||
|
useEffect(() => {
|
||||||
|
if (prompted.current) return;
|
||||||
|
+ // The hook rehydrates the last persisted payload as placeholder data before
|
||||||
|
+ // the network call resolves; that snapshot can predate an `isEnabled: false`
|
||||||
|
+ // flip, so never decide from it.
|
||||||
|
+ if (isPlaceholderData) return;
|
||||||
|
const remoteVersion = data?.internalAppVersion;
|
||||||
|
- }, [data]);
|
||||||
|
+ }, [data, isPlaceholderData]);
|
||||||
|
--- apps/user-ui/tests/app/root-layout.test.tsx
|
||||||
|
+ ROOT-32: a seeded stale snapshot (isEnabled:true) with a pending query shows no alert.
|
||||||
|
--- apps/user-ui/JEST-TEST-CASES.md
|
||||||
|
+ ROOT-32 row.
|
||||||
|
|
||||||
|
[2026-11-05 23:25:16 IST] the update prompt uses the app's BottomDialog at 40% height.
|
||||||
|
|
||||||
|
Replaced the native `Alert.alert` with `BottomDialog` (common-ui) sized to 40%
|
||||||
|
of the window height, so it matches the rest of the app (handle, slide-up,
|
||||||
|
scrollable body) and can carry real buttons. `enableDismiss` follows
|
||||||
|
`updatePrompt.isClosable` (backdrop tap + Android back only when closable);
|
||||||
|
the closable variant renders a "Later" button, the hard gate renders only
|
||||||
|
"Update & Restart". "Updating…" disables the button while fetch/reload runs.
|
||||||
|
|
||||||
|
--- apps/user-ui/components/UpdateChecker.tsx
|
||||||
|
-import { Alert } from 'react-native';
|
||||||
|
+import { useWindowDimensions, View } from 'react-native';
|
||||||
|
+import { BottomDialog, MyButton, MyText, tw } from 'common-ui';
|
||||||
|
- const prompted = useRef(false);
|
||||||
|
+ const [prompt, setPrompt] = useState<{ isClosable: boolean } | null>(null);
|
||||||
|
+ const [isUpdating, setIsUpdating] = useState(false);
|
||||||
|
- Alert.alert('Update available', message, [buttons], { cancelable: isClosable });
|
||||||
|
+ setPrompt({ isClosable: updatePrompt.isClosable === true });
|
||||||
|
+ ...
|
||||||
|
+ <BottomDialog open={prompt !== null} onClose={handleClose} enableDismiss={isClosable}>
|
||||||
|
+ <View testID="update-dialog" style={{ height: Math.round(height * 0.4) }}> ... </View>
|
||||||
|
+ </BottomDialog>
|
||||||
|
--- apps/user-ui/tests/app/root-layout.test.tsx
|
||||||
|
- ROOT-16/17/30/31/32 now assert the rendered dialog (testIDs update-dialog,
|
||||||
|
update-later, update-restart) instead of spying on Alert.alert.
|
||||||
|
--- apps/user-ui/JEST-TEST-CASES.md
|
||||||
|
- ROOT-16/17/31 wording updated from "alert" to "bottom dialog".
|
||||||
|
|
||||||
|
[2026-11-05 23:30:12 IST] every update prompt now honours `updatePrompt.isEnabled`.
|
||||||
|
|
||||||
|
The dialog still shown with `isEnabled: false` was not UpdateChecker: it was
|
||||||
|
HealthTestWrapper's store-version gate (`versionNum` vs `Constants.expoConfig
|
||||||
|
.version`, rendered `enableDismiss={false}` so it cannot be closed). That gate
|
||||||
|
never read the new switch. WebViewWrapper was a third surface (host-gated
|
||||||
|
`webviewHtml`) that also ignored it.
|
||||||
|
|
||||||
|
--- apps/user-ui/components/HealthTestWrapper.tsx
|
||||||
|
- const { data: backendConsts } = useGetEssentialConsts();
|
||||||
|
+ const { data: backendConsts, isPlaceholderData } = useGetEssentialConsts();
|
||||||
|
+ const updatePrompt = backendConsts?.updatePrompt;
|
||||||
|
+ const isUpdatePromptEnabled = updatePrompt?.isEnabled === true;
|
||||||
|
+ const isUpdatePromptClosable = updatePrompt?.isClosable === true;
|
||||||
|
useEffect(() => {
|
||||||
|
+ // Same switch as UpdateChecker, and never from the persisted placeholder.
|
||||||
|
+ if (isPlaceholderData) return;
|
||||||
|
+ if (!isUpdatePromptEnabled) return;
|
||||||
|
...
|
||||||
|
- }, [versionFromBackend]);
|
||||||
|
+ }, [versionFromBackend, isPlaceholderData, isUpdatePromptEnabled]);
|
||||||
|
- <BottomDialog open={showUpdateDialog} onClose={...} enableDismiss={false}>
|
||||||
|
+ <BottomDialog open={showUpdateDialog} onClose={...} enableDismiss={isUpdatePromptClosable}>
|
||||||
|
+ {isUpdatePromptClosable && <Later button that closes the dialog>}
|
||||||
|
--- apps/backend/src/trpc/apis/common-apis/common-trpc-index.ts
|
||||||
|
const updatePrompt = { isEnabled: false, isClosable: true }
|
||||||
|
- const shouldShowNotice = host.includes('raw') || host.includes('mf')
|
||||||
|
+ const shouldShowNotice = updatePrompt.isEnabled && (host.includes('raw') || host.includes('mf'))
|
||||||
|
return {
|
||||||
|
webviewHtml: shouldShowNotice ? updateNotice : null,
|
||||||
|
- isWebviewClosable: shouldShowNotice ? false : true,
|
||||||
|
+ isWebviewClosable: shouldShowNotice ? updatePrompt.isClosable : true,
|
||||||
|
updatePrompt,
|
||||||
|
}
|
||||||
|
--- apps/user-ui/tests/app/root-layout.test.tsx
|
||||||
|
+ ROOT-33: versionNum ahead but updatePrompt.isEnabled:false -> no store dialog.
|
||||||
|
+ ROOT-34: closable store dialog renders Later and dismisses.
|
||||||
|
--- apps/user-ui/JEST-TEST-CASES.md
|
||||||
|
+ ROOT-33/ROOT-34 rows; ROOT-05/06 note the switch.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue