Skip to content

✅ 加固消息与 pageLoad 回归护栏,精简 runtime guard - #1766

Open
cyfung1031 wants to merge 5 commits into
scriptscat:mainfrom
cyfung1031:codex/runtime-guard
Open

cyfung1031 wants to merge 5 commits into
scriptscat:mainfrom
cyfung1031:codex/runtime-guard

Conversation

@cyfung1031

@cyfung1031 cyfung1031 commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Checklist / 检查清单

  • Fixes mentioned issues / 已修复或实现相关问题
  • Code reviewed by human / 代码通过人工检查
  • Changes tested / 已完成测试

N/A — 本 PR 没有需要关闭的 issue;人工检查仍待维护者完成。

背景

runtime 启动链路出错时,问题可能延迟表现为 userscript 没有执行或 E2E timeout,定位困难。

主要风险有两类:

  1. 消息 route 重复注册时会静默覆盖旧 handler。
  2. pageLoad producer 使用内部对象 spread 时,新增内部字段可能意外进入跨 context DTO。

本次改动

  • Server.on()Group.on() 拒绝重复注册;需要替换时使用显式的 replace()
  • trimScriptInfo() 使用 pageLoad allowlist 投影,避免内部字段泄漏到 wire DTO。
  • 增加真实 producer → DTO → consumer 的回归测试。
  • 增加一个最小 Chromium runtime smoke,验证实际 userscript 能完成启动。
  • 精简 runtime guard:
    • 文档变更跳过;
    • 仅测试变更执行 typecheck 与 runtime contract tests;
    • 其他相关变更执行完整 guard;
    • 只有明确的 TypeScript、断言或 build 错误阻挡 push;无法确定为代码问题的 pnpm、浏览器、timeout 等失败允许 push。
  • CI 的 E2E job 依赖现有 lint 和 test shards;前置 job 失败时跳过 E2E。保留现有每个 shard 的 build,不增加 artifact 上传/下载流程。

实现考虑

  • typecheck 与 runtime contract tests 保持并行执行。实测并行耗时 3.50 秒,串行为 4.71 秒。
  • 不启用仓库已知可能陈旧的 Vitest experimental cache。
  • push guard 仍保留严格的 guard:runtime;只有 guard:runtime:push 使用环境失败放行策略。
  • SKIP_RUNTIME_GUARD=1 仍是完全跳过本次 hook 的显式选项。

已知限制

  • Chromium smoke 只覆盖 Chromium 的 MAIN/page userscript 启动链路,不替代完整 E2E 或其他浏览器测试。
  • CI 当前仍由每个 E2E shard 独立 build;这是为了遵循仓库现有流程,不引入新的构建 artifact 机制。
  • push guard 对无法明确归因的失败采用放行策略,因此这类失败需要在 CI 或人工检查中继续确认。

建议审查重点

  1. 重复 route 注册是否应在注册位置立即失败。
  2. pageLoad allowlist 是否覆盖当前跨 context DTO。
  3. push guard 是否只在明确代码失败时阻挡。
  4. lint 或 test shard 失败时,E2E 是否确实被跳过。

验证

验证绑定到 PR head 754bf8df81a81564909a2517b5d7b9a0547fb642

  • runtime guard classifier tests:8 passed;
  • runtime contract:142 tests passed;
  • pnpm run typecheck:通过;
  • pnpm run validate:yaml:all:通过;
  • sandbox 外严格 pnpm run guard:runtime:通过,耗时 16.27 秒,包含 build 和 Chromium smoke;
  • sandbox 外 Chromium smoke:1 passed,约 7.6 秒;
  • CI 的 lint、test shards、Run tests、4 个 E2E shards、Fossa:通过;
  • codecov/project:当前失败;该状态在前一个 head c33643c0 已存在,本次未将其描述为通过。

之前 sandbox 内的 Chromium SIGABRT 在 sandbox 外未复现,因此不能作为产品 runtime failure 结论。

截图

N/A — 本 PR 没有 UI 改动。

@cyfung1031

Copy link
Copy Markdown
Collaborator Author

@CodFrm 这个 PR 最高优先度。从其他PR的 CI log 会找到这个现象。我本机好像重现不了。但CI 的E2E会一直跑到超时
Screenshot 2026-09-22 at 17 43 43

@cyfung1031 cyfung1031 added the P0 🚑 需要紧急处理的内容 label Sep 22, 2026
@cyfung1031
cyfung1031 marked this pull request as draft September 22, 2026 08:46
@cyfung1031
cyfung1031 marked this pull request as ready for review September 22, 2026 08:56
@cyfung1031 cyfung1031 changed the title ✅ 添加消息路由与 pageLoad 运行时回归护栏 ✅ 加固消息与 pageLoad 回归护栏,精简 runtime guard Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 🚑 需要紧急处理的内容

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant