fix(mobile): 校验区域清单构建配置并隔离转换缓存 - #4013
Open
elfcv wants to merge 1 commit into
Open
Conversation
Signed-off-by: cnxpfcv-oss <270533111+cnxpfcv-oss@users.noreply.github.com>
|
| Filename | Overview |
|---|---|
| apps/mobile/metro.config.js | 在 Metro 初始化和生产转换边界加入环境快照、最终配置校验及缓存命名空间隔离。 |
| scripts/shared/mobile-manifest-build-guard.cjs | 新增共享 URL/区域校验器和不泄露原始环境值的 SHA-256 构建快照。 |
| scripts/shared/client-endpoint-build-env.mjs | 在移动端 bundle 子进程环境生成后调用共享清单校验器。 |
| apps/mobile/src/tests/mobileManifestBuildGuard.test.ts | 覆盖正式转换门禁、环境漂移、开发模式兼容性及真实 Metro 转换缓存隔离。 |
| scripts/tests/client-endpoint-build-env.test.mjs | 覆盖 URL 规范化、错配拒绝、敏感值不回显和快照身份稳定性。 |
| docs/dev-rules/mobile-development.md | 记录正式打包清单约束、缓存隔离、重启要求及开发模式例外。 |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[构建入口] --> B[从仓内 endpoint 配置派生环境]
B --> C[校验区域与清单地址]
C -->|无效| X[中止构建]
C -->|有效| D[加载 Metro 配置]
D --> E[生成区域与地址摘要]
E --> F[扩展 Metro cacheVersion]
F --> G{生产转换 dev=false?}
G -->|否| H[保留开发端点覆盖]
G -->|是| I[复核最终环境]
I -->|环境漂移| Y[要求重启 Metro]
I -->|一致| J[执行默认转换并使用隔离缓存]
Reviews (1): Last reviewed commit: "fix(mobile): guard manifest build env an..." | Re-trigger Greptile
Contributor
|
这条 PR 命中了维护者确认门(当前在拦:product;同时还有 security、rules),需要维护者确认后才能合并。 讨论 issue:#4015 请维护者直接在本 PR 上 Approve;如果需要修改,请 Request Changes,作者改完后再 Approve 即可放行。在此之前自动流程不会合并。 |
Contributor
|
命中 UI 路径(apps/mobile/metro.config.js)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这次改了什么
摘要
为移动端 CN / Global 的清单自举配置增加构建期防错检查,防止“本区和对端都指向同一区域”或残留环境变量被打进生产 bundle。
同时补上转换缓存边界:仅检查最终环境仍可能复用旧的 Babel 内联结果,因此 Metro 缓存按构建区域及两个清单地址的原始值摘要隔离。相同配置仍可复用缓存;生产构建初始化后配置发生变化则要求重启 Metro,避免主进程、缓存与工作进程使用不同值。
变更类型
fix缺陷修复docs/test/chore文档、测试或工程维护范围
mobileClientBundleProcessEnv在生成子进程环境后校验;Metro 在实际生产转换请求(dev: false)处再次校验,不依赖 runner 的NODE_ENV。cacheVersion,追加区域/两区原始地址的 SHA-256 摘要;检查初始化后的环境漂移,且不能通过切为 CindyDev 绕过。.env地址覆盖;自建地址应调整config/endpoint*.json正本。UI 变化
不涉及。引用的设计规范:不涉及。
怎么验证的
环境:macOS arm64,Node 22.23.1;本地 checkout 分支
fix/3861-mobile-manifest-build-guard,基线e9c3729a1。未启动开发 Metro 实例或安装运行客户端;以下 Metro 验证为测试进程/一次性 CLI 导出,故无真机__DEV__build label。自动验证
pnpm test:unit:relatedpnpm --filter mobile exec vitest run --pool=threads --maxWorkers=4pnpm --filter mobile run --if-present typecheckpnpm check:i18n-glossarynode --test scripts/__tests__/client-endpoint-build-env.test.mjspnpm check:dco/git diff --check缓存回归不是只检查 hash:测试使用真实 Metro Transformer / Expo Babel 与共享内存缓存,检查 CN → Global → Global → CN → Global(等价 URL 增加尾斜杠)的实际内联代码,并确认同配置有 2 次缓存命中。修复前可复现旧区域地址被复用,修复后测试通过。测试仅传 Buffer,不写探针源文件、不使用开发者磁盘缓存。
指纹:改动前后运行
node apps/mobile/scripts/ci-fingerprint.mjs compute --output <report>,再用compare --base <before> --current <after>比对,两平台均不变:96e76c9f4cb4fd4c990fb09e631e8ab42d61583e20a7dee6fb588f451c59b37deec3faf7e37a8b41手工验证
pnpm --filter mobile exec expo export --platform android --max-workers 1 --output-dir <temp-dir>:实际 Android bundling 立即被新校验器阻止。config/endpoint.dev.json失败。用基线 Metro 配置的内存加载对照运行同一导出,也得到相同缺文件错误;未修改开发者配置来掩盖此限制。未执行的验证
风险
风险分类
影响与回滚
app.config.js、其 CJS loader、Expoextra、原生身份与依赖均未改;本地指纹对比一致,不引入冷更要求。最终仍以 PR CI 的 base/head 指纹比较为准。提交前检查
git commit -s)