Skip to content

fix: unify adapter error handling and enforce four-framework contracts - #226

Merged
yourtion merged 2 commits into
mainfrom
fix/portable-adapter-contract
Oct 29, 2026
Merged

yourtion merged 2 commits into
mainfrom
fix/portable-adapter-contract

Conversation

@yourtion

@yourtion yourtion commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

切换 Express、Koa、LeizmWeb、H3 时,同一份业务代码的校验、错误观察和 HTTP 响应应保持一致。本 PR 修复 TestAgent 失败断言的假阳性,并用同一套真实 HTTP 契约持续验证四个适配器。

  • 修复 .error() 接受成功响应、.success() 忽略 HTTP 错误的问题;网络/格式器异常不再被当成预期业务失败。
  • 将 checker、hook 调度和错误观察收敛到核心:错误信封前触发 onError,校验失败触发 onValidate(Error);宿主错误边界不会重复观察。
  • 四个适配器新增 createErrorHandler(api),接入原生 body parser 错误;非法 JSON 统一为 INVALID_BODY/400,保留 cause。
  • 统一纯文本、空 JSON/204、HEAD 和 OPTIONS/Allow;修复写完响应继续匹配路由、路径参数解码与序列化失败过早标记响应已发送的问题。
  • 一个宿主注册表驱动公共 HTTP 契约、原有 SDK/OpenAPI 合约与未修改的博客业务。新增 116 项适配器/业务测试,覆盖重复 query、路径匹配/解码、空响应、解析失败、错误观察和中间件短路。CI 在 Node 20/22/24 下显式检查构建产物,覆盖率阶段检查源码。
  • 补齐 H3 博客启动入口、错误边界接入说明和迁移指南;六个公开包同步为 3.5.0,未发布 npm 包或 tag。

验证(本地 Node 24):

  • pnpm test:955 项主测试 + 13 项示例测试通过,包含构建和 H3 类型检查。
  • pnpm run test:cov:955 项通过;语句/行 99.66%,分支 95.22%,函数 99.62%。
  • pnpm run test:adapters:116 项构建产物契约通过。
  • pnpm run check、19 项发布工具测试、frozen-lockfile 安装通过。
  • 六个 workspace tarball 的独立 consumer 安装、导入与 H3 请求 smoke 通过。

迁移注意:Koa 错误边界放在 parser/routes 前,Express/LeizmWeb 放在路由后,H3 使用 onError;自定义 CORS/OPTIONS 在 erest 路由前处理。onResponse 表示处理完成,不表示网络发送完成。大小写、尾斜杠、正则路由及宿主 404/405 内容仍由宿主配置决定,详见 MIGRATION.md 与 guides/adapters.md。

Fix TestAgent assertions, observe errors before envelopes, share adapter execution,
and bridge native parser failures. Add common HTTP and unchanged-blog contracts
to CI, document migration behavior, and coordinate packages at 3.5.0.
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.66%. Comparing base (012dd82) to head (8c3ee0f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
+ Coverage   99.61%   99.66%   +0.04%     
==========================================
  Files          29       31       +2     
  Lines        3150     3306     +156     
  Branches     1025     1085      +60     
==========================================
+ Hits         3138     3295     +157     
+ Misses         12       11       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yourtion
yourtion merged commit 0cb0c41 into main Oct 29, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant