From d045ec75501e7fb933e8ad2967049e1c6c066236 Mon Sep 17 00:00:00 2001 From: harryisfish Date: Fri, 6 Nov 2026 23:23:28 +0800 Subject: [PATCH 1/2] docs(mobile): document physical device launch verification --- packages/docs/e2e.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/docs/e2e.md b/packages/docs/e2e.md index f5bcc1d6d..82017474a 100644 --- a/packages/docs/e2e.md +++ b/packages/docs/e2e.md @@ -214,3 +214,7 @@ native config 默认关闭 trace 和整段 video。原始日志、自动失败 项目已配置 Codex、Claude Code 和 Cursor 的 e2e MCP。安装依赖后重新打开可信项目会话。编写或运行测试前,读取 [e2e skill](../../.agents/skills/e2e/SKILL.md)。 当前未选择 AI 模型。需要 `agent.act` 时,先选择订阅、API 或本地模型,再按 `pnpm exec e2e guide setup` 配置 provider。ChatGPT 订阅的登录命令为 `pnpm exec e2e login openai`,完成登录后再运行模型测试。不要把凭证写入仓库;CI 保持不调用真实模型。 + +## 真机启动检查 + +真机安装应覆盖现有 App,保留数据和钥匙串。安装成功后还须确认 Release App 显示正常界面且进程仍存活;`devicectl` 返回启动成功并不证明 JavaScript 初始化成功。若 App 立即退出,先用 `devicectl device process launch --console` 抓取异常,不要通过卸载或清空数据排查。 From 6e4e00a09c0885c2e9cc034062a2fbcc5bdfa517 Mon Sep 17 00:00:00 2001 From: harryisfish Date: Fri, 6 Nov 2026 23:32:14 +0800 Subject: [PATCH 2/2] fix(mobile): install strict text decoder before router startup --- apps/mobile/app/_layout.tsx | 1 - apps/mobile/index.ts | 2 + apps/mobile/package.json | 6 ++- apps/mobile/scripts/check-polyfills.mjs | 68 +++++++++++++++++++++++++ apps/mobile/src/platform/polyfills.ts | 1 + pnpm-lock.yaml | 12 +++++ 6 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 apps/mobile/index.ts create mode 100644 apps/mobile/scripts/check-polyfills.mjs diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx index 457f38b4e..64396d9e1 100644 --- a/apps/mobile/app/_layout.tsx +++ b/apps/mobile/app/_layout.tsx @@ -1,4 +1,3 @@ -import '@/platform/polyfills' import '../global.css' import { useLinkingURL } from 'expo-linking' diff --git a/apps/mobile/index.ts b/apps/mobile/index.ts new file mode 100644 index 000000000..5dcaace11 --- /dev/null +++ b/apps/mobile/index.ts @@ -0,0 +1,2 @@ +import './src/platform/polyfills' +import 'expo-router/entry' diff --git a/apps/mobile/package.json b/apps/mobile/package.json index 91e49304b..29c3fb2a8 100644 --- a/apps/mobile/package.json +++ b/apps/mobile/package.json @@ -1,14 +1,16 @@ { "name": "vibeface-mobile", "private": true, - "main": "expo-router/entry", + "main": "./index.ts", "scripts": { "start": "expo start", "ios": "expo run:ios", "android": "expo run:android", - "typecheck": "tsc --noEmit" + "typecheck": "tsc --noEmit", + "test:polyfills": "node scripts/check-polyfills.mjs" }, "dependencies": { + "@bacons/text-decoder": "0.0.0", "@expo-google-fonts/geist": "^0.4.2", "@expo-google-fonts/geist-mono": "^0.4.3", "@rn-primitives/slot": "^1.5.2", diff --git a/apps/mobile/scripts/check-polyfills.mjs b/apps/mobile/scripts/check-polyfills.mjs new file mode 100644 index 000000000..09023e0d5 --- /dev/null +++ b/apps/mobile/scripts/check-polyfills.mjs @@ -0,0 +1,68 @@ +import assert from 'node:assert/strict' +import { webcrypto, randomUUID } from 'node:crypto' +import { existsSync, readFileSync } from 'node:fs' +import { createRequire } from 'node:module' +import { dirname, resolve } from 'node:path' +import { fileURLToPath } from 'node:url' +import vm from 'node:vm' +import ts from 'typescript' + +const app = fileURLToPath(new URL('..', import.meta.url)) +const packageFile = resolve(app, 'package.json') +const expoRequire = createRequire(createRequire(packageFile).resolve('expo/package.json')) +const { transformSync } = expoRequire('@babel/core') + +function bootstrap(existing) { + const context = vm.createContext({ TextEncoder, ArrayBuffer, DataView, Uint8Array, console, __DEV__: false }) + context.global = context + if (existing) context.TextDecoder = existing + const modules = new Map() + function load(specifier, parent) { + if (specifier === 'react-native-url-polyfill/auto') return {} + if (specifier === 'expo-crypto') return { + CryptoDigestAlgorithm: { SHA256: 'SHA-256' }, + digest: (algorithm, data) => webcrypto.subtle.digest(algorithm, data), + getRandomValues: data => webcrypto.getRandomValues(data), randomUUID, + } + if (specifier === 'expo-router/entry') { + assert.equal(typeof load('../../packages/client/src/lib/transport.ts', packageFile).createTransport, 'function') + assert.equal(typeof load('../../packages/client/src/lib/secure.ts', packageFile).secureKit, 'function') + return {} + } + const typescript = resolve(dirname(parent), `${specifier}.ts`) + const filename = specifier.startsWith('.') && existsSync(typescript) ? typescript : createRequire(parent).resolve(specifier) + if (modules.has(filename)) return modules.get(filename).exports + const source = readFileSync(filename, 'utf8') + const code = filename.endsWith('.ts') + ? ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2022 } }).outputText + : transformSync(source, { filename, babelrc: false, configFile: false, plugins: [expoRequire.resolve('@babel/plugin-transform-flow-strip-types'), expoRequire.resolve('@babel/plugin-transform-modules-commonjs')] }).code + const module = { exports: {} } + modules.set(filename, module) + vm.runInContext(`(function(require, module, exports) {${code}\n})`, context, { filename })(value => load(value, filename), module, module.exports) + return module.exports + } + load(JSON.parse(readFileSync(packageFile, 'utf8')).main, packageFile) + return context.TextDecoder +} + +const Decoder = bootstrap() +const decoder = new Decoder('utf-8', { fatal: true }) +const encoder = new TextEncoder() +assert.equal(decoder.fatal, true) +assert.equal(decoder.decode(encoder.encode('中文 😀')), '中文 😀') +assert.equal(decoder.decode(Uint8Array.of(0xef, 0xbb, 0xbf, 0x61)), 'a') +assert.equal(new Decoder('utf-8', { ignoreBOM: true }).decode(Uint8Array.of(0xef, 0xbb, 0xbf, 0x61)), '\ufeffa') +const padded = Uint8Array.of(0xff, 0x61, 0x62, 0xff) +assert.equal(decoder.decode(padded.subarray(1, 3)), 'ab') +assert.equal(decoder.decode(new DataView(padded.buffer, 1, 2)), 'ab') +assert.equal(decoder.decode(encoder.encode('again').buffer), 'again') +for (const bytes of [[0x80], [0xc0, 0xaf], [0xe2, 0x82], [0xed, 0xa0, 0x80], [0xf4, 0x90, 0x80, 0x80]]) { + assert.throws(() => decoder.decode(Uint8Array.from(bytes)), { name: 'TypeError' }) + assert.equal(decoder.decode(encoder.encode('recovered')), 'recovered') +} +assert.equal(new Decoder().decode(Uint8Array.of(0x80)), '\ufffd') +const stream = new Decoder('utf-8', { fatal: true }) +assert.equal(stream.decode(Uint8Array.of(0xe4, 0xb8), { stream: true }), '') +assert.equal(stream.decode(Uint8Array.of(0xad)), '中') +assert.equal(bootstrap(TextDecoder), TextDecoder) +console.log('Mobile bootstrap and strict UTF-8 decoding passed (missing and existing TextDecoder).') diff --git a/apps/mobile/src/platform/polyfills.ts b/apps/mobile/src/platform/polyfills.ts index 915dc81f1..e51afb6f2 100644 --- a/apps/mobile/src/platform/polyfills.ts +++ b/apps/mobile/src/platform/polyfills.ts @@ -1,3 +1,4 @@ +import '@bacons/text-decoder/install' import 'react-native-url-polyfill/auto' import { CryptoDigestAlgorithm, digest, getRandomValues, randomUUID } from 'expo-crypto' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ee31aa916..79e6489fd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ importers: apps/mobile: dependencies: + '@bacons/text-decoder': + specifier: 0.0.0 + version: 0.0.0(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0)) '@expo-google-fonts/geist': specifier: ^0.4.2 version: 0.4.2 @@ -780,6 +783,11 @@ packages: resolution: {integrity: sha512-Vj1jF3cPfxg7OAfoI7QnVKLoILlm2JF9pnVHrX8qx7AHMiYWT+NDAA7jChlNgRS4WTLc/fD1lXLmPixluj+3Gg==} engines: {node: '>=6.9.0'} + '@bacons/text-decoder@0.0.0': + resolution: {integrity: sha512-8KNbnXSHfhZRR1S1IQEdWQNa9HE/ylWRisDdkoCmHiaP53mksnPaxyqUSlwpJ3DyG1xEekRwFDEG+pbCbSsrkQ==} + peerDependencies: + react-native: '*' + '@clack/core@1.5.1': resolution: {integrity: sha512-iHTrHA8MtVuLl2TfZySmcKv1qO2PoyC9Z7pfSDozEuV5vtY3/wcOPKJXlqJ5Oq2Cx5DDGQGAMVx6HZfRRoVEbQ==} engines: {node: '>= 20.12.0'} @@ -7126,6 +7134,10 @@ snapshots: '@babel/helper-string-parser': 7.29.7 '@babel/helper-validator-identifier': 7.29.7 + '@bacons/text-decoder@0.0.0(react-native@0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0))': + dependencies: + react-native: 0.88.0(@babel/core@7.29.7)(@react-native/metro-config@0.88.0(@babel/core@7.29.7))(@types/react@19.3.0)(react@19.3.0) + '@clack/core@1.5.1': dependencies: fast-wrap-ansi: 0.2.2