fix: remove unused errorHasStatus helper

This commit is contained in:
ghbot committed 2026-08-24 18:59:11 +08:00
1 parent c8a32b6251
commit c0f4dd2d3b
6 files changed
+1607 -414

No files matched your search

+9 -3
View File
@@ -50,6 +50,7 @@ npm run ci:test # node --import tsx --experimental-test-coverage
### CI gate (`.github/workflows/ci.yml`)
The CI workflow runs on every push/PR to main:
1. `npm ci` — clean install
2. `npm run typecheck` — strict type check
3. `npm run lint` — ESLint
@@ -139,7 +140,8 @@ The review pipeline is: `GooseReviewer.review()` → `normalizeReviewDecision()`
```typescript
// Example: add a new check for hardcoded credentials
const newRule = "Check for hardcoded credentials (API keys, passwords, tokens) in the patch. Report as 'change' (blocking) when found in production code.";
const newRule =
"Check for hardcoded credentials (API keys, passwords, tokens) in the patch. Report as 'change' (blocking) when found in production code.";
```
2. **Update the output schema** — If the new finding needs a new field, update `reviewDecisionSchema` in `src/review/gooseReviewer.ts` and the `ReviewDecision` type in `src/types.ts`.
@@ -219,6 +221,7 @@ npm run typecheck && npm run lint && npm test && npm run build
### Continuous audit
Update `workflow_status.md` after each milestone:
- Mark completed items with ✅
- Note remaining items with reasons
- Track coverage, test count, and build passes
@@ -258,12 +261,14 @@ Update `workflow_status.md` after each milestone:
## [2.0.0] - 2026-08-24
### Added
- feat: MergeGuard merge deduplication
- feat: MetricsCollector for Actions runs
- feat: failureMessages error categorization
- feat: smart retry with jitter and total timeout
### Fixed
- fix: normalizeKnowledge line ending normalization
```
@@ -283,6 +288,7 @@ gh release create v2.0.0 --title "v2.0.0" --notes "Release notes here"
```
5. **Verify release**:
- Check that `review.yml` workflow dispatches correctly
- Verify the reusable workflow at the new tag works
- Confirm CI passes on the release commit
@@ -300,7 +306,7 @@ gh release create v2.0.0 --title "v2.0.0" --notes "Release notes here"
All config is defined in `src/config.ts` with Zod schema validation. Key environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| ------------------------ | --------- | -------------------------------------------- |
| `GOOSE_API_KEY` | — | LLM API key for goose |
| `GOOSE_MODEL` | `gpt-5.4` | Model name |
| `REVIEW_POLICY` | `allow` | Review policy: allow/require_approval/reject |
@@ -317,7 +323,7 @@ Full list in `.env.example` and `src/config.ts`.
## Key Files
| Path | Purpose |
|------|---------|
| -------------------------------- | --------------------------------------- |
| `src/actions/router.ts` | Event routing and handler registration |
| `src/actions/runReview.ts` | Actions entry point |
| `src/review/processor.ts` | Core review orchestration |
+33 -33
View File
@@ -12,7 +12,7 @@
### 1.1 PR 自动审查
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ---------------------------------------- | ---------------------------------------------------------- | ---- | --------------------------- | ------------------------------------------------------------- |
| 四段输出 (review/change/comment/result) | `review/gooseReviewer.ts` + `review/normalize.ts` | ✅ | Zod schema 校验 + 过滤器 | 无 |
| 审查策略 (allow/require_approval/reject) | `review/policy.ts` | ✅ | `evaluateReviewDecision` | 无 |
| 恶意代码检测并自动关闭 | `review/processor.ts` → `closeMaliciousPullRequest` | ✅ | 评论 + 关闭 PR | 无 |
@@ -26,7 +26,7 @@
### 1.2 Issue/PR 分类
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ----------------- | ------------------------------------------------------ | ---- | ------------------ | ---- |
| Issue 标签分类 | `triage/processor.ts` → `processIssueTriage` | ✅ | 单阶段 goose 调用 | 无 |
| PR 标签分类 | `triage/processor.ts` → `processPullRequestTriage` | ✅ | 两阶段粗筛+详查 | 无 |
| 重复检测 (单阶段) | `triage/processor.ts` → `runSingleStageTriage` | ✅ | Issue 专用 | 无 |
@@ -37,7 +37,7 @@
### 1.3 @bot PR 对话
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ------------- | ---------------------------------------------------- | ---- | --------------------------- | ---- |
| @bot 提及检测 | `chat/processor.ts` → `containsBotMention` | ✅ | 多别名 | 无 |
| 权限检查 | `chat/processor.ts` → `isTrustedChatPermission` | ✅ | write/maintain/admin | 无 |
| 快照脱敏 | `chat/processor.ts` → `createRepositorySnapshot` | ✅ | 排除 .git + 配置 + 符号链接 | 无 |
@@ -50,7 +50,7 @@
### 1.4 冲突修复
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ------------ | ------------------------------------------------------------ | ---- | ------------------------------- | --------------------------------------------------------------------------- |
| 自动冲突修复 | `review/conflictResolver.ts` → `resolvePullRequestConflicts` | ✅ | 完整流水线 | 无 |
| 冲突检测 | `review/conflictResolver.ts` → `canAutoResolveConflicts` | ✅ | 8 条件判断 | 无 |
| Git 操作安全 | `review/conflictResolver.ts` → `buildConflictPushArgs` | ✅ | 仓库/分支/SHA 安全校验 | 无 |
@@ -62,7 +62,7 @@
### 1.5 Webhook 模式
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ------------ | ---------------------------------------------------- | ---- | ----------------------------- | ----------------------------- |
| 签名校验 | `webhook/server.ts` → `verifyGitHubWebhookSignature` | ✅ | HMAC-SHA256 + timingSafeEqual | 无 |
| 去重 | `webhook/server.ts` → `WebhookTaskQueue` | ✅ | deliveryId 去重 24h 保留 | 无 |
| 任务队列 | `webhook/server.ts` → `WebhookTaskQueue` | ✅ | 并发 + 限流 + 重试 2 次 | **无持久化** — 进程重启丢队列 |
@@ -73,7 +73,7 @@
### 1.6 仓库认知
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ---------------- | --------------------------------------------------------- | ---- | ---------------------- | ---- |
| 认知加载 | `repository/knowledge.ts` → `loadRepositoryKnowledge` | ✅ | 未命中时创建默认模板 | 无 |
| 认知校验 | `repository/knowledge.ts` → `validateRepositoryKnowledge` | ✅ | 32 KiB 限制 + 密钥检测 | 无 |
| 认知持久化 | `storage/cacheStore.ts` | ✅ | R2 写入 | 无 |
@@ -82,7 +82,7 @@
### 1.7 事件路由
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ---------- | ------------------------------------------ | ---- | ------------------------------ | ---- |
| 事件路由 | `actions/router.ts` → `EventRouter` | ✅ | 注册+分发 | 无 |
| 三链路隔离 | `actions/router.ts` → `Promise.allSettled` | ✅ | recheck/conflict/chat 互相独立 | 无 |
| 错误汇总 | `actions/router.ts` → `AggregateError` | ✅ | 多个失败时汇总 | 无 |
@@ -90,7 +90,7 @@
### 1.8 新增模块 (v2.0 半程)
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|------|---------|------|------|------|
| ---------- | ------------------------------------------- | ---- | -------------------------- | -------------------------------------- |
| 合并防重入 | `review/merge-guard.ts` → `MergeGuard` | ✅ | 100% 测试覆盖 | **未接入 processor.ts** — 有定义无调用 |
| 失败分类 | `ai/failureMessages.ts` | ✅ | 100% 测试覆盖 | **未接入生产代码** — 无 import 引用 |
| 指标收集器 | `metrics/collector.ts` → `MetricsCollector` | ✅ | 100% 测试覆盖 | **未接入生产代码** — 无 import 引用 |
@@ -103,7 +103,7 @@
### 2.1 未覆盖的边界情况
| 编号 | 区域 | 盲点 | 影响 | 优先级 |
|------|------|------|------|--------|
| ---- | ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | ------ |
| B-01 | `review/processor.ts` | 没有为 `supersedePreviousBotReviews` 的 GraphQL 调用失败做充分降级 | 残留旧 inline 评论 | P2 |
| B-02 | `review/processor.ts` | `waitForMergeable` 5 次重试后仍返回 null 时继续处理 | 可能错误合并 | P1 |
| B-03 | `review/conflictResolver.ts` | `acquireConflictLock` 没有超时机制 | 崩溃后锁残留(内存级,重启即消失,但同进程内可能永久阻塞) | P2 |
@@ -123,7 +123,7 @@
### 2.2 错误路径
| 编号 | 区域 | 错误路径 | 当前处理 | 改进建议 |
|------|------|---------|---------|---------|
| ---- | ---------------------------- | ----------------------------------------------------- | ----------------------------------- | --------------------------------- |
| E-01 | `review/processor.ts` | `createGitHubReview` 提交失败后只做一次 fallback | 降级到 COMMENT 但仍在同一事件中继续 | 可考虑重试 |
| E-02 | `review/processor.ts` | `supersedePreviousBotReviews` 中部分 GraphQL 调用失败 | 日志 warn 后继续 | 正确 |
| E-03 | `ai/gooseCli.ts` | Docker 容器创建失败 | 抛出异常 | 正确 |
@@ -136,7 +136,7 @@
### 2.3 安全风险
| 编号 | 风险 | 位置 | 严重程度 | 说明 |
|------|------|------|---------|------|
| ---- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------- | -------- | ----------------------------------------------------------------- |
| S-01 | `sanitization.ts` 未排除 `.npmrc`、`terraform/`、`kube/`、`docker/` 配置 | 全局 | P2 | 这些文件可能包含注册表令牌或云凭据 |
| S-02 | `apiProxy.ts` 中 `timingSafeEqual` 对比:`Buffer.from(suppliedToken)` 可能因编码抛出异常 | `apiProxy.ts:131` | P2 | 调用方应确保 `suppliedToken` 是 ASCII,但未显式处理 |
| S-03 | `webhook/server.ts` `readRawBody` 中 `for await...of` 可能被慢速请求阻塞 | `webhook/server.ts:98` | P1 | 已有 body 30s 超时,但 `readRawBody` 内部无超时 |
@@ -151,13 +151,13 @@
### P0 (阻塞)
| ID | 问题 | 位置 | 说明 |
|----|------|------|------|
| ----- | ---- | ---- | -------------------------------------- |
| P0-01 | 无 | — | 构建、类型检查、测试全部通过,无阻塞项 |
### P1 (高)
| ID | 问题 | 位置 | 说明 |
|----|------|------|------|
| ----- | --------------------------------- | ------------------------------- | ------------------------------------------------------------------------------------------- |
| P1-01 | `MergeGuard` 未接入生产代码 | `review/merge-guard.ts` | 定义了 `MergeGuard` 类,但 processor.ts 中 `maybeMergePullRequest` 未调用,无实际防重入效果 |
| P1-02 | `failureMessages` 未接入生产代码 | `ai/failureMessages.ts` | 定义了 `categorizeFailure` / `formatFailureMessage`,但无任何模块调用 |
| P1-03 | `MetricsCollector` 未接入生产代码 | `metrics/collector.ts` | 定义了完整指标收集器,但 `src/actions/runReview.ts` 和 `review/processor.ts` 未调用 |
@@ -170,7 +170,7 @@
### P2 (中)
| ID | 问题 | 位置 | 说明 |
|----|------|------|------|
| ----- | ---------------------------------------------------------------- | ------------------------------ | -------------------------------------------------------- |
| P2-01 | 快照排除清单不完整 | `security/sanitization.ts` | 缺少 `.npmrc`、`terraform/`、`kube/`、`docker/` 配置路径 |
| P2-02 | webhook 队列无持久化 | `webhook/server.ts` | 进程重启丢失所有待处理任务 |
| P2-03 | `processScheduledPendingMerges` 不分页 | `review/processor.ts:279-284` | 只取 100 条 PR,超过时遗漏 |
@@ -185,7 +185,7 @@
### P3 (低)
| ID | 问题 | 位置 | 说明 |
|----|------|------|------|
| ----- | ---------------------------------------------------------------- | ---------------------------------- | -------------------------- |
| P3-01 | 无分片并行审查 | `review/processor.ts` | 大 PR 串行 LLM 调用延迟高 |
| P3-02 | 无 AI Provider 抽象层 | `ai/gooseCli.ts` | 换 provider 需大改 |
| P3-03 | 审查结果无去重 | `review/gooseReviewer.ts` | 相似 finding 刷屏 |
@@ -251,7 +251,7 @@ metrics/ ← 指标
### 4.2 关键架构问题
| 问题 | 严重程度 | 说明 |
|------|---------|------|
| ------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `review/processor.ts` 承担过多职责 | P1 | 1736 行:编排、进度、提交、check run、旧审查清理、合并、审批、评论命令 |
| `review/conflictResolver.ts` 5 种职责混合 | P1 | 1250 行:冲突检测、git 操作、快照管理、diff 检查、验证、确认 |
| 3 个新模块无生产引用 | P1 | `MergeGuard`、`failureMessages`、`MetricsCollector` 均有定义和测试但未引入 |
@@ -263,7 +263,7 @@ metrics/ ← 指标
### 4.3 设计模式评价
| 模式 | 位置 | 评价 |
|------|------|------|
| ---------------------- | ----------------------------------------------- | ------------------------------------------------------------------------------------- |
| EventRouter (策略模式) | `actions/router.ts` | 良好:注册式分发,可扩展 |
| 快照模式 (Snapshot) | `review/conflictResolver.ts` | 良好:`inventorySnapshot` + `diffSnapshotInventories` + `applySnapshotChanges` 三阶段 |
| 仓储模式 (Repository) | `storage/r2.ts` | 一般:`downloadR2Object`/`uploadR2Object` 是过程式,非接口抽象 |
@@ -279,7 +279,7 @@ metrics/ ← 指标
### 5.1 重试策略
| 方面 | 评价 | 改进建议 |
|------|------|---------|
| ----------------------------- | ---------------------------- | ------------------ |
| `withRetry` 已实现智能重试 | ✅ 抖动 + 分类 + 总超时 | 已落地 (M1-1) |
| 默认 5 次重试 + 1s base delay | 合理 | 可接受 |
| 4xx 非重试逻辑 | 正确 | 无 |
@@ -289,7 +289,7 @@ metrics/ ← 指标
### 5.2 缓存策略
| 方面 | 评价 | 改进建议 |
|------|------|---------|
| ------------- | ------------------------- | --------------------------------------------------------- |
| 本地审查缓存 | ✅ 文件级缓存 + Zod 校验 | 无 |
| R2 持久化缓存 | ✅ 多版本 + 身份校验 | 无 |
| 仓库认知缓存 | ✅ 32 KiB 限制 + 密钥检测 | 可增加版本管理/淘汰 |
@@ -299,7 +299,7 @@ metrics/ ← 指标
### 5.3 并发处理
| 方面 | 评价 | 改进建议 |
|------|------|---------|
| ------------ | ---------------------------------- | ------------------- |
| 事件路由并行 | ✅ `Promise.allSettled` 三链路隔离 | 无 |
| webhook 队列 | ✅ 并发控制 + 限流 | 可加持久化 |
| 冲突锁 | ✅ 内存 Set 锁 | 可加超时 |
@@ -309,7 +309,7 @@ metrics/ ← 指标
### 5.4 内存与资源
| 方面 | 评价 |
|------|------|
| -------------------- | ---------------------------- |
| ECD 容器内存限制 4GB | 合理 |
| ECD 容器 CPU 2 核 | 合理 |
| 进程数限制 512 | 合理 |
@@ -324,7 +324,7 @@ metrics/ ← 指标
### 6.1 密钥处理
| 密钥 | 位置 | 处理方式 | 评价 |
|------|------|---------|------|
| --------------- | ------------------------- | -------------------------------- | --------------------- |
| `GOOSE_API_KEY` | `config.ts` | Zod schema 读取环境变量 | ✅ |
| `GITHUB_TOKEN` | `config.ts` | 直接从 process.env 读取 | ✅ |
| GitHub App 私钥 | `config.ts` → `client.ts` | `normalizePrivateKey` 处理 `\\n` | ✅ |
@@ -335,7 +335,7 @@ metrics/ ← 指标
### 6.2 注入防护
| 防护 | 位置 | 评价 |
|------|------|------|
| -------------- | ------------------------------------------------ | ---------------------------------- |
| 路径跨越防护 | `conflictResolver.ts` → `safeFilePath` | ✅ 双重检查 |
| 分支名安全校验 | `conflictResolver.ts` → `isSafeGitBranch` | ✅ 控制字符排除 |
| 仓库名安全校验 | `conflictResolver.ts` → `isSafeGitHubRepository` | ✅ 正则白名单 |
@@ -347,7 +347,7 @@ metrics/ ← 指标
### 6.3 脱敏覆盖
| 路径/模式 | 已覆盖 | 缺漏 |
|-----------|--------|------|
| -------------------------------------- | ------ | --------------------------------------------------------------------------------- |
| GitHub PAT (ghp_...) | ✅ | — |
| GitHub PAT v2 (github_pat_) | ✅ | — |
| OpenAI API key (sk-...) | ✅ | — |
@@ -359,7 +359,7 @@ metrics/ ← 指标
### 6.4 安全评估总结
| 领域 | 评级 | 要点 |
|------|------|------|
| ---------- | ---- | -------------------------------- |
| 凭据隔离 | A | 容器内无真实凭据,一次性代理安全 |
| 注入防护 | A | 路径/分支/仓库名白名单校验完善 |
| 快照脱敏 | B+ | 主要路径已覆盖,缺 `.npmrc` 等 |
@@ -374,7 +374,7 @@ metrics/ ← 指标
### 7.1 覆盖缺口
| 模块 | 当前 lines | 目标 | 主要缺口 |
|------|-----------|------|---------|
| ---------------------------- | ---------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `review/processor.ts` | 49.42% | ≥80% | `processPullRequest` 主流程、`supersedePreviousBotReviews` 大段、`maybeMergePullRequest` 大部分、`processScheduledPendingMerges`、`processRecheckComment`、`processConflictComment` |
| `review/conflictResolver.ts` | 57.52% | ≥80% | `resolvePullRequestConflicts` 主流程、`buildConflictPrompt`、`buildValidationRepairPrompt`、`runConflictValidation`、`runCommand` |
| `triage/processor.ts` | 63.19% | ≥80% | `processTriage` 主流程、`triagePullRequestInTwoStages` 大部分、`ensureLabelsExist`、`postDuplicateFeedback` |
@@ -385,7 +385,7 @@ metrics/ ← 指标
### 7.2 测试质量
| 维度 | 评价 |
|------|------|
| ---------- | ---------------------------------------- |
| 测试结构 | ✅ AAA 模式统一使用 |
| 测试命名 | ✅ 描述性命名 |
| Mock 使用 | ✅ 无真实 LLM/HTTP 调用 |
@@ -397,7 +397,7 @@ metrics/ ← 指标
### 7.3 测试文件增长
| 指标 | v1.2.0 | 当前 | 增长 |
|------|--------|------|------|
| ---------------- | ------ | ------ | ------ |
| 测试文件 | 36 | 48 | +12 |
| 测试数 | 151 | 321 | +170 |
| 覆盖率 lines | 61.41% | 66.20% | +4.79% |
@@ -442,7 +442,7 @@ metrics/ ← 指标
### 8.1 README 一致性
| 对比项 | README.md | README-zh.md | 一致性 |
|--------|-----------|-------------|--------|
| --------------- | --------- | ------------ | ------ |
| PR 审查四段输出 | ✅ | ✅ | 一致 |
| 审查策略 | ✅ | ✅ | 一致 |
| 增量缓存 | ✅ | ✅ | 一致 |
@@ -458,7 +458,7 @@ metrics/ ← 指标
### 8.2 配置文档
| 配置项 | `.env.example` | README | 代码中 `config.ts` | 一致性 |
|--------|---------------|--------|-------------------|--------|
| ---------------------------- | -------------- | ------ | ------------------ | ------------------ |
| PORT | ✅ | ✅ | ✅ | 一致 |
| LOG_LEVEL | ✅ | ❌ | ✅ | 未在 README 文档化 |
| GHBOT_RUNTIME_DIR | ✅ | ✅ | ✅ | 一致 |
@@ -486,7 +486,7 @@ metrics/ ← 指标
### 8.3 文档缺漏
| 缺漏 | 说明 | 优先级 |
|------|------|--------|
| ------------------------------------------------------- | --------------------------------------- | ------ |
| `LOG_LEVEL` 未在 README 文档化 | 仅在 `.env.example` 和 `config.ts` 中有 | P3 |
| `workflow_status.md` 未同步最新状态 | 标记了"未落地项"但未更新为当前实际状态 | P2 |
| 无 CHANGELOG | 版本迭代无历史记录 | P3 |
@@ -496,7 +496,7 @@ metrics/ ← 指标
### 8.4 部署文档
| 部署方式 | 文档化 | 评价 |
|---------|--------|------|
| ----------------------- | ------ | ----------------------------- |
| GitHub Actions (主模式) | ✅ | 详细 |
| Webhook Docker 部署 | ✅ | 详细 |
| 本地开发 | ✅ | 详细 |
@@ -538,7 +538,7 @@ metrics/ ← 指标
## 附录 A: 文件行数统计 (35 源文件 + 48 测试文件)
| 排名 | 文件 | 行数 | 覆盖 | 需关注 |
|------|------|------|------|--------|
| ---- | ------------------------------ | ---- | ------ | ------------------ |
| 1 | src/review/processor.ts | 1736 | 49.42% | 🔴 大文件 + 低覆盖 |
| 2 | src/review/conflictResolver.ts | 1250 | 57.52% | 🔴 大文件 + 低覆盖 |
| 3 | src/ai/gooseCli.ts | 726 | 73.07% | 🟡 3 种模式耦合 |
+16 -2
View File
@@ -49,19 +49,23 @@ The codebase uses a large number of small, focused files, consistent error handl
**File**: `src/review/processor.ts`, lines 1347-1351
**Code**:
```typescript
.sort(
(left, right) => Date.parse(right.started_at ?? "") - Date.parse(left.started_at ?? "")
)
```
**Issue**: `Date.parse("")` returns `NaN`. `NaN - NaN` is `NaN`. The `Array.prototype.sort()` comparator must return a number — a `NaN` return value breaks the sort implementation, producing undefined behavior (the array may be in any order, or the sort may throw on some engines).
**Failure scenario**: Any check run in the list where `started_at` is `null` or `undefined` causes the comparator to return `NaN` for that pair. The function then selects the wrong check run (or none) via `[0]`, potentially causing `markReviewCheckApproved` to:
- Update the wrong check run
- Throw `"Could not find ghbot review check"` if the wrong element is selected
- Silently skip the admin approval update
**Fix**: Use a deterministic fallback:
```typescript
.sort((left, right) => {
const lt = left.started_at ? Date.parse(left.started_at) : 0;
@@ -74,6 +78,7 @@ The codebase uses a large number of small, focused files, consistent error handl
**File**: `src/review/processor.ts`, lines 188-249
**Code**:
```typescript
const conflictResolutionEligible = canAutoResolveConflicts({
enabled: config.autoResolveConflicts,
@@ -81,15 +86,17 @@ const conflictResolutionEligible = canAutoResolveConflicts({
...
});
```
**Issue**: When `REVIEW_POLICY=require_approval`, the review passes with `outcome: "pass"` but `requiresAdminApproval: true`. The `processPullRequest` function immediately proceeds to check conflict eligibility (line 188) with `reviewPassed: true` — before checking whether an admin has actually approved (that check is at line 164-170, but it does not prevent conflict resolution from starting).
**Failure scenario**: The bot resolves conflicts and pushes a new commit, merging the PR *before* an admin has reviewed it. The `require_approval` policy is bypassed.
**Failure scenario**: The bot resolves conflicts and pushes a new commit, merging the PR _before_ an admin has reviewed it. The `require_approval` policy is bypassed.
**Fix**: Add `&& !disposition.requiresAdminApproval` to the conflict eligibility condition, or move the conflict resolution block after the admin approval check.
### C6. Duplicated `isNotFoundError` across 5 files
**Files**:
- `src/review/processor.ts:1065`
- `src/chat/processor.ts:307`
- `src/webhook/processor.ts:516`
@@ -97,6 +104,7 @@ const conflictResolutionEligible = canAutoResolveConflicts({
- `src/repository/knowledge.ts:87`
**Code** (identical in all):
```typescript
function isNotFoundError(error: unknown): boolean {
return typeof error === "object" && error !== null && "status" in error && error.status === 404;
@@ -146,6 +154,7 @@ function isNotFoundError(error: unknown): boolean {
**Code**: The `default` case in the switch returns `value` (the string) as-is, which then fails the `z.boolean()` parse. The error message is unhelpful — it will say "Expected boolean, received string" without showing the actual value.
**Fix**: Add a more descriptive error:
```typescript
default:
throw new Error(`Invalid boolean value: "${value}". Expected true/false/1/0/yes/no/on/off.`);
@@ -155,6 +164,7 @@ default:
**Files**: `src/review/processor.ts`, lines 1375-1381
**Code**:
```typescript
export function isRecheckComment(body: string): boolean {
return body.trim() === RECHECK_COMMENT_COMMAND;
@@ -215,6 +225,7 @@ See C3. The `formatFailureMessage` produces better user-facing error messages th
**File**: `src/review/policy.ts`, line 143
**Code**:
```typescript
function normalizeReviewMode(value: string): ReviewMode {
return value === "strict" ? "strict" : "normal";
@@ -236,12 +247,13 @@ No test covers the `replace_all` behavior of `Edit` tool. This is not a codebase
**Needs Discussion**
| Category | Count | Severity |
|----------|-------|----------|
| ------------------- | ----- | -------- |
| CRITICAL (Blocking) | 6 | C1-C6 |
| REQUIRED | 8 | R1-R8 |
| SUGGESTION | 10 | S1-S10 |
**Must fix before next release**:
- C1: Wire `MergeGuard` into `processor.ts` (prevents duplicate merge race)
- C2: Wire or remove `MetricsCollector` (half-shipped observability)
- C3: Wire or remove `failureMessages.ts` (dead code)
@@ -251,11 +263,13 @@ No test covers the `replace_all` behavior of `Edit` tool. This is not a codebase
- R3: Fix `GOOSE_MODEL` default
**Should fix but not blocking**:
- R2: Extract type-guard helpers
- R8: Improve `waitForMergeable` polling
- S9: Clean up `"lenient"` mode handling
**No action needed** (confirmed clean):
- Security posture (container isolation, credential redaction, path traversal protection, snapshot sanitization) is strong
- Config schema validation is thorough
- All existing tests pass and are well-structured
+1535 -362
View File
File diff suppressed because it is too large. Load diff
+7 -7
View File
@@ -190,7 +190,9 @@ export async function processPullRequest(
}
const mergeablePullRequest = await waitForMergeable(octokit, owner, repo, pullNumber);
const conflictResolutionEligible = !disposition.requiresAdminApproval && canAutoResolveConflicts({
const conflictResolutionEligible =
!disposition.requiresAdminApproval &&
canAutoResolveConflicts({
enabled: config.autoResolveConflicts,
reviewPassed: true,
mergeable: mergeablePullRequest.mergeable,
@@ -927,7 +929,10 @@ async function maybeMergePullRequest(
}
if (mergeGuard.isAlreadyAttempted(owner, repo, pullNumber)) {
logger.info({ owner, repo, pullNumber }, "Skipping merge because MergeGuard already attempted it.");
logger.info(
{ owner, repo, pullNumber },
"Skipping merge because MergeGuard already attempted it."
);
metrics.recordMergeAttempt("already_merged");
return;
}
@@ -1063,11 +1068,6 @@ async function hasCurrentHeadApprovalFrom(
return false;
}
function errorHasStatus(error: unknown, key: string, expected: number): boolean {
const candidate = error as Record<string, unknown>;
return typeof candidate[key] === "number" && candidate[key] === expected;
}
function reviewProgressMarker(headSha: string): string {
return `${REVIEW_PROGRESS_MARKER_PREFIX} head=${headSha} -->`;
}
+7 -7
View File
@@ -7,7 +7,7 @@
## 执行结果总览
| 门禁 | 状态 |
|------|------|
| -------------------- | ---------------------------------------------------------------------------- |
| npm run typecheck | ✅ 通过 |
| npm run lint | ✅ 0 error |
| npm run format:check | ✅ All matched files use Prettier code style! |
@@ -19,7 +19,7 @@
## 测试规模增长
| 指标 | 之前(v1.2.0) | 现在 | 增长 |
|------|----------------|------|------|
| ---------------- | -------------- | ------ | ------ |
| 测试文件 | 36 | 48 | +12 |
| 测试数 | 151 | 321 | +170 |
| 覆盖率 lines | 61.41% | 66.20% | +4.79% |
@@ -31,7 +31,7 @@
### 源文件(新模块)
| 文件 | 功能 | 覆盖 | 生产接入 |
|------|------|------|---------|
| --------------------------- | ---------------------- | ---- | --------- |
| `src/ai/failureMessages.ts` | 失败分类与告警文案 | 100% | ❌ 未接入 |
| `src/review/merge-guard.ts` | 合并防重入锁 | 100% | ❌ 未接入 |
| `src/metrics/collector.ts` | Actions 运行指标收集器 | 100% | ❌ 未接入 |
@@ -39,7 +39,7 @@
### 测试文件(新)
| 文件 | 测试数 | 覆盖范围 |
|------|--------|---------|
| -------------------------------------- | ------ | -------- |
| `test/goose-reviewer.test.ts` | 11 | 97.35% |
| `test/r2-storage.test.ts` | 22 | 100% |
| `test/triage-processor-extra.test.ts` | 11 | 已覆盖 |
@@ -54,7 +54,7 @@
## 已落地项
| 里程碑 | 任务 | 状态 |
|--------|------|------|
| ------ | ---------------------------------------- | --------------------------- |
| M0-1 | normalizeKnowledge 行尾归一 | ✅ |
| M0-2 | gooseReviewer 测试(26.57%→97.35%) | ✅ |
| M0-3 | r2 测试(49.01%→100%) | ✅ |
@@ -71,7 +71,7 @@
## 未落地项
| 里程碑 | 任务 | 原因 |
|--------|------|------|
| ------ | ---------------------------------------- | ---------------------------------- |
| M0-8 | 集成测试 | 需 testcontainers/MinIO 等基础设施 |
| M1-2 | 陈旧检测(stale detection) | processor.ts 未拆分前修改风险高 |
| M1-3 | MergeGuard 接 processor.ts | 需处理器拆分后接入 |
@@ -82,7 +82,7 @@
## 审计发现摘要(详见 docs/audit-v2-final.md)
| 类别 | 计数 | 关键项 |
|------|------|--------|
| ---- | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| P0 | 0 | 无阻塞项 |
| P1 | 8 | MergeGuard/failureMessages/MetricsCollector 未接入、processor.ts 1736行、conflictResolver.ts 1250行、覆盖率不足、waitForMergeable 无超时、无陈旧检测 |
| P2 | 10 | sanitization 排除清单不完整、webhook 队列无持久化、分页缺失等 |