Commit Graph

3 Commits

Author SHA1 Message Date
浅念 4c4c43f7d9 fix(adapter-wp): 原型键防御与对抗测试;meta 冲突策略统一(单值先者+issue/phpRaw 清理);extras 原型污染防御;config 校验;prebuild 依赖固化
- Fix 1:routes/STATUS_MAP 查键一律 Object.hasOwn 守卫('constructor'/
  'valueOf' 等继承键裸索引命中函数值绕过 undefined 检查)+ 对抗测试
- Fix 2:prebuild 脚本先建 contracts dist(fresh-clone build 不再 TS2307,
  亦防 stale dist 静默编译;已实测 rm -rf dist 后全链成功)
- Fix 3:单值 meta(thumbnail/seo×2)重复→先者胜出+issue(WP 单值语义,
  首个占位即便值非法不被顶替);wppop 重复→最后一次决定终态(成功清
  phpRaw/失败清 wppop_sections,两键互斥);三方策略 JSDoc 冻结
- Fix 4:extras 改 null 原型字典——'__proto__' meta 不再被 setter 静默
  吞掉(测试钉死自有键+JSON 往返);gallery 累积语义明确
- Fix 5:typeRoutes 空字符串路由值 → TypeError fail fast
- 173→184 测试全绿;typecheck/lint/build 绿

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-21 10:10:03 +08:00
浅念 25e8b9cb5c feat(adapter-wp): saxes 流式 WXR 解析器
parseWxrStream(readable, {limits, now}) → AsyncGenerator<WxrEvent>:
逐 chunk 喂入 saxes(^6.0.0,ISC;计划所写 ^0.9 不存在于版本历史),
item/term 按文档序交错产出;任一时刻只持有当前聚合状态 + 单 chunk 内
待 yield 队列,绝不收集已产出 item 列表(峰值内存与文件大小解耦)。

- 字段:postId(数值解析)/postType/status/postName/link/title/
  contentEncoded/excerptEncoded/postDate/postModified/attachmentUrl/
  creator + metas{key,value}[] + categories{domain,nicename,value}[] +
  rawLocation(wxr://item/<n>、wxr://term/<n>)
- 错误体系照 PhpError 先例:WxrError 基类;WxrParseError 带 saxes
  行列位置(error 事件同步抛出时捕获);WxrLimitError 按 kind 区分
- 限额:bytes/items/terms/depth/cdata/fieldLength(先检查后追加,
  超限内容永不入缓冲)/metaPerItem/time(可注入时钟)——超限即抛,
  不静默截断
- 实体防线(测试钉死):saxes 实体表固定为五预定义 + 数字引用,
  DOCTYPE 内部/SYSTEM 实体不注册——引用即 WxrParseError,替换文本
  不进产出;纯字符串解析,全程无网络 I/O
- 跨 chunk 喂入(7 字节/块)与单 chunk 产出一致(StringDecoder 处理
  多字节边界);畸形 XML(提前闭合/截断)→ WxrParseError 带行列

130 测试全绿(新增 22)。

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-21 08:55:11 +08:00
浅念 dc4557cccf feat(adapter-wp): 包骨架与限额契约
Plan 2 Task 1:@sf/adapter-wp 包骨架(照 contracts 先例:build extends +
rootDir "." + exclude test)+ WxrLimits 十字段限额契约与 DEFAULT_WXR_LIMITS
值域冻结(设计基线 §7.2)+ 跨包接线。

跨包接线(一份 paths 三方消费):
- 根 tsconfig compilerOptions.paths 把 @sf/contracts、@sf/adapter-wp 映射到
  各自 src/index.ts;adapter tsconfig extends 根 tsconfig 使包级 tsc 读同一
  份 paths(extends 相对路径按声明处解析,映射始终落在仓库根)
- 根 vitest.config.ts resolve.alias 指向同一映射(vitest 不读 tsconfig paths)
- adapter 加 @sf/contracts workspace:* 依赖;三方均直连 src,不经 dist
  (已实测:移走 contracts dist 后 vitest 与包级 tsc 仍全绿)
- 根 devDependencies 加 @types/node@^22(对齐 apps/api 钉 22):alias 的
  fileURLToPath 辅助需 node 类型,此前根程序靠 apps/api 传递 @types 才有
  node 全局,属偶合

限额类型锁(照 contracts 单源派生先例):DEFAULT_WXR_LIMITS as const
satisfies WxrLimits + _LIMIT_KEYS 键集与 keyof WxrLimits 双向咬合断言;
timeBudgetMs 以可注入时钟(构造函数 now())测试于 Task 3、实测覆盖于 Task 8。

验证:pnpm test 78 绿(75+3);pnpm --filter @sf/adapter-wp exec tsc
-p tsconfig.json --noEmit exit 0(--listFiles 证实 contracts 经 src 解析);
根 typecheck 链与 pnpm lint 绿;build 产物形状核验后清理。

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-21 08:05:08 +08:00