feat: add one-click SegmentLoadError repro action#12474
Conversation
| ); | ||
| } | ||
|
|
||
| await loadBundleAsync(SEGMENT_LOAD_REPRO_TARGET); |
There was a problem hiding this comment.
[🟡 P2] 段不存在时 repro 会静默成功而不复现
问题
loadTargetSegmentForRepro 把 __loadBundleAsync 的 resolve 当作"已触发复现",但生产加载器对不在 manifest 中的 key 走的是 eager-fallback 分支(installProdBundleLoader.ts 中 loadedSegments.add(segmentKey); segmentStates.set('ready'); ... return;)——它只打一条 warning 然后正常 resolve,不会抛错。
当前 SEGMENT_LOAD_REPRO_TARGET = 'seg:components.primitives.Icon.react.brand.ArtifactNews' 的格式与 deriveSegmentKey 对该文件的推导完全一致,所以现在是对的。但它依赖 ArtifactNews 始终被分配为独立 segment root;一旦 allocator 调整、图标被并入公共/eager bundle,或 key 拼写漂移,该 key 就不再命中 manifest。
影响
此时 await loadBundleAsync(...) 会正常 resolve,UI 停留在 reproducing 后随 2.5s 重启结束,既不抛 SegmentLoadError 也无任何失败提示。QA 会误判为"无法复现/已修复",而实际上工具根本没加载到目标 segment。对一个专门用于复现 SegmentLoadError 的工具而言,这种静默 no-op 是有实际误导性的。
建议
加载后校验目标确实是一个真实 segment:例如通过加载器导出的 getSegmentState/isSegmentLoaded 判断是否命中真实 segment(区分 eager-fallback),或在调用前对照 manifest 断言 key 存在,命中 fallback 时主动抛错,避免"假成功"。
Generated by Claude Code
| ? `${error.name}: ${errMsg}` | ||
| : errMsg, | ||
| ); | ||
| if (!isLoadingTargetSegment) { |
There was a problem hiding this comment.
[🟡 P2] 复现成功时丢失结构化证据
问题
当 loadTargetSegmentForRepro() 真正抛出 SegmentLoadError(即工具达成目的的那一刻),catch 里因 isLoadingTargetSegment === true 而跳过 installBundleResult(success:false),且没有任何替代事件写入 defaultLogger.app.jsBundleDev。于是 app 侧结构化日志对这次复现完全无记录。
同时 installBundle(index.native.ts)在 install 成功后已 setTimeout(appRestart, 2500) 排定整机重启,该定时器不受这里 catch 影响。
影响
复现出的 SegmentLoadError 只在 error 态 UI 中短暂展示,最多约 2.5s(还要减去 install/段加载耗时)后就被整机重启抹掉;而 app 侧诊断管线里没有留下任何该错误的结构化条目(仅原生 NativeLogger 有)。对一个以"捕获 SegmentLoadError"为唯一目的的工具,证据留存窗口极短且缺失结构化记录。
建议
在 segment 复现分支为成功/失败各补一条专用 jsBundleDev 事件(含 error.name/message/segment key),确保重启前已落库;如需人工观察,也可考虑复现路径下不立即触发 2.5s 重启,或先记录再重启。
Generated by Claude Code
Summary
Load Target Segmentaction to JS Bundle Manager for downloaded bundles matching the running app versionSwitchbehavior unchangedWhy
This provides a deterministic harness for the
SegmentLoadErroractivation race:seg:components.primitives.Icon.react.brand.ArtifactNewsSegmentLoadErrorThe selected icon is lazy and is not rendered by Bundle Manager before the action, so an already-loaded segment should not short-circuit the repro.
This PR is a QA reproduction tool, not the production fix.
Runtime and resource scope
Test plan
Load Target SegmentSegmentLoadErrorSHA mismatch before restartSwitchstill installs and restarts without requesting the target segmentAutomated checks:
yarn jest packages/kit/src/views/Setting/pages/DevBundleSwitcher/segmentLoadRepro.test.ts --runInBandyarn agent:check --profile commit