// resets the guest app through the engine lifecycle bridge. a storage reset // replaces the tenant worker before clearing its scoped stores, which is the // maestro `clearState` contract. a plain reload keeps the faster reload path. // // this replaces a host-realm `localStorage.clear()` + `indexedDB.deleteDatabase` // loop that was wrong twice: (1) `localStorage.clear()` wiped engine settings // and every co-tenant sim's tenant storage, not just this app's; (2) the delete // loop ran in the host realm where the only database is the engine's own // `preview-share-state`, which the engine holds open — `deleteDatabase` then // hung forever (no success/error/blocked event fired), so the whole eval timed // out at 60s and never cleared the guest's secure-store session either. that // was the bluesky e2e suite's blanket setupApp failure. export function resetGuestAppStateEval(resetStorage: boolean): string { return `(async () => { const bridge = globalThis.SootSim && globalThis.SootSim.bridges && globalThis.SootSim.bridges.hotRemount if (!bridge) return false if (${resetStorage ? 'true' : 'false'}) { if (typeof bridge.resetExternalApp !== 'function') return false const result = await bridge.resetExternalApp({ strategy: 'full' }) return result.failures.length === 0 && result.relaunched } if (typeof bridge.reloadExternalApp !== 'function') return false await bridge.reloadExternalApp() return true })()` }