Files
ghbot/计划与指南/riper5_20260822_ghbot_v1.md
T
lezi-fun 9e47ab339e feat: sync ghbot-Nodeloc v1.2.0 capabilities into upstream
Merges all 33 commits from lza6/ghbot-Nodeloc (v1.0.0 through v1.2.0)
while keeping both sides' features in every conflicted file:

- EventRouter dispatch extracted from runReview.ts (7.1), with the
  runtime environment block preserved on the review-start comment
- Unified command ack messages (6.3) combined with the collapsed
  runtime environment block and bot signature on /recheck replies
- Status banner and collapsible unposted findings in review bodies (6.1)
- Centralized runtime directories behind GHBOT_RUNTIME_DIR (D-13);
  webhook knowledge cache now lives under tempRootDirectory()
- Production hardening for merge races, timeouts, webhook ops;
  atomic temp-file rename for R2 cache restores kept from upstream
- Webhook parity retained: triage events gated by WEBHOOK_TRIAGE_ENABLED,
  read-only command guidance, repository knowledge injection,
  runtime environment block on webhook chat replies
- Sanitization/secret redaction centralization, error-aware retry,
  duplicate merge prevention, in-process webhook retries, /metrics
- Infra: eslint/prettier gates with CI verify workflow, docs archives

typecheck, eslint, prettier format:check, and 164 tests all pass.
2026-08-24 11:47:28 +08:00

149 lines
6.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# RIPER-5 任务执行记录 — ghbot v1.0.0 迭代落地
**任务ID**: riper5_20260822_ghbot_v1
**创建时间**: 2026-08-22
**用户需求**: 按《下一步改进指南.md》完整落地闭环所有任务,真实 E2E 测验、验收、审计、提交推送、创建发行版
---
## 1. 研究分析(已完成)
### 1.1 需求分解
- 修复基线:2 个失败测试 → 全绿
- 落地指南中 P0~P6 可执行项
- 真实 E2E(非 mock)验证 webhook 链路
- 推送 + 发行版 + CI 审计
### 1.2 代码考古
- 审查 `src/` 全部 28 个源文件、2 个 workflow、测试套件结构
- 基线实测:typecheck 通过 / test 68 项 66 过 2 挂
### 1.3 约束识别
- 安全红线不可动(AUTO_MERGE=false 等)
- Windows 环境(chmod 位映射差异)
- 无 linter/formatter 门禁(需新建)
- origin (lezi-fun/ghbot) 无 push 权限 → 使用镜像 fork (lza6/ghbot-Nodeloc)
## 2. 方案探索(已完成,见《下一步改进指南.md》第 2 节决策树)
## 3. 执行计划(已完成,里程碑 M0→M5)
## 4. 执行日志
### M0 基线恢复 ✅
| 步骤 | 内容 | 结果 |
| --------------- | -------------------------- | ------------- |
| D-01 修复 | chmod 断言 POSIX-only 分支 | test 68/68 绿 |
| ESLint/Prettier | flat config + 全量格式化 | lint 0 error |
| pre-commit | Node 版钩子防生成物入库 | 生效 |
### M1 可靠性 ✅
| 步骤 | 对应指南项 | 结果 |
| -------------- | ---------- | ------------------------------------- |
| retry 错误感知 | 4.1 | isRetryableError + 7 测试 |
| 评论命令隔离 | 4.2 | allSettled 并行容错 |
| 审查结果净化 | 4.3 | normalizeReviewDecision |
| 合并幂等 | 4.5 | live-state 复检 + already-merged 容错 |
| webhook 重试 | 4.6 | 进程内重试 2 次 |
| 测试补强 | 3.2 | 新增 9 个测试文件 |
### M2 安全 ✅
| 步骤 | 对应指南项 | 结果 |
| ------------ | ---------- | -------------------------------- |
| 共享脱敏清单 | 8.2/7.2 | sanitization.ts 单一来源 |
| 凭据掩码 | 8.4 | secrets.ts 复用于 knowledge 校验 |
| bot 身份判定 | 8.1 | comment.user.type==="Bot" 跳过 |
### M3 可观测性 ✅
| 步骤 | 对应指南项 | 结果 |
| -------------- | ---------- | ----------------------------------- |
| metrics 注册表 | 5.2 | MetricsRegistry + Prometheus 序列化 |
| /metrics 端点 | 5.2 | webhook server 集成 |
### M5 收口 ✅
| 步骤 | 结果 |
| ------------------------ | ------------------------- |
| 版本 1.0.0 | package.json |
| 双语 README 开发门禁章节 | 已同步 |
| E2E 记录归档 | 计划与指南/E2E验证记录.md |
### 4.2 问题处理
| 问题 | 根因 | 解法 |
| ---------------------------- | ------------------------------------- | -------------------------------------- |
| pre-commit 钩子崩溃 | 绝对路径含中文+空格被 sh 错误展开 | 改为仓库相对路径调用 |
| eslint no-control-regex 误报 | Git ref 正则/ANSI 剥离需要控制字符 | disable-next-line + 理由注释 |
| retry 测试超时 10s | 默认 maxAttempts=5 未覆盖 | 显式传 {maxAttempts:3} |
| push 403 | origin 无权限(lza6 非 collaborator) | 推送到有权限的 fork lza6/ghbot-Nodeloc |
| README 注入时反引号内容丢失 | bash heredoc 内命令替换 | 手动 Edit 修复两处段落 |
### 4.3 质量检查(最终门禁实测输出)
```text
npm run typecheck → 通过(0 错误)
npm run lint → 通过(0 error)
npm run format:check → All matched files use Prettier code style!
npm test → tests 134 / pass 134 / fail 0
npm run build → dist/ 产物生成且可被 node 加载执行
npm audit --omit=dev → found 0 vulnerabilities(官方 registry)
```
### E2E 实测(生产构建真实 HTTP,详见 E2E验证记录.md)
```text
GET /healthz → {"ok":true,"webhook":true}
GET /metrics → ghbot_uptime_seconds N
POST 合法签名投递 → {"ok":true}
POST 非法签名 → {"error":"Invalid webhook signature."} (401)
POST 重复 delivery → {"ok":true,"duplicate":true}
指标计数 accepted=1, bad_signature=1, duplicate=1 ✅
```
### CI 远端验证
```text
CI #32574065674 (push main): typecheck-lint-test → success (29s)
PR Review Bot schedule: success
```
## 5. 回顾总结
### 5.1 成果验证
- 19 个原子提交全部落地并推送
- 测试 68 → 134(+97%),全绿
- 指南 P0/P1/P2/P3(部分)/P6(部分)/安全项完成
### 5.2 变更摘要
- **新增**:src/review/normalize.ts、src/security/{sanitization,secrets}.ts、src/webhook/metrics.ts、eslint.config.js、.prettierrc.json、.github/workflows/ci.yml、scripts/*.cjs、test/ 下 12 个新测试文件、《计划与指南/》文档集
- **修改**:retry.ts(错误感知)、runReview.ts(三链路隔离+bot跳过)、processor.ts(合并幂等)、gooseReviewer.ts(净化接线)、chat/processor.ts 与 conflictResolver.ts(共享清单)、webhook/server.ts(重试+metrics)、storage/cacheStore.ts(pullNumber 校验)、r2.ts(export normalizeEndpoint)、knowledge.ts(共享密钥校验)、双语 README、package.json(v1.0.0+脚本)
### 5.3 质量报告
- 覆盖率:总体 61.6% → 核心模块(policy/prompt/diff/retry/sanitization/secrets/normalize/format)100%,cacheStore 95%,knowledge 98.8%
- 安全审计:0 高危漏洞;凭据红线全程未触碰
- 技术债务:processor.ts 编排函数覆盖率仍偏低(49%),已在指南标注后续方向(事件路由器解耦 7.1)
### 5.4 经验总结
1. Windows 权限位断言必须平台分支——chmod 在 NTFS 上只映射 rw 位
2. git hooks 内避免绝对路径(中文/空格目录),用仓库相对路径最稳
3. withRetry 加错误分类后,测试必须显式传小 maxAttempts 否则退避拖慢套件
4. 无 push 权限时先查 fork 权限再动手,不要反复撞 403
5. bash heredoc 中嵌入 markdown 代码块会触发命令替换——README 批量注入用 Edit 工具更可靠
### 交付物链接
- 仓库: https://github.com/lza6/ghbot-Nodeloc (main @ dc3736a)
- 发行版: https://github.com/lza6/ghbot-Nodeloc/releases/tag/v1.0.0
- CI: run 32574065674 success