fix(app): validate persisted client state (#3289)

* fix(app): validate persisted client state

Persisted replica data could satisfy TypeScript through an assertion while missing fields required by renderers. Treat every AsyncStorage value as untrusted input, clear values that fail strict schemas, and version the replica DTO so incompatible caches cannot hydrate.

* fix(app): preserve validated legacy state

* fix(app): preserve validated preferences

Preserve supported legacy location fields and every shipped theme while keeping unknown persisted fields rejected. Align browser test seeds with the current preference shape so strict validation exercises the intended provider.

* fix(app): migrate legacy agent preferences

Released clients stored host/location fields and per-provider thinkingOptionId together. Migrate those exact strict bytes into current preferences without admitting unknown fields.

* fix(app): preserve drafts with legacy reviews

Accept the exact strict shape released for workspace review attachments so migration can discard that obsolete attachment without clearing every persisted draft.
This commit is contained in:
Mohamed Boudra
2026-08-13 12:02:39 +02:00
committed by GitHub
parent c190fed27c
commit 36312352db
69 changed files with 1801 additions and 800 deletions
@@ -2,23 +2,22 @@ import AsyncStorage from "@react-native-async-storage/async-storage";
import Constants from "expo-constants";
import * as Notifications from "expo-notifications";
import { Platform } from "react-native";
import { z } from "zod";
import { readValidatedString } from "@/storage/validated-storage";
import type { RevokePushNotificationsInput, StartPushNotificationsInput } from "./types";
const STORAGE_PREFIX = "@paseo:expo-push-token:";
const ExpoPushTokenSchema = z.string().trim().min(1);
function storageKey(serverId: string): string {
return `${STORAGE_PREFIX}${serverId}`;
}
function getExpoProjectId(): string | null {
const constants = Constants as unknown as {
easConfig?: { projectId?: unknown };
expoConfig?: { extra?: { eas?: { projectId?: unknown } } };
};
const fromEas = constants.easConfig?.projectId;
if (typeof fromEas === "string" && fromEas.trim()) return fromEas.trim();
const fromExtra = constants.expoConfig?.extra?.eas?.projectId;
return typeof fromExtra === "string" && fromExtra.trim() ? fromExtra.trim() : null;
const fromEas = ExpoPushTokenSchema.safeParse(Constants.easConfig?.projectId);
if (fromEas.success) return fromEas.data;
const fromExtra = ExpoPushTokenSchema.safeParse(Constants.expoConfig?.extra?.eas?.projectId);
return fromExtra.success ? fromExtra.data : null;
}
async function ensurePushPermission(): Promise<boolean> {
@@ -31,7 +30,7 @@ async function ensurePushPermission(): Promise<boolean> {
async function resolveToken(serverId: string): Promise<string | null> {
const key = storageKey(serverId);
const cached = await AsyncStorage.getItem(key);
const cached = await readValidatedString(AsyncStorage, key, ExpoPushTokenSchema);
if (!(await ensurePushPermission())) {
await AsyncStorage.removeItem(key);
return null;
@@ -87,7 +86,7 @@ export function startSubscription(input: StartPushNotificationsInput): () => voi
export async function revokeSubscription(input: RevokePushNotificationsInput): Promise<void> {
const key = storageKey(input.serverId);
const token = await AsyncStorage.getItem(key);
const token = await readValidatedString(AsyncStorage, key, ExpoPushTokenSchema);
if (
token &&
input.client?.isConnected &&