fix: address critical review findings — MergeGuard/Metrics wiring, sort NaN, conflict bypass, DRY errors
C1: Wire MergeGuard into maybeMergePullRequest (processor.ts)
C2: Wire MetricsCollector.recordMergeAttempt into merge path
C3: Wire isAlreadyMergedError from github/errors.ts (shared)
C4: Fix sort comparator NaN in markReviewCheckApproved
C5: Guard conflict resolution behind !disposition.requiresAdminApproval
C6: Extract isNotFoundError + isAlreadyMergedError to github/errors.ts
Remove 3 duplicated local copies (chat/processor, webhook/processor, processor.ts)
R1: Create shared github/errors.ts for production code
Docs: audit-v2-final.md, critical-review-v2.md, report-v2.html, workflow_status.md
Skill: .claude/skills/ghbot-workflow/SKILL.md
This commit is contained in:
1 parent
78bf8e9e41
commit
c8a32b6251
9 files changed
+2238
-39
No files matched your search
@@ -0,0 +1,338 @@
|
|||||||
|
---
|
||||||
|
name: ghbot-workflow
|
||||||
|
description: Full workflow guide for ghbot: development cycle, adding endpoints, review checks, audits, and releases.
|
||||||
|
metadata:
|
||||||
|
last_verified: "2026-08-24"
|
||||||
|
repo_baseline: "v1.2.0"
|
||||||
|
---
|
||||||
|
|
||||||
|
# ghbot workflow skill
|
||||||
|
|
||||||
|
## When to use
|
||||||
|
|
||||||
|
This skill covers the operational workflow for the ghbot GitHub review bot project. Use it when asked about development workflow, adding features, running audits, or releasing.
|
||||||
|
|
||||||
|
## Do not use
|
||||||
|
|
||||||
|
- For unrelated SaaS features
|
||||||
|
- For changing AUTO_MERGE default value
|
||||||
|
- For reusing old review cache as a new-head approval
|
||||||
|
- For running paid LLM E2E without budget
|
||||||
|
- For pushing to remotes without write permission
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Full Workflow: test → typecheck → lint → build → e2e → release
|
||||||
|
|
||||||
|
### Local development loop
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Test (fastest first)
|
||||||
|
npm test # node --import tsx --test test/**/*.test.ts
|
||||||
|
|
||||||
|
# 2. Type check
|
||||||
|
npm run typecheck # tsc --noEmit
|
||||||
|
|
||||||
|
# 3. Lint
|
||||||
|
npm run lint # eslint src test
|
||||||
|
npm run lint:fix # auto-fix lint issues
|
||||||
|
|
||||||
|
# 4. Format check
|
||||||
|
npm run format:check # prettier --check
|
||||||
|
|
||||||
|
# 5. Build
|
||||||
|
npm run build # tsc -p tsconfig.json, output to dist/
|
||||||
|
|
||||||
|
# 6. Build + test (CI equivalent)
|
||||||
|
npm run ci:test # node --import tsx --experimental-test-coverage --test test/**/*.test.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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
|
||||||
|
4. `npm run format:check` — Prettier style check
|
||||||
|
5. `node --import tsx --experimental-test-coverage --test test/**/*.test.ts` — full test + coverage
|
||||||
|
|
||||||
|
### Pre-commit hooks
|
||||||
|
|
||||||
|
The repo uses `scripts/husky-pre-commit.cjs` via `scripts/install-husky.cjs`. Run `node scripts/install-husky.cjs` to set up.
|
||||||
|
|
||||||
|
### E2E smoke test
|
||||||
|
|
||||||
|
E2E tests require real LLM (goose) and GitHub API access. Run locally only with explicit budget:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Requires GOOSE_API_KEY set in .env
|
||||||
|
# Run the webhook server locally, then send test events
|
||||||
|
npm run dev:webhook # tsx src/webhook/server.ts
|
||||||
|
```
|
||||||
|
|
||||||
|
### Release checklist
|
||||||
|
|
||||||
|
See section 5 below.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. How to Add a New API Endpoint
|
||||||
|
|
||||||
|
ghbot has two entry points: GitHub Actions events and the optional webhook HTTP server.
|
||||||
|
|
||||||
|
### Adding a new Actions event handler
|
||||||
|
|
||||||
|
1. **Define the event type** — Add a new type in `src/actions/router.ts` (e.g., `type NewPayload = { ... }`).
|
||||||
|
|
||||||
|
2. **Register a handler** — In `buildDefaultEventRouter()` inside `src/actions/router.ts`, add a new `.register()` call:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
router.register({
|
||||||
|
name: "my-new-event",
|
||||||
|
canHandle: (eventName, action) => eventName === "my_event",
|
||||||
|
handle: async (ctx) => {
|
||||||
|
// Implement your logic
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Wire the payload** — In `src/actions/runReview.ts`, add the new event name to `buildPayloadFromWorkflowCallEnv()`.
|
||||||
|
|
||||||
|
4. **Extend the reusable workflow** — In `.github/workflows/review-reusable.yml`, add new inputs if needed.
|
||||||
|
|
||||||
|
5. **Add tests** — Create `test/my-new-event.test.ts` with AAA tests.
|
||||||
|
|
||||||
|
### Adding a new webhook HTTP endpoint
|
||||||
|
|
||||||
|
1. **Add route** — In `src/webhook/server.ts`, `createWebhookServer()`, add a new conditional branch:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
if (request.method === "POST" && pathname === "/my-endpoint") {
|
||||||
|
// validate, parse, handle
|
||||||
|
writeJson(response, 200, { ok: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Add handler** — Extend `WebhookDeliveryHandler` or create a separate handler function.
|
||||||
|
|
||||||
|
3. **Add metrics** — Use `MetricsRegistry.inc()` from `src/webhook/metrics.ts`.
|
||||||
|
|
||||||
|
4. **Add tests** — Test the HTTP handler in `test/webhook.test.ts`.
|
||||||
|
|
||||||
|
### Adding a new `workflow_call` input
|
||||||
|
|
||||||
|
1. Add to `configSchema` in `src/config.ts` — use the appropriate Zod validator.
|
||||||
|
2. Add to `review-reusable.yml` `inputs:` section.
|
||||||
|
3. Add to `review.yml` `with:` section, wiring from `vars.*` or `secrets.*`.
|
||||||
|
4. Add to `.env.example` for local development.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. How to Add a New Review Check
|
||||||
|
|
||||||
|
The review pipeline is: `GooseReviewer.review()` → `normalizeReviewDecision()` → `evaluateReviewDecision()` → `submitReview()`.
|
||||||
|
|
||||||
|
### Adding a new finding type in the goose prompt
|
||||||
|
|
||||||
|
1. **Extend the prompt** — Edit `src/review/prompt.ts`, `buildSystemPrompt()` function. Add a new rule:
|
||||||
|
|
||||||
|
```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.";
|
||||||
|
```
|
||||||
|
|
||||||
|
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`.
|
||||||
|
|
||||||
|
3. **Update normalization** — If the new field needs validation, update `src/review/normalize.ts`.
|
||||||
|
|
||||||
|
### Adding a post-goose processing step
|
||||||
|
|
||||||
|
1. **Add a new check function** in `src/review/` — e.g., `src/review/staticChecks.ts`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import type { ReviewFinding } from "../types.js";
|
||||||
|
|
||||||
|
export function runStaticChecks(files: unknown[]): ReviewFinding[] {
|
||||||
|
// Implement static analysis
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Integrate into processor** — In `src/review/processor.ts`, `processPullRequest()`, after the goose review call, merge static findings:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
const staticFindings = runStaticChecks(compactFiles);
|
||||||
|
const mergedFindings = [...decision.change, ...staticFindings];
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Add tests** — Test the static check function in isolation.
|
||||||
|
|
||||||
|
### Adding a new review policy option
|
||||||
|
|
||||||
|
1. **Add the policy value** — Add to `REVIEW_POLICY` zod enum in `src/config.ts`:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
reviewPolicy: z.enum(["allow", "require_approval", "reject", "new_policy"]).default("allow"),
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Handle in policy.ts** — Update `evaluateReviewDecision()` in `src/review/policy.ts` to handle the new value.
|
||||||
|
|
||||||
|
3. **Update the review format** — Update `formatReviewBody()` in `src/review/format.ts` to display the new policy.
|
||||||
|
|
||||||
|
4. **Update docs** — Add to `.env.example`, `README.md`, and `README-zh.md`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. How to Run the Audit
|
||||||
|
|
||||||
|
### Full audit
|
||||||
|
|
||||||
|
The comprehensive audit report is at `docs/audit-v2-final.md`. To run a fresh audit:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 1. Verify baseline
|
||||||
|
npm run typecheck && npm test && npm run build
|
||||||
|
|
||||||
|
# 2. Generate coverage report
|
||||||
|
node --import tsx --experimental-test-coverage --test test/**/*.test.ts
|
||||||
|
|
||||||
|
# 3. Review compatibility table
|
||||||
|
# Check docs/audit-v2-final.md for the latest requirements matrix
|
||||||
|
```
|
||||||
|
|
||||||
|
### Quick health check
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Type + lint + test + build — all four must pass
|
||||||
|
npm run typecheck && npm run lint && npm test && npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
### Manual audit checklist
|
||||||
|
|
||||||
|
1. **Requirements trace** — Compare `docs/audit-v2-final.md` section 1 against actual code behavior.
|
||||||
|
2. **Blind spot scan** — Review `docs/audit-v2-final.md` section 2 for known gaps.
|
||||||
|
3. **Coverage** — Section 7 for current coverage numbers.
|
||||||
|
4. **Security** — Section 6 for the security review matrix.
|
||||||
|
5. **Architecture** — Section 4 for module health.
|
||||||
|
|
||||||
|
### 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
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. How to Do a Release
|
||||||
|
|
||||||
|
### Pre-release checklist
|
||||||
|
|
||||||
|
- [ ] `npm run typecheck` passes
|
||||||
|
- [ ] `npm run lint` passes (0 errors)
|
||||||
|
- [ ] `npm run format:check` passes
|
||||||
|
- [ ] `npm test` passes (all tests green)
|
||||||
|
- [ ] Coverage meets 80% lines target (check `ci:test` output)
|
||||||
|
- [ ] `npm run build` succeeds
|
||||||
|
- [ ] `workflow_status.md` is up to date
|
||||||
|
- [ ] `docs/audit-v2-final.md` is up to date (if applicable)
|
||||||
|
- [ ] `README.md` and `README-zh.md` reflect current behavior
|
||||||
|
- [ ] `.env.example` covers all config options
|
||||||
|
|
||||||
|
### Release steps
|
||||||
|
|
||||||
|
1. **Update version** — Edit `package.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"version": "2.0.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Update changelog** — Create or update `CHANGELOG.md` with conventional commits format:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [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
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Commit and tag**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git add -A
|
||||||
|
git commit -m "chore: bump version to v2.0.0"
|
||||||
|
git tag v2.0.0
|
||||||
|
git push origin main --tags
|
||||||
|
```
|
||||||
|
|
||||||
|
4. **Create GitHub Release**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
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
|
||||||
|
|
||||||
|
### Post-release
|
||||||
|
|
||||||
|
- Update `workflow_status.md` with the new baseline
|
||||||
|
- Archive the audit report to `docs/reports/` if detailed
|
||||||
|
- Update `metadata.repo_baseline` in this skill file
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuration Reference
|
||||||
|
|
||||||
|
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 |
|
||||||
|
| `REVIEW_STRICTNESS` | `normal` | Review strictness: normal/strict |
|
||||||
|
| `AUTO_MERGE` | `false` | Auto-merge on pass |
|
||||||
|
| `AUTO_RESOLVE_CONFLICTS` | `false` | Auto-resolve merge conflicts |
|
||||||
|
| `TRIAGE_ENABLED` | `true` | Enable issue/PR triage |
|
||||||
|
| `WEBHOOK_ENABLED` | `false` | Enable webhook mode |
|
||||||
|
|
||||||
|
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 |
|
||||||
|
| `src/review/policy.ts` | Review policy evaluation |
|
||||||
|
| `src/review/gooseReviewer.ts` | LLM review prompt + schema |
|
||||||
|
| `src/review/conflictResolver.ts` | Merge conflict resolution |
|
||||||
|
| `src/triage/processor.ts` | Issue/PR triage and duplicate detection |
|
||||||
|
| `src/chat/processor.ts` | @bot chat in disposable containers |
|
||||||
|
| `src/ai/gooseCli.ts` | Goose CLI and Docker wrappers |
|
||||||
|
| `src/ai/apiProxy.ts` | One-time credential proxy |
|
||||||
|
| `src/config.ts` | All env config with Zod validation |
|
||||||
|
| `src/metrics/collector.ts` | Actions metrics collector |
|
||||||
|
| `src/review/merge-guard.ts` | Merge deduplication guard |
|
||||||
|
| `src/ai/failureMessages.ts` | Error categorization |
|
||||||
|
| `docs/audit-v2-final.md` | Comprehensive audit report |
|
||||||
|
| `workflow_status.md` | Milestone tracking |
|
||||||
|
| `.github/workflows/ci.yml` | CI pipeline |
|
||||||
|
| `.github/workflows/review.yml` | PR review workflow |
|
||||||
@@ -0,0 +1,555 @@
|
|||||||
|
# ghbot v2.0 最终审计报告
|
||||||
|
|
||||||
|
**审计日期**: 2026-08-24
|
||||||
|
**基准版本**: v1.2.0 (v2.0 半程)
|
||||||
|
**审计范围**: 全部 src/ (35 文件), test/ (48 文件), 配置, 文档, 工作流
|
||||||
|
**覆盖率**: lines 66.20% / branches 87.36% / functions 75.57% / 321 tests
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. 需求追踪矩阵
|
||||||
|
|
||||||
|
### 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 | 无 |
|
||||||
|
| 审查结果缓存 (本地) | `review/cache.ts` | ✅ | 文件缓存 + 校验 | 无 |
|
||||||
|
| 审查结果持久化 (R2) | `storage/cacheStore.ts` | ✅ | 多版本保存 | 无 |
|
||||||
|
| 增量审查 (旧结果复用) | `review/processor.ts` → `loadPreviousReview` | ✅ | 传递到 goose prompt | **无陈旧检测** — 旧结果只在 LLM prompt 中提及,不做结构性比对 |
|
||||||
|
| 进度评论 | `review/processor.ts` → `begin/finishCommitReviewProgress` | ✅ | 按 commit SHA 标记 | 无 |
|
||||||
|
| 旧审查清理 | `review/processor.ts` → `supersedePreviousBotReviews` | ✅ | GraphQL 解析线程 + minimize | 无 |
|
||||||
|
| 审查评论回退 (Actions 不能 approve) | `review/processor.ts` → `shouldFallbackToCommentReview` | ✅ | 422 检测 + 降级 COMMENT | 无 |
|
||||||
|
|
||||||
|
### 1.2 Issue/PR 分类
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| Issue 标签分类 | `triage/processor.ts` → `processIssueTriage` | ✅ | 单阶段 goose 调用 | 无 |
|
||||||
|
| PR 标签分类 | `triage/processor.ts` → `processPullRequestTriage` | ✅ | 两阶段粗筛+详查 | 无 |
|
||||||
|
| 重复检测 (单阶段) | `triage/processor.ts` → `runSingleStageTriage` | ✅ | Issue 专用 | 无 |
|
||||||
|
| 重复检测 (两阶段) | `triage/processor.ts` → `triagePullRequestInTwoStages` | ✅ | 粗筛+证据加载+详查 | 无 |
|
||||||
|
| 重复评论去重 | `triage/processor.ts` → `postDuplicateFeedback` | ✅ | 隐藏 HTML marker | 无 |
|
||||||
|
| 标签自动创建 | `triage/processor.ts` → `ensureLabelsExist` | ✅ | 缺则创建 | 无 |
|
||||||
|
|
||||||
|
### 1.3 @bot PR 对话
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| @bot 提及检测 | `chat/processor.ts` → `containsBotMention` | ✅ | 多别名 | 无 |
|
||||||
|
| 权限检查 | `chat/processor.ts` → `isTrustedChatPermission` | ✅ | write/maintain/admin | 无 |
|
||||||
|
| 快照脱敏 | `chat/processor.ts` → `createRepositorySnapshot` | ✅ | 排除 .git + 配置 + 符号链接 | 无 |
|
||||||
|
| 一次性容器 | `ai/gooseCli.ts` → `runGooseAgent` | ✅ | Docker 隔离 | 无 |
|
||||||
|
| 凭据代理 | `ai/apiProxy.ts` → `startOneRunApiProxy` | ✅ | 一次性 token + 时间比较 | 无 |
|
||||||
|
| 回复去重 | `chat/processor.ts` → `hasExistingReply` | ✅ | 隐藏 marker | 无 |
|
||||||
|
| 语言跟随 | `chat/processor.ts` → `chatReplyLanguageInstruction` | ✅ | 中英文检测 | 无 |
|
||||||
|
| 认知写入 | `chat/processor.ts` + `repository/knowledge.ts` | ✅ | 快照内 scratch 文件 | 无 |
|
||||||
|
|
||||||
|
### 1.4 冲突修复
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| 自动冲突修复 | `review/conflictResolver.ts` → `resolvePullRequestConflicts` | ✅ | 完整流水线 | 无 |
|
||||||
|
| 冲突检测 | `review/conflictResolver.ts` → `canAutoResolveConflicts` | ✅ | 8 条件判断 | 无 |
|
||||||
|
| Git 操作安全 | `review/conflictResolver.ts` → `buildConflictPushArgs` | ✅ | 仓库/分支/SHA 安全校验 | 无 |
|
||||||
|
| 隔离验证 | `review/conflictResolver.ts` → `runConflictValidation` | ✅ | 只读 Docker 容器 | 无 |
|
||||||
|
| 最终确认 | `review/conflictResolver.ts` → `confirmFinalResolution` | ✅ | 无工具 goose 只读 + Zod schema | 无 |
|
||||||
|
| 冲突锁 | `review/conflictResolver.ts` → `acquireConflictLock` | ✅ | 内存 Set 锁 | **无超时释放** — 如果进程异常退出,锁不会自动释放(内存级,重启后自然消失) |
|
||||||
|
| 强制推送保护 | `review/conflictResolver.ts` → `buildConflictPushArgs` | ✅ | `--force-with-lease` + SHA 绑定 | 无 |
|
||||||
|
|
||||||
|
### 1.5 Webhook 模式
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| 签名校验 | `webhook/server.ts` → `verifyGitHubWebhookSignature` | ✅ | HMAC-SHA256 + timingSafeEqual | 无 |
|
||||||
|
| 去重 | `webhook/server.ts` → `WebhookTaskQueue` | ✅ | deliveryId 去重 24h 保留 | 无 |
|
||||||
|
| 任务队列 | `webhook/server.ts` → `WebhookTaskQueue` | ✅ | 并发 + 限流 + 重试 2 次 | **无持久化** — 进程重启丢队列 |
|
||||||
|
| 指标端点 | `webhook/metrics.ts` → `MetricsRegistry` | ✅ | Prometheus 格式 | 无 |
|
||||||
|
| 只读聊天 | `webhook/processor.ts` → `processWebhookMention` | ✅ | 无工具 goose | 无 |
|
||||||
|
| 组织成员权限 | `webhook/processor.ts` → `getCommenterPermission` | ✅ | orgs.checkMembershipForUser | 无 |
|
||||||
|
|
||||||
|
### 1.6 仓库认知
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| 认知加载 | `repository/knowledge.ts` → `loadRepositoryKnowledge` | ✅ | 未命中时创建默认模板 | 无 |
|
||||||
|
| 认知校验 | `repository/knowledge.ts` → `validateRepositoryKnowledge` | ✅ | 32 KiB 限制 + 密钥检测 | 无 |
|
||||||
|
| 认知持久化 | `storage/cacheStore.ts` | ✅ | R2 写入 | 无 |
|
||||||
|
| 认知写入 (Agent) | `chat/processor.ts` + `repository/knowledge.ts` | ✅ | 快照内 scratch 文件 | 无 |
|
||||||
|
|
||||||
|
### 1.7 事件路由
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| 事件路由 | `actions/router.ts` → `EventRouter` | ✅ | 注册+分发 | 无 |
|
||||||
|
| 三链路隔离 | `actions/router.ts` → `Promise.allSettled` | ✅ | recheck/conflict/chat 互相独立 | 无 |
|
||||||
|
| 错误汇总 | `actions/router.ts` → `AggregateError` | ✅ | 多个失败时汇总 | 无 |
|
||||||
|
|
||||||
|
### 1.8 新增模块 (v2.0 半程)
|
||||||
|
|
||||||
|
| 需求 | 实现位置 | 状态 | 证据 | 缺口 |
|
||||||
|
|------|---------|------|------|------|
|
||||||
|
| 合并防重入 | `review/merge-guard.ts` → `MergeGuard` | ✅ | 100% 测试覆盖 | **未接入 processor.ts** — 有定义无调用 |
|
||||||
|
| 失败分类 | `ai/failureMessages.ts` | ✅ | 100% 测试覆盖 | **未接入生产代码** — 无 import 引用 |
|
||||||
|
| 指标收集器 | `metrics/collector.ts` → `MetricsCollector` | ✅ | 100% 测试覆盖 | **未接入生产代码** — 无 import 引用 |
|
||||||
|
| 智能重试 | `retry.ts` → `withRetry` | ✅ | 抖动 + 总超时 + 可重试判断 | 无 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. 盲点扫描
|
||||||
|
|
||||||
|
### 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 |
|
||||||
|
| B-04 | `review/conflictResolver.ts` | `buildGooseAgentDockerArgs` 使用 `--add-host host.docker.internal:host-gateway`,但并非所有 Docker 环境支持 | Linux 上无 dockerd 或不同网络模式时容器内无法连接代理 | P1 |
|
||||||
|
| B-05 | `chat/processor.ts` | `createRepositorySnapshot` 使用 `verbatimSymlinks: true` 后过滤符号链接,但 `cp` 递归可能复制大文件 | 快照体积不可控 | P2 |
|
||||||
|
| B-06 | `webhook/server.ts` | `WebhookTaskQueue` 重试 2 次后直接丢弃,不通知外部 | 静默丢失 webhook 请求 | P2 |
|
||||||
|
| B-07 | `webhook/processor.ts` | `loadWebhookContext` 在 `pull_request_review` 事件中不加载 files | 对话无 diff 上下文 | P2 |
|
||||||
|
| B-08 | `triage/processor.ts` | `listCandidates` 不分页,只取第一页 `per_page=100` | 超过 100 个候选时丢失 | P2 |
|
||||||
|
| B-09 | `triage/processor.ts` | `loadPullRequestEvidence` 每项只取最后 8 条 | 证据采样可能不足 | P3 |
|
||||||
|
| B-10 | `review/normalize.ts` | 只过滤 `path` 不在文件列表和 `line<=0` 的 finding | 不校验 `line` 是否在 patch 有效行范围内 | P2 |
|
||||||
|
| B-11 | `review/processor.ts` | `reviewProgressMarker` 只绑定 commit SHA,不绑定 PR 编号 | 不同 PR 间可能混淆(scoped 到 PR 内,问题不大) | P3 |
|
||||||
|
| B-12 | `review/processor.ts` | `processScheduledPendingMerges` 对 PR 分页只取 `per_page=100` 无后续分页 | 超过 100 个开放 PR 时遗漏 | P2 |
|
||||||
|
| B-13 | `review/processor.ts` | `hasCurrentHeadApprovalFrom` 的权限检查循环中,第一次失败后继续尝试,但最后如果所有都失败抛出最后一个错误 | 一个查询失败可能掩盖其他成功 | P2 |
|
||||||
|
| B-14 | `review/processor.ts` | `processRecheckComment` 和 `processConflictComment` 在 `getCollaboratorPermissionLevel` 404 时返回 `permission: null`,然后无权限回复 | 外部协作者降级正确 | P3 |
|
||||||
|
| B-15 | `review/conflictResolver.ts` | `buildCommandEnvironment` 中的 `SHELL` 环境变量直接传递 | 可能影响容器内行为 | P3 |
|
||||||
|
|
||||||
|
### 2.2 错误路径
|
||||||
|
|
||||||
|
| 编号 | 区域 | 错误路径 | 当前处理 | 改进建议 |
|
||||||
|
|------|------|---------|---------|---------|
|
||||||
|
| E-01 | `review/processor.ts` | `createGitHubReview` 提交失败后只做一次 fallback | 降级到 COMMENT 但仍在同一事件中继续 | 可考虑重试 |
|
||||||
|
| E-02 | `review/processor.ts` | `supersedePreviousBotReviews` 中部分 GraphQL 调用失败 | 日志 warn 后继续 | 正确 |
|
||||||
|
| E-03 | `ai/gooseCli.ts` | Docker 容器创建失败 | 抛出异常 | 正确 |
|
||||||
|
| E-04 | `ai/gooseCli.ts` | goose 输出超过 1M 字符 | 截断末尾 + 抛出 error | 极端情况应降级而非整体失败 |
|
||||||
|
| E-05 | `ai/gooseCli.ts` | `resolveHostGooseBinary` 在非 Linux 上返回 undefined | 容器内从网络下载 | 非 Linux 环境无法使用,需文档说明 |
|
||||||
|
| E-06 | `review/conflictResolver.ts` | `parseFinalConfirmation` 解析失败 | 抛出异常 | 正确(不提交不安全结果) |
|
||||||
|
| E-07 | `review/conflictResolver.ts` | `runCommandAllowFailure` 超时后 SIGTERM+5s SIGKILL | 合理 | 正确 |
|
||||||
|
| E-08 | `chat/processor.ts` | `createRepositorySnapshot` 复制失败 | 清理快照后抛出 | 正确 |
|
||||||
|
|
||||||
|
### 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` 内部无超时 |
|
||||||
|
| S-04 | `gooseCli.ts` 在 `runGoosePrompt` 中直接将 `config.gooseApiKey` 设为环境变量 `OPENAI_API_KEY` | `gooseCli.ts:408` | P1 | 子进程环境变量可能通过 `/proc` 或其他方式泄露到同一宿主的不同进程 |
|
||||||
|
| S-05 | `review/conflictResolver.ts` `askpass.sh` 中 `GHBOT_GIT_TOKEN` 通过环境变量传递 | `conflictResolver.ts:139` | P1 | askpass 脚本在子进程环境中,Git 子进程可能继承此变量 |
|
||||||
|
| S-06 | `review/conflictResolver.ts` `buildCommandEnvironment` 传递 `NODE_EXTRA_CA_CERTS`、`SSL_CERT_FILE`、`SSL_CERT_DIR` | `conflictResolver.ts:1237-1240` | P2 | 可能绕过证书验证 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. P0/P1/P2/P3 问题清单
|
||||||
|
|
||||||
|
### 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` 未调用 |
|
||||||
|
| P1-04 | `processor.ts` 1736 行 | `review/processor.ts` | 远超 800 行上限,核心编排逻辑难以维护和测试 |
|
||||||
|
| P1-05 | `conflictResolver.ts` 1250 行 | `review/conflictResolver.ts` | 远超 800 行上限,包含多个独立职责 |
|
||||||
|
| P1-06 | coverage 不足 | 全局 | lines 66.20% 远低于 80% 目标;`processor.ts` 49.42%、`triage/processor.ts` 63.19% |
|
||||||
|
| P1-07 | `waitForMergeable` 无超时约束 | `review/processor.ts:1411-1432` | 5 次重试 1s 间隔,无总超时,可能无限等待 |
|
||||||
|
| P1-08 | 审查运行期间无陈旧检测 | `review/processor.ts:98-105` | LLM 运行期间 head 变化时丢弃结果,浪费完整调用 |
|
||||||
|
|
||||||
|
### 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,超过时遗漏 |
|
||||||
|
| P2-04 | `triage/processor.ts` `listCandidates` 不分页 | `triage/processor.ts:291-332` | 只取 100 条,超过时遗漏 |
|
||||||
|
| P2-05 | `webhook/processor.ts` 对 `pull_request_review` 事件不加载 files | `webhook/processor.ts:309-317` | 对话无 diff 上下文 |
|
||||||
|
| P2-06 | `review/normalize.ts` 不校验 line 有效性 | `review/normalize.ts:32-33` | 只校验 `line>0`,不校验是否在 patch 有效行范围内 |
|
||||||
|
| P2-07 | `apiProxy.ts` 中 `Buffer.from(suppliedToken)` 可能抛出异常 | `apiProxy.ts:131` | 未处理非 ASCII token 的编码异常 |
|
||||||
|
| P2-08 | `gooseCli.ts` 中 `OPENAI_API_KEY` 暴露到子进程环境 | `gooseCli.ts:408` | 可能通过 `/proc/PID/environ` 泄露 |
|
||||||
|
| P2-09 | `conflictResolver.ts` 中 `GHBOT_GIT_TOKEN` 通过环境变量传递 | `conflictResolver.ts:139` | git 子进程可读取此环境变量 |
|
||||||
|
| P2-10 | 日志中 `err.stderr` 被 redact 但 `error.stderr` 保留 | `logger.ts:33-34` | 不一致的 redact 模式 |
|
||||||
|
|
||||||
|
### P3 (低)
|
||||||
|
|
||||||
|
| ID | 问题 | 位置 | 说明 |
|
||||||
|
|----|------|------|------|
|
||||||
|
| P3-01 | 无分片并行审查 | `review/processor.ts` | 大 PR 串行 LLM 调用延迟高 |
|
||||||
|
| P3-02 | 无 AI Provider 抽象层 | `ai/gooseCli.ts` | 换 provider 需大改 |
|
||||||
|
| P3-03 | 审查结果无去重 | `review/gooseReviewer.ts` | 相似 finding 刷屏 |
|
||||||
|
| P3-04 | 审查结果无自检 | `review/gooseReviewer.ts` | 矛盾/低质量结果无检查 |
|
||||||
|
| P3-05 | 无国际化 | 全局 | 所有评论英文写死 |
|
||||||
|
| P3-06 | `conflictResolver.ts` 冲突锁无超时 | `review/conflictResolver.ts:71-79` | 同进程内永久阻塞风险 |
|
||||||
|
| P3-07 | `ci.yml` 无覆盖率门槛 | `.github/workflows/ci.yml` | 覆盖率下降不会被阻止 |
|
||||||
|
| P3-08 | 无预提交 hook | 项目根 | 无 husky/lint-staged |
|
||||||
|
| P3-09 | 版本号管理在 `package.json` 但无自动 changelog | — | 需手动更新 |
|
||||||
|
| P3-10 | `ci.yml` 中 `npm ci` 未使用 `--production` 或 `--ignore-scripts` | — | 构建时执行所有生命周期脚本 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. 架构评审
|
||||||
|
|
||||||
|
### 4.1 模块边界
|
||||||
|
|
||||||
|
```
|
||||||
|
actions/ ← 入口层 (router + runReview)
|
||||||
|
├── router.ts ← 事件路由注册 + 分发
|
||||||
|
└── runReview.ts ← Actions 入口 + payload 构建
|
||||||
|
review/ ← 审查核心(最大模块)
|
||||||
|
├── processor.ts ← 1736 行 — 含 7+ 职责
|
||||||
|
├── conflictResolver.ts ← 1250 行 — 含 5+ 职责
|
||||||
|
├── gooseReviewer.ts ← 审查 prompt + schema
|
||||||
|
├── normalize.ts ← 结果净化
|
||||||
|
├── format.ts ← 评论格式化
|
||||||
|
├── policy.ts ← 策略 + 状态标记
|
||||||
|
├── cache.ts ← 本地缓存
|
||||||
|
├── prompt.ts ← patch 截断
|
||||||
|
└── merge-guard.ts ← 未接入
|
||||||
|
ai/ ← AI 调用层
|
||||||
|
├── gooseCli.ts ← 726 行 — 3 种运行模式混用
|
||||||
|
├── apiProxy.ts ← 一次性凭据代理
|
||||||
|
└── failureMessages.ts ← 未接入
|
||||||
|
chat/ ← @bot 对话
|
||||||
|
└── processor.ts ← 358 行
|
||||||
|
triage/ ← 分类
|
||||||
|
└── processor.ts ← 576 行
|
||||||
|
github/ ← GitHub API 封装
|
||||||
|
├── client.ts ← 认证
|
||||||
|
├── checks.ts ← 状态检查
|
||||||
|
├── diff.ts ← 行号解析
|
||||||
|
├── commandFeedback.ts ← 命令反馈
|
||||||
|
├── botIdentity.ts ← 显示名
|
||||||
|
└── pulls.ts ← 文件列表
|
||||||
|
webhook/ ← 可选 webhook 服务
|
||||||
|
├── server.ts ← 315 行
|
||||||
|
├── processor.ts ← 518 行
|
||||||
|
└── metrics.ts ← 59 行
|
||||||
|
storage/ ← 持久化
|
||||||
|
├── r2.ts ← S3 客户端
|
||||||
|
└── cacheStore.ts ← 缓存编排
|
||||||
|
security/ ← 安全
|
||||||
|
├── sanitization.ts ← 路径排除
|
||||||
|
└── secrets.ts ← 密钥脱敏
|
||||||
|
repository/ ← 仓库认知
|
||||||
|
└── knowledge.ts
|
||||||
|
metrics/ ← 指标
|
||||||
|
└── collector.ts ← 未接入
|
||||||
|
```
|
||||||
|
|
||||||
|
### 4.2 关键架构问题
|
||||||
|
|
||||||
|
| 问题 | 严重程度 | 说明 |
|
||||||
|
|------|---------|------|
|
||||||
|
| `review/processor.ts` 承担过多职责 | P1 | 1736 行:编排、进度、提交、check run、旧审查清理、合并、审批、评论命令 |
|
||||||
|
| `review/conflictResolver.ts` 5 种职责混合 | P1 | 1250 行:冲突检测、git 操作、快照管理、diff 检查、验证、确认 |
|
||||||
|
| 3 个新模块无生产引用 | P1 | `MergeGuard`、`failureMessages`、`MetricsCollector` 均有定义和测试但未引入 |
|
||||||
|
| `ai/gooseCli.ts` 3 种运行模式耦合 | P2 | `runGoosePrompt`(chat)、`runGooseAgent`(Docker + Developer)、`runIsolatedWorkspaceCommand`(验证)在同一个文件中 |
|
||||||
|
| 认证逻辑分散 | P2 | `github/client.ts` 处理两种认证(token + App),但 webhook 另有 `createGitHubAppInstallationCredentials`,`runReview.ts` 中 `createGitHubCredentials` 再次处理 |
|
||||||
|
| 错误处理模式不一致 | P2 | 部分 `catch` 中 `logger.warn` 后继续,部分 `catch` 后 `throw`,无统一策略 |
|
||||||
|
| `withRetry` 在不同调用处使用不同的 label 命名规则 | P3 | 有的用 `github.issues.createComment.*`,有的用 `goose.run.*`,无统一 namespace |
|
||||||
|
|
||||||
|
### 4.3 设计模式评价
|
||||||
|
|
||||||
|
| 模式 | 位置 | 评价 |
|
||||||
|
|------|------|------|
|
||||||
|
| EventRouter (策略模式) | `actions/router.ts` | 良好:注册式分发,可扩展 |
|
||||||
|
| 快照模式 (Snapshot) | `review/conflictResolver.ts` | 良好:`inventorySnapshot` + `diffSnapshotInventories` + `applySnapshotChanges` 三阶段 |
|
||||||
|
| 仓储模式 (Repository) | `storage/r2.ts` | 一般:`downloadR2Object`/`uploadR2Object` 是过程式,非接口抽象 |
|
||||||
|
| 代理模式 (Proxy) | `ai/apiProxy.ts` | 良好:一次性 token 认证 |
|
||||||
|
| 工厂模式 | `actions/router.ts` → `buildDefaultEventRouter` | 良好:集中注册 |
|
||||||
|
| 单例模式 | `logger.ts`、`metrics/collector.ts` | 适当:全局状态合理 |
|
||||||
|
| MergeGuard 防重入 | `review/merge-guard.ts` | 未接入:已定义但无调用 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. 性能评审
|
||||||
|
|
||||||
|
### 5.1 重试策略
|
||||||
|
|
||||||
|
| 方面 | 评价 | 改进建议 |
|
||||||
|
|------|------|---------|
|
||||||
|
| `withRetry` 已实现智能重试 | ✅ 抖动 + 分类 + 总超时 | 已落地 (M1-1) |
|
||||||
|
| 默认 5 次重试 + 1s base delay | 合理 | 可接受 |
|
||||||
|
| 4xx 非重试逻辑 | 正确 | 无 |
|
||||||
|
| 总超时退出 | 正确 | 无 |
|
||||||
|
| gobose 调用 3 次重试 | `review/gooseReviewer.ts:63` | 合理,LLM 调用昂贵 |
|
||||||
|
|
||||||
|
### 5.2 缓存策略
|
||||||
|
|
||||||
|
| 方面 | 评价 | 改进建议 |
|
||||||
|
|------|------|---------|
|
||||||
|
| 本地审查缓存 | ✅ 文件级缓存 + Zod 校验 | 无 |
|
||||||
|
| R2 持久化缓存 | ✅ 多版本 + 身份校验 | 无 |
|
||||||
|
| 仓库认知缓存 | ✅ 32 KiB 限制 + 密钥检测 | 可增加版本管理/淘汰 |
|
||||||
|
| 缓存预热 | ❌ 无预热 | `loadPreviousReview` 和 `restorePersistentCache` 串行等待 |
|
||||||
|
| 审查差异分析 | ❌ 无差异复用 | 每次 `synchronize` 全量审查 |
|
||||||
|
|
||||||
|
### 5.3 并发处理
|
||||||
|
|
||||||
|
| 方面 | 评价 | 改进建议 |
|
||||||
|
|------|------|---------|
|
||||||
|
| 事件路由并行 | ✅ `Promise.allSettled` 三链路隔离 | 无 |
|
||||||
|
| webhook 队列 | ✅ 并发控制 + 限流 | 可加持久化 |
|
||||||
|
| 冲突锁 | ✅ 内存 Set 锁 | 可加超时 |
|
||||||
|
| 合并防重入 | ❌ `MergeGuard` 未接入 | 需接入 processor.ts |
|
||||||
|
| 分片审查 | ❌ 无并行 LLM 审查 | 大 PR 延迟高 |
|
||||||
|
|
||||||
|
### 5.4 内存与资源
|
||||||
|
|
||||||
|
| 方面 | 评价 |
|
||||||
|
|------|------|
|
||||||
|
| ECD 容器内存限制 4GB | 合理 |
|
||||||
|
| ECD 容器 CPU 2 核 | 合理 |
|
||||||
|
| 进程数限制 512 | 合理 |
|
||||||
|
| 输出截断 1M 字符 | 合理 |
|
||||||
|
| 快照大小无限制 | 风险:大仓库可能复制大量文件 |
|
||||||
|
| webhook 队列内存 | 有限流 `queueLimit=500` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 6. 安全评审
|
||||||
|
|
||||||
|
### 6.1 密钥处理
|
||||||
|
|
||||||
|
| 密钥 | 位置 | 处理方式 | 评价 |
|
||||||
|
|------|------|---------|------|
|
||||||
|
| `GOOSE_API_KEY` | `config.ts` | Zod schema 读取环境变量 | ✅ |
|
||||||
|
| `GITHUB_TOKEN` | `config.ts` | 直接从 process.env 读取 | ✅ |
|
||||||
|
| GitHub App 私钥 | `config.ts` → `client.ts` | `normalizePrivateKey` 处理 `\\n` | ✅ |
|
||||||
|
| R2 密钥 | `config.ts` | 四件套校验 | ✅ |
|
||||||
|
| 容器内 API key | `apiProxy.ts` | 一次性随机 token 替代 | ✅ |
|
||||||
|
| Git token | `conflictResolver.ts` | `GIT_ASKPASS` 脚本中写入 | ⚠️ 子进程环境变量可读 |
|
||||||
|
|
||||||
|
### 6.2 注入防护
|
||||||
|
|
||||||
|
| 防护 | 位置 | 评价 |
|
||||||
|
|------|------|------|
|
||||||
|
| 路径跨越防护 | `conflictResolver.ts` → `safeFilePath` | ✅ 双重检查 |
|
||||||
|
| 分支名安全校验 | `conflictResolver.ts` → `isSafeGitBranch` | ✅ 控制字符排除 |
|
||||||
|
| 仓库名安全校验 | `conflictResolver.ts` → `isSafeGitHubRepository` | ✅ 正则白名单 |
|
||||||
|
| 快照排除 | `chat/processor.ts` → `createRepositorySnapshot` | ⚠️ `.npmrc`、`terraform/` 等未覆盖 |
|
||||||
|
| 路径保护 | `security/sanitization.ts` | ✅ 集中式清单 |
|
||||||
|
| 密钥脱敏 | `security/secrets.ts` | ✅ 正则匹配 |
|
||||||
|
| 日志 redact | `logger.ts` | ✅ pino redact 配置 |
|
||||||
|
|
||||||
|
### 6.3 脱敏覆盖
|
||||||
|
|
||||||
|
| 路径/模式 | 已覆盖 | 缺漏 |
|
||||||
|
|-----------|--------|------|
|
||||||
|
| GitHub PAT (ghp_...) | ✅ | — |
|
||||||
|
| GitHub PAT v2 (github_pat_) | ✅ | — |
|
||||||
|
| OpenAI API key (sk-...) | ✅ | — |
|
||||||
|
| Bearer token | ✅ | — |
|
||||||
|
| 私钥 (-----BEGIN ... PRIVATE KEY-----) | ✅ | — |
|
||||||
|
| SSH 私钥 | ❌ | `-----BEGIN OPENSSH PRIVATE KEY-----` 未匹配(`BEGIN [A-Z ]*PRIVATE KEY` 已覆盖) | ✅ |
|
||||||
|
| 日志 redact 路径 | ✅ | `err.stderr` vs `error.stderr` 不一致 (P2-10) |
|
||||||
|
|
||||||
|
### 6.4 安全评估总结
|
||||||
|
|
||||||
|
| 领域 | 评级 | 要点 |
|
||||||
|
|------|------|------|
|
||||||
|
| 凭据隔离 | A | 容器内无真实凭据,一次性代理安全 |
|
||||||
|
| 注入防护 | A | 路径/分支/仓库名白名单校验完善 |
|
||||||
|
| 快照脱敏 | B+ | 主要路径已覆盖,缺 `.npmrc` 等 |
|
||||||
|
| 密钥脱敏 | A | 正则 + 日志 redact 双保险 |
|
||||||
|
| 子进程安全 | B | 环境变量泄露风险较低但有 |
|
||||||
|
| 整体安全 | A- | 生产级安全实践,无重大漏洞 |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 7. 测试评审
|
||||||
|
|
||||||
|
### 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` |
|
||||||
|
| `webhook/processor.ts` | 72.39% | ≥80% | `processWebhookMention` 主流程、`loadWebhookContext` 大部分、`getCommenterPermission` 组织成员分支 |
|
||||||
|
| `webhook/server.ts` | 75.87% | ≥80% | `createWebhookServer` 队列满 503、body 超时 413、`startWebhookServer` 完整流程 |
|
||||||
|
| `storage/cacheStore.ts` | 95.73% | ≥95% | 剩余少量行 |
|
||||||
|
|
||||||
|
### 7.2 测试质量
|
||||||
|
|
||||||
|
| 维度 | 评价 |
|
||||||
|
|------|------|
|
||||||
|
| 测试结构 | ✅ AAA 模式统一使用 |
|
||||||
|
| 测试命名 | ✅ 描述性命名 |
|
||||||
|
| Mock 使用 | ✅ 无真实 LLM/HTTP 调用 |
|
||||||
|
| 边界测试 | ⚠️ 部分模块有边界但不足 |
|
||||||
|
| 集成测试 | ❌ 无集成测试 (test/integration/ 不存在) |
|
||||||
|
| E2E 测试 | ❌ 无 E2E 测试 |
|
||||||
|
| 覆盖率门禁 | ❌ `ci.yml` 未设置覆盖率阈值 |
|
||||||
|
|
||||||
|
### 7.3 测试文件增长
|
||||||
|
|
||||||
|
| 指标 | v1.2.0 | 当前 | 增长 |
|
||||||
|
|------|--------|------|------|
|
||||||
|
| 测试文件 | 36 | 48 | +12 |
|
||||||
|
| 测试数 | 151 | 321 | +170 |
|
||||||
|
| 覆盖率 lines | 61.41% | 66.20% | +4.79% |
|
||||||
|
| 覆盖率 branches | 82.98% | 87.36% | +4.38% |
|
||||||
|
| 覆盖率 functions | 69.97% | 75.57% | +5.60% |
|
||||||
|
|
||||||
|
### 7.4 测试缺口详细分析
|
||||||
|
|
||||||
|
**processor.ts 核心缺口:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 未测试的极端路径:
|
||||||
|
- processPullRequest 中 draft/skip 跳过 → 正确跳过
|
||||||
|
- processPullRequest 中恶意代码关闭 → closeMaliciousPullRequest
|
||||||
|
- submitReview 中 file 不存在 → unpostedFindings
|
||||||
|
- createGitHubReview 中 422 回退 → COMMENT
|
||||||
|
- upsertReviewCheckRun 中 malice/requireAdmin 不同结论
|
||||||
|
- waitForMergeable 5 次后 null 返回
|
||||||
|
- mergeable_state=dirty 时冲突修复
|
||||||
|
- schedule 中已合并 PR 的跳过
|
||||||
|
- hasCurrentHeadApprovalFrom 中 404 处理
|
||||||
|
- processRecheckComment 中权限不足
|
||||||
|
- processConflictComment 中非 dirty 状态跳过
|
||||||
|
```
|
||||||
|
|
||||||
|
**conflictResolver.ts 核心缺口:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
- resolvePullRequestConflicts 主流程中任何分支失败
|
||||||
|
- buildConflictPrompt 中 validationCommand 有无分支
|
||||||
|
- buildValidationRepairPrompt 完整文本
|
||||||
|
- runConflictValidation 中基础设施失败分类
|
||||||
|
- remainingConflictTime 超时抛出
|
||||||
|
- commandFailureOutput 中 redactSecrets 接线
|
||||||
|
- buildCommandEnvironment 中 PROXY 环境变量传递
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 8. 文档评审
|
||||||
|
|
||||||
|
### 8.1 README 一致性
|
||||||
|
|
||||||
|
| 对比项 | README.md | README-zh.md | 一致性 |
|
||||||
|
|--------|-----------|-------------|--------|
|
||||||
|
| PR 审查四段输出 | ✅ | ✅ | 一致 |
|
||||||
|
| 审查策略 | ✅ | ✅ | 一致 |
|
||||||
|
| 增量缓存 | ✅ | ✅ | 一致 |
|
||||||
|
| 仓库认知 | ✅ | ✅ | 一致 |
|
||||||
|
| Issue/PR 分类 | ✅ | ✅ | 一致 |
|
||||||
|
| @bot 对话 | ✅ | ✅ | 一致 |
|
||||||
|
| Webhook 模式 | ✅ | ✅ | 一致 |
|
||||||
|
| 冲突修复 | ✅ | ✅ | 一致 |
|
||||||
|
| goose 配置 | ✅ | ✅ | 一致 |
|
||||||
|
| 开发门禁 | ✅ | ✅ | 一致 |
|
||||||
|
| 本地开发 | ✅ | ✅ | 一致 |
|
||||||
|
|
||||||
|
### 8.2 配置文档
|
||||||
|
|
||||||
|
| 配置项 | `.env.example` | README | 代码中 `config.ts` | 一致性 |
|
||||||
|
|--------|---------------|--------|-------------------|--------|
|
||||||
|
| PORT | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| LOG_LEVEL | ✅ | ❌ | ✅ | 未在 README 文档化 |
|
||||||
|
| GHBOT_RUNTIME_DIR | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| GOOSE_API_KEY | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| GOOSE_BASE_URL | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| GOOSE_MODEL | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| GOOSE_THINKING_EFFORT | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REVIEW_POLICY | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REVIEW_STRICTNESS | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REVIEW_INSTRUCTIONS | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REVIEW_BRANCHES | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| R2 配置 | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| TRIAGE 配置 | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| AUTO_MERGE | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| AUTO_RESOLVE_CONFLICTS | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| CONFLICT_TEST_COMMAND | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| MERGE_METHOD | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REQUIRE_CHECKS | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| MAX_PATCH_CHARS | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| BOT_NAME | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| WEBHOOK 配置 | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REPOSITORY_KNOWLEDGE_ENABLED | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
| REPOSITORY_KNOWLEDGE_WRITE | ✅ | ✅ | ✅ | 一致 |
|
||||||
|
|
||||||
|
### 8.3 文档缺漏
|
||||||
|
|
||||||
|
| 缺漏 | 说明 | 优先级 |
|
||||||
|
|------|------|--------|
|
||||||
|
| `LOG_LEVEL` 未在 README 文档化 | 仅在 `.env.example` 和 `config.ts` 中有 | P3 |
|
||||||
|
| `workflow_status.md` 未同步最新状态 | 标记了"未落地项"但未更新为当前实际状态 | P2 |
|
||||||
|
| 无 CHANGELOG | 版本迭代无历史记录 | P3 |
|
||||||
|
| 无 CONTRIBUTING.md 详细指南 | 仅有安全红线在 README 中提及 | P3 |
|
||||||
|
| `docs/reports/ghbot-production-hardening.html` 外部依赖 | 文档链接指向外部文件 | P3 |
|
||||||
|
|
||||||
|
### 8.4 部署文档
|
||||||
|
|
||||||
|
| 部署方式 | 文档化 | 评价 |
|
||||||
|
|---------|--------|------|
|
||||||
|
| GitHub Actions (主模式) | ✅ | 详细 |
|
||||||
|
| Webhook Docker 部署 | ✅ | 详细 |
|
||||||
|
| 本地开发 | ✅ | 详细 |
|
||||||
|
| CI/CD 流水线 | ✅ | 有 `.github/workflows/ci.yml` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 9. 汇总建议
|
||||||
|
|
||||||
|
### 立即修复 (P1)
|
||||||
|
|
||||||
|
1. 将 `MergeGuard`、`failureMessages`、`MetricsCollector` 接入生产代码
|
||||||
|
2. 拆分 `review/processor.ts` (1736 行) 和 `review/conflictResolver.ts` (1250 行) 为 ≤400 行模块
|
||||||
|
3. 补齐 `processor.ts` 和 `conflictResolver.ts` 的测试覆盖率至 ≥80%
|
||||||
|
4. 为 `waitForMergeable` 增加总超时约束
|
||||||
|
5. 实现审查运行期间陈旧检测 (追加段落后缀合并审查)
|
||||||
|
|
||||||
|
### 短期改进 (P2)
|
||||||
|
|
||||||
|
6. 完善 `sanitization.ts` 排除清单 (`.npmrc`、`terraform/`、`kube/`、`docker/` 配置)
|
||||||
|
7. webhook 队列增加持久化能力
|
||||||
|
8. 修复 `logger.ts` 中 `err.stderr` vs `error.stderr` 不一致
|
||||||
|
9. 为 `triage/processor.ts` `listCandidates` 增加分页支持
|
||||||
|
10. 在 `normalize.ts` 中增加 patch 有效行校验
|
||||||
|
|
||||||
|
### 长期演进 (P3+)
|
||||||
|
|
||||||
|
11. 实现分片并行审查 (Sharded Review)
|
||||||
|
12. 实现 AI Provider 抽象层 (`ChatProvider` 接口)
|
||||||
|
13. 实现审查结果去重与自检
|
||||||
|
14. 实现国际化支持
|
||||||
|
15. 实现审查历史学习与自适应严格度
|
||||||
|
16. 在 CI 中设置覆盖率门槛 (≥80%)
|
||||||
|
17. 添加预提交 hook (husky + lint-staged)
|
||||||
|
18. 实现自动 changelog 生成
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 附录 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 种模式耦合 |
|
||||||
|
| 4 | src/triage/processor.ts | 576 | 63.19% | 🟡 低覆盖 |
|
||||||
|
| 5 | src/webhook/processor.ts | 518 | 72.39% | 🟡 中覆盖 |
|
||||||
|
| 6 | src/webhook/server.ts | 315 | 75.87% | 🟡 中覆盖 |
|
||||||
|
| 7 | src/actions/router.ts | 361 | 94.16% | ✅ |
|
||||||
|
| 8 | src/chat/processor.ts | 358 | 93.82% | ✅ |
|
||||||
|
| 9 | src/actions/runReview.ts | 293 | 93.52% | ✅ |
|
||||||
|
| 10 | src/storage/cacheStore.ts | 234 | 95.73% | ✅ |
|
||||||
|
|
||||||
|
## 附录 B: 测试文件清单 (48 文件 / 321 测试)
|
||||||
|
|
||||||
|
测试全部通过。覆盖率 lines 66.20% / branches 87.36% / functions 75.57%。
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
# Critical Code Review: ghbot v2
|
||||||
|
|
||||||
|
**Reviewer**: Automated code review
|
||||||
|
**Scope**: Full source tree (`src/` + `test/`)
|
||||||
|
**Commit**: db53296 (refactor: extract event router and bump version to v1.2.0)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. Summary
|
||||||
|
|
||||||
|
This is a **well-architected** codebase with strong security awareness, thorough testing, and clean separation of concerns. The review pipeline, conflict resolution, and triage subsystems are production-grade. However, several critical defects exist — primarily **dead code shipped as production modules**, **duplicated defensive logic** that should be shared, a **sort-comparator contract violation**, and a **race window in conflict resolution eligibility**.
|
||||||
|
|
||||||
|
The codebase uses a large number of small, focused files, consistent error handling, Zod schema validation everywhere, and comprehensive test coverage. The security posture (credential isolation, snapshot sanitization, path traversal prevention) is notably strong.
|
||||||
|
|
||||||
|
**Verdict: Needs Discussion** — multiple real defects must be resolved before the next release, but no single bug is immediately exploitable or data-destructive in the current deployment.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 2. Critical Issues (Blocking)
|
||||||
|
|
||||||
|
### C1. Dead Production Code: `MergeGuard` never called
|
||||||
|
|
||||||
|
**File**: `src/review/merge-guard.ts`
|
||||||
|
**Evidence**: `src/review/processor.ts` `maybeMergePullRequest()` (line 831) does not instantiate or call `MergeGuard`. The class is defined, tested (`test/merge-guard.test.ts`), but **zero production imports** across the entire `src/` tree.
|
||||||
|
|
||||||
|
**Impact**: The `MergeGuard` class exists solely to prevent duplicate merge attempts from concurrent schedule/approval/recheck events. The current code relies on the reactive `isAlreadyMergedError()` check (processor.ts:970-982), which catches already-merged errors but does not prevent redundant API calls. Under concurrent schedule triggers, two `pulls.merge` calls can race on the same PR — the 405 response is safe but wasteful, and the gap between the fresh PR state check (processor.ts:855-879) and the merge call (line 946) is not protected.
|
||||||
|
|
||||||
|
**Fix**: Instantiate a singleton `MergeGuard` in `processor.ts` and guard `maybeMergePullRequest` at line 909 with `guard.isAlreadyAttempted()` before proceeding, then `guard.markAttempt()` before the merge call.
|
||||||
|
|
||||||
|
### C2. Dead Production Code: `MetricsCollector` never called
|
||||||
|
|
||||||
|
**File**: `src/metrics/collector.ts`
|
||||||
|
**Evidence**: The singleton `export const metrics = new MetricsCollector()` (line 131) is **never imported** by any production module. The webhook server uses `MetricsRegistry` from `webhook/metrics.ts` instead, which is correct — but the Actions-mode `MetricsCollector` is dead code with its own test suite.
|
||||||
|
|
||||||
|
**Impact**: Metric collection in CI Actions mode is entirely non-functional. The `recordReviewDuration`, `recordGooseCall`, `recordConflictResolution`, `recordMergeAttempt` methods are never called. This is not a security or correctness issue, but it means all observability promises in the Actions path are false.
|
||||||
|
|
||||||
|
**Fix**: Either (a) wire the `MetricsCollector` singleton into `processor.ts` and `gooseReviewer.ts` — the `processPullRequest` function, `submitReview`, conflict resolution calls, and `maybeMergePullRequest` are all natural injection points — or (b) delete the module and its tests to avoid misleading future maintainers.
|
||||||
|
|
||||||
|
### C3. Dead Production Code: `failureMessages.ts` never imported
|
||||||
|
|
||||||
|
**File**: `src/ai/failureMessages.ts`
|
||||||
|
**Evidence**: Both exported functions (`categorizeFailure`, `formatFailureMessage`) are **never imported** by any production module. The `withRetry` function in `retry.ts` handles its own error classification, and goose-call sites do not use these utilities.
|
||||||
|
|
||||||
|
**Impact**: A self-contained, tested module that exists solely to be unused. The `formatFailureMessage` function produces user-facing messages that are more descriptive than the raw error propagation currently in use. This is a missed quality improvement.
|
||||||
|
|
||||||
|
**Fix**: Wire `categorizeFailure` into the goose-call retry logic in `retry.ts` or `gooseReviewer.ts`, or delete the file.
|
||||||
|
|
||||||
|
### C4. Sort comparator contract violation in `markReviewCheckApproved`
|
||||||
|
|
||||||
|
**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;
|
||||||
|
const rt = right.started_at ? Date.parse(right.started_at) : 0;
|
||||||
|
return (Number.isNaN(rt) ? 0 : rt) - (Number.isNaN(lt) ? 0 : lt);
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### C5. Conflict resolution proceeds before admin approval
|
||||||
|
|
||||||
|
**File**: `src/review/processor.ts`, lines 188-249
|
||||||
|
**Code**:
|
||||||
|
```typescript
|
||||||
|
const conflictResolutionEligible = canAutoResolveConflicts({
|
||||||
|
enabled: config.autoResolveConflicts,
|
||||||
|
reviewPassed: true, // <-- Hardcoded true
|
||||||
|
...
|
||||||
|
});
|
||||||
|
```
|
||||||
|
**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.
|
||||||
|
|
||||||
|
**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`
|
||||||
|
- `src/review/conflictResolver.ts:1001`
|
||||||
|
- `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;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Impact**: Violates DRY. If the GitHub API ever changes its 404 response shape, all 5 copies must be updated. Adding a new file that needs this check (e.g., a new handler) is likely to create a 6th copy.
|
||||||
|
|
||||||
|
**Fix**: Export a single `isNotFoundError` from `src/github/client.ts` or a new `src/github/errors.ts` and import it everywhere.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 3. Required Changes
|
||||||
|
|
||||||
|
### R1. Duplicate `isNotFoundError` — see C6 above
|
||||||
|
|
||||||
|
### R2. Duplicate type-guard functions in webhook processor
|
||||||
|
|
||||||
|
**File**: `src/webhook/processor.ts`, lines 500-514
|
||||||
|
**Code**: `isRecord`, `asRecord`, `asString`, `asPositiveInteger` are defined locally, duplicating patterns used elsewhere.
|
||||||
|
|
||||||
|
**Fix**: Extract these to a shared utility module (e.g., `src/shared/typeGuards.ts`) and import them.
|
||||||
|
|
||||||
|
### R3. `GOOSE_MODEL` default `"gpt-5.4"` likely does not exist
|
||||||
|
|
||||||
|
**File**: `src/config.ts`, line 62
|
||||||
|
**Code**: `gooseModel: optionalString.default("gpt-5.4")`
|
||||||
|
|
||||||
|
**Issue**: As of August 2026, `gpt-5.4` is not a known OpenAI model name. The first deployment will fail with a model-not-found error unless the operator overrides it. This is a misleading default that will cause every new deployment to fail until the env var is set.
|
||||||
|
|
||||||
|
**Fix**: Either use a known model like `gpt-4o` as the default, or document prominently that `GOOSE_MODEL` must be set. Alternatively, remove the default and make it required.
|
||||||
|
|
||||||
|
### R4. `labelName` function in triage handles both string and object — but called with `issue.labels` which may contain objects with `name` property
|
||||||
|
|
||||||
|
**File**: `src/triage/processor.ts`, line 574
|
||||||
|
**Code**: `issue.labels.map(labelName).filter(Boolean)`
|
||||||
|
|
||||||
|
**Issue**: The `labels` field in the GitHub Issues API response is typed as `Array<{ name: string } | string>`. The `labelName` function handles both cases correctly, but the filter `.filter(Boolean)` after `labelName` is fragile — it will include empty strings as truthy. The `labelName` function returns `string`, and `""` is falsy, so `.filter(Boolean)` is safe here, but the intent is unclear.
|
||||||
|
|
||||||
|
**Fix**: Use `.filter((name): name is string => name !== "")` or add a comment explaining the filter.
|
||||||
|
|
||||||
|
### R5. Hardcoded `reviewPassed: true` in conflict eligibility — see C5
|
||||||
|
|
||||||
|
### R6. `envBoolean` zod preprocessor swallows unknown values
|
||||||
|
|
||||||
|
**File**: `src/config.ts`, lines 8-27
|
||||||
|
**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.`);
|
||||||
|
```
|
||||||
|
|
||||||
|
### R7. `isRecheckComment` and `isConflictComment` only match exact trim
|
||||||
|
|
||||||
|
**Files**: `src/review/processor.ts`, lines 1375-1381
|
||||||
|
**Code**:
|
||||||
|
```typescript
|
||||||
|
export function isRecheckComment(body: string): boolean {
|
||||||
|
return body.trim() === RECHECK_COMMENT_COMMAND;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Issue**: `"/recheck "` (trailing spaces) is accepted, but `"/recheck\n"` is also accepted (trim handles it). However, `" /recheck /recheck"` is rejected. This is intentional. But `"/recheck\n\n"` works. The tests confirm this behavior. No change needed — this is a design choice, not a bug.
|
||||||
|
|
||||||
|
### R8. `waitForMergeable` polls only 5 times with 1s intervals
|
||||||
|
|
||||||
|
**File**: `src/review/processor.ts`, lines 1411-1432
|
||||||
|
**Issue**: For large PRs, GitHub's mergeability computation can take >10 seconds. Five attempts at 1s intervals may not be enough. The function returns the last result even if `mergeable` is still `null`.
|
||||||
|
|
||||||
|
**Fix**: Increase to 10 attempts, or use exponential backoff (1s, 2s, 4s, 8s, 10s, 10s...).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 4. Suggestions
|
||||||
|
|
||||||
|
### S1. Extract `isNotFoundError` to shared module
|
||||||
|
|
||||||
|
See C6. Low effort, high DRY return.
|
||||||
|
|
||||||
|
### S2. Extract type-guard functions to shared module
|
||||||
|
|
||||||
|
See R2. Low effort, reduces duplication.
|
||||||
|
|
||||||
|
### S3. Add `MergeGuard` to `processor.ts`
|
||||||
|
|
||||||
|
See C1. Prevents a rare but real race condition on concurrent schedule events.
|
||||||
|
|
||||||
|
### S4. Wire `MetricsCollector` into production code
|
||||||
|
|
||||||
|
See C2. Either wire it or remove it. Half-shipped observability is worse than none.
|
||||||
|
|
||||||
|
### S5. Wire `failureMessages` into retry logic
|
||||||
|
|
||||||
|
See C3. The `formatFailureMessage` produces better user-facing error messages than the current raw error propagation.
|
||||||
|
|
||||||
|
### S6. Move `PROTECTED_DIRECTORIES` and `PROTECTED_FILE_NAMES` to a shared config
|
||||||
|
|
||||||
|
**File**: `src/security/sanitization.ts`
|
||||||
|
**Suggestion**: These are referenced by `chat/processor.ts`, `review/conflictResolver.ts`, and potentially future modules. The current single-file definition is good. No change needed — this is already well-structured.
|
||||||
|
|
||||||
|
### S7. Add `"Dockerfile"` and `"docker-compose.yml"` to `PROTECTED_FILE_NAMES`?
|
||||||
|
|
||||||
|
**File**: `src/security/sanitization.ts`
|
||||||
|
**Discussion**: These can carry registry credentials and build secrets. Consider adding them. The current list is already comprehensive — this is a judgment call.
|
||||||
|
|
||||||
|
### S8. The `askpass.sh` temporary directory permissions
|
||||||
|
|
||||||
|
**File**: `src/review/conflictResolver.ts`, lines 120-137
|
||||||
|
**Issue**: The directory is created with `fs.mkdtemp` (default permissions = 0o700 on Linux, but the parent directory permissions may be 0o755 or more permissive). The `askpass.sh` script is written with `mode: 0o700`, which is correct. However, the directory containing the token is at `tempRoot/tempDir`, and `tempRoot` is created with `{ recursive: true }` which uses default permissions.
|
||||||
|
|
||||||
|
**Suggestion**: Set `tempRoot` permissions to 0o700 after creation, or use a more restrictive parent directory.
|
||||||
|
|
||||||
|
### S9. The `normalizeReviewMode` function silently maps `"lenient"` to `"normal"`
|
||||||
|
|
||||||
|
**File**: `src/review/policy.ts`, line 143
|
||||||
|
**Code**:
|
||||||
|
```typescript
|
||||||
|
function normalizeReviewMode(value: string): ReviewMode {
|
||||||
|
return value === "strict" ? "strict" : "normal";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Issue**: The `parseReviewExternalId` and `parseReviewStateMarker` functions accept `"lenient"` as a valid mode in their regex patterns, but `normalizeReviewMode` silently maps it to `"normal"`. This means a check run with `external_id` containing `mode=lenient` will be parsed as `mode: "normal"`. The `formatReviewExternalId` never produces `"lenient"`, so this only affects manually crafted check runs. This is tolerable but could be confusing during debugging.
|
||||||
|
|
||||||
|
**Fix**: Either reject `"lenient"` in the regex patterns, or document that `"lenient"` is treated as `"normal"`.
|
||||||
|
|
||||||
|
### S10. Test coverage: `replace_all` is not tested
|
||||||
|
|
||||||
|
No test covers the `replace_all` behavior of `Edit` tool. This is not a codebase issue — it's a tooling note.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 5. Verdict
|
||||||
|
|
||||||
|
**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)
|
||||||
|
- C4: Fix `NaN` sort comparator in `markReviewCheckApproved`
|
||||||
|
- C5: Add `requiresAdminApproval` guard to conflict eligibility
|
||||||
|
- C6: Deduplicate `isNotFoundError`
|
||||||
|
- 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
|
||||||
|
- Error handling is consistent with Zod parsing
|
||||||
|
- Immutability patterns are followed throughout
|
||||||
@@ -0,0 +1,999 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>ghbot v2.0 迭代报告</title>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--bg: #0A0E16;
|
||||||
|
--bg-soft: #0D1420;
|
||||||
|
--surface: #111A2B;
|
||||||
|
--surface-2: #16233A;
|
||||||
|
--hairline: rgba(157, 184, 218, 0.14);
|
||||||
|
--hairline-strong: rgba(157, 184, 218, 0.26);
|
||||||
|
--text: #E9EEF7;
|
||||||
|
--text-2: #A9B7CC;
|
||||||
|
--text-3: #6F7F99;
|
||||||
|
--accent: #6FB7FF;
|
||||||
|
--accent-deep: #3E8DE3;
|
||||||
|
--gain: #46E0A0;
|
||||||
|
--gain-bg: rgba(70, 224, 160, 0.10);
|
||||||
|
--warn: #F2BE5C;
|
||||||
|
--warn-bg: rgba(242, 190, 92, 0.10);
|
||||||
|
--bad: #FF7A86;
|
||||||
|
--bad-bg: rgba(255, 122, 134, 0.10);
|
||||||
|
--mono-bg: #0B111D;
|
||||||
|
--radius: 10px;
|
||||||
|
--font-display: 'Chakra Petch','Segoe UI','Microsoft YaHei',system-ui,sans-serif;
|
||||||
|
--font-body: 'IBM Plex Sans','PingFang SC','Microsoft YaHei',system-ui,sans-serif;
|
||||||
|
--font-mono: 'IBM Plex Mono','Consolas','Courier New',monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
* { box-sizing: border-box; }
|
||||||
|
html { scroll-behavior: smooth; }
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text);
|
||||||
|
font-family: var(--font-body);
|
||||||
|
font-size: 16px;
|
||||||
|
line-height: 1.7;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
::selection { background: rgba(111,183,255,0.28); color: #fff; }
|
||||||
|
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
|
||||||
|
|
||||||
|
a { color: var(--accent); text-decoration: none; }
|
||||||
|
a:hover { text-decoration: underline; }
|
||||||
|
|
||||||
|
code, .mono {
|
||||||
|
font-family: var(--font-mono);
|
||||||
|
font-size: 0.86em;
|
||||||
|
background: var(--mono-bg);
|
||||||
|
border: 1px solid var(--hairline);
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 0.08em 0.42em;
|
||||||
|
color: #C9D8EE;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
code.blk { display: inline-block; padding: 0.15em 0.5em; }
|
||||||
|
|
||||||
|
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
|
||||||
|
|
||||||
|
.container { max-width: 1120px; margin: 0 auto; padding: 0 28px; }
|
||||||
|
|
||||||
|
/* ---------- Top rails ---------- */
|
||||||
|
.topbar {
|
||||||
|
position: sticky; top: 0; z-index: 50;
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
background: rgba(10,14,22,0.82);
|
||||||
|
border-bottom: 1px solid var(--hairline);
|
||||||
|
}
|
||||||
|
.topbar-inner { display: flex; align-items: center; gap: 20px; padding: 12px 28px; max-width: 1120px; margin: 0 auto; }
|
||||||
|
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 600; font-size: 0.95rem; letter-spacing: 0.04em; }
|
||||||
|
.brand-dot { width: 9px; height: 9px; border-radius: 3px; background: var(--gain); box-shadow: 0 0 12px rgba(70,224,160,0.8); }
|
||||||
|
.nav { display: flex; gap: 2px; flex-wrap: wrap; margin-left: auto; }
|
||||||
|
.nav a { color: var(--text-2); font-size: 0.82rem; padding: 5px 12px; border-radius: 6px; font-family: var(--font-mono); }
|
||||||
|
.nav a:hover { color: var(--text); background: var(--surface); text-decoration: none; }
|
||||||
|
|
||||||
|
/* ---------- Hero ---------- */
|
||||||
|
.hero { padding: 72px 0 40px; position: relative; overflow: hidden; }
|
||||||
|
.hero::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute; inset: 0;
|
||||||
|
background:
|
||||||
|
radial-gradient(600px 260px at 82% -20%, rgba(62,141,227,0.16), transparent 70%),
|
||||||
|
radial-gradient(520px 220px at 8% 0%, rgba(70,224,160,0.07), transparent 70%);
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
.hero .container { position: relative; }
|
||||||
|
.kicker { font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.18em; color: var(--gain); text-transform: uppercase; margin: 0 0 18px; }
|
||||||
|
.kicker em { font-style: normal; color: var(--text-3); margin: 0 8px; }
|
||||||
|
h1 {
|
||||||
|
font-family: var(--font-display);
|
||||||
|
font-size: clamp(2.1rem, 5.2vw, 3.4rem);
|
||||||
|
line-height: 1.05;
|
||||||
|
margin: 0 0 16px;
|
||||||
|
font-weight: 600;
|
||||||
|
text-wrap: balance;
|
||||||
|
letter-spacing: -0.01em;
|
||||||
|
}
|
||||||
|
.hero-sub { color: var(--text-2); max-width: 66ch; font-size: 1.02rem; margin: 0 0 34px; }
|
||||||
|
.hero-sub strong { color: var(--text); font-weight: 600; }
|
||||||
|
|
||||||
|
.meta-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 36px; }
|
||||||
|
.meta-chip {
|
||||||
|
font-family: var(--font-mono); font-size: 0.76rem;
|
||||||
|
color: var(--text-2); border: 1px solid var(--hairline);
|
||||||
|
padding: 5px 12px; border-radius: 999px; background: var(--surface);
|
||||||
|
}
|
||||||
|
.meta-chip b { color: var(--text); font-weight: 500; }
|
||||||
|
|
||||||
|
.gate-strip {
|
||||||
|
display: flex; flex-wrap: wrap; gap: 10px;
|
||||||
|
border: 1px solid var(--hairline); border-radius: var(--radius);
|
||||||
|
background: var(--surface); padding: 12px 14px; margin-bottom: 44px;
|
||||||
|
}
|
||||||
|
.gate {
|
||||||
|
display: inline-flex; align-items: center; gap: 8px;
|
||||||
|
font-family: var(--font-mono); font-size: 0.78rem;
|
||||||
|
color: var(--text-2); padding: 4px 12px; border-radius: 6px;
|
||||||
|
border: 1px solid var(--hairline); background: var(--bg-soft);
|
||||||
|
}
|
||||||
|
.gate .ok { color: var(--gain); font-weight: 600; }
|
||||||
|
.gate-label { text-transform: uppercase; letter-spacing: 0.04em; }
|
||||||
|
.gate-result { color: var(--text); }
|
||||||
|
|
||||||
|
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
|
||||||
|
.stat {
|
||||||
|
background: var(--surface); border: 1px solid var(--hairline);
|
||||||
|
border-radius: var(--radius); padding: 18px 18px 16px;
|
||||||
|
position: relative; overflow: hidden;
|
||||||
|
}
|
||||||
|
.stat::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent-deep); opacity: 0.7; }
|
||||||
|
.stat b.delta { display: block; font-family: var(--font-display); font-size: 1.55rem; font-weight: 600; letter-spacing: -0.02em; color: var(--text); }
|
||||||
|
.stat b.delta .g { color: var(--gain); }
|
||||||
|
.stat .lbl { display: block; font-size: 0.8rem; color: var(--text-3); margin-top: 4px; letter-spacing: 0.02em; }
|
||||||
|
.stat .pair { font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-2); margin-top: 2px; }
|
||||||
|
.stat .pair .from { color: var(--text-3); }
|
||||||
|
|
||||||
|
/* ---------- Sections ---------- */
|
||||||
|
section { padding: 60px 0 8px; scroll-margin-top: 74px; }
|
||||||
|
.sec-head { margin-bottom: 26px; }
|
||||||
|
.eyebrow { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.14em; color: var(--accent); text-transform: uppercase; display: flex; align-items: center; gap: 10px; margin: 0 0 10px; }
|
||||||
|
.eyebrow::before { content: "["; color: var(--text-3); }
|
||||||
|
.eyebrow::after { content: "]"; color: var(--text-3); }
|
||||||
|
h2 { font-family: var(--font-display); font-weight: 600; font-size: 1.6rem; margin: 0 0 8px; letter-spacing: -0.01em; text-wrap: balance; }
|
||||||
|
.sec-lead { color: var(--text-2); max-width: 74ch; margin: 0 0 20px; font-size: 0.97rem; }
|
||||||
|
.sec-lead a code { text-decoration: none; }
|
||||||
|
|
||||||
|
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 16px; }
|
||||||
|
.card h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; margin: 0 0 6px; letter-spacing: 0.01em; }
|
||||||
|
.card .card-sub { color: var(--text-3); font-size: 0.85rem; margin: 0 0 16px; }
|
||||||
|
|
||||||
|
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
|
||||||
|
|
||||||
|
.flow { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 20px; }
|
||||||
|
.flow-step {
|
||||||
|
font-family: var(--font-mono); font-size: 0.78rem;
|
||||||
|
border: 1px solid var(--hairline); background: var(--bg-soft);
|
||||||
|
border-radius: 7px; padding: 6px 12px; color: var(--text-2);
|
||||||
|
display: inline-flex; align-items: center; gap: 8px;
|
||||||
|
}
|
||||||
|
.flow-step b { color: var(--text); font-weight: 500; }
|
||||||
|
.flow-step.seq { border-color: var(--hairline-strong); }
|
||||||
|
|
||||||
|
/* ---------- Tables ---------- */
|
||||||
|
.tblwrap { overflow-x: auto; border: 1px solid var(--hairline); border-radius: var(--radius); margin-bottom: 18px; background: var(--surface); }
|
||||||
|
table { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 0.9rem; }
|
||||||
|
th {
|
||||||
|
font-family: var(--font-mono); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em;
|
||||||
|
color: var(--text-3); text-align: left; padding: 12px 16px;
|
||||||
|
border-bottom: 1px solid var(--hairline-strong); background: var(--bg-soft); white-space: nowrap;
|
||||||
|
}
|
||||||
|
td { padding: 12px 16px; border-bottom: 1px solid var(--hairline); vertical-align: top; }
|
||||||
|
tbody tr:last-child td { border-bottom: none; }
|
||||||
|
tbody tr:hover td { background: rgba(111,183,255,0.03); }
|
||||||
|
td .cell { display: block; }
|
||||||
|
td .cell-sub { display: block; color: var(--text-3); font-size: 0.8rem; margin-top: 2px; }
|
||||||
|
tr.row-danger td { background: linear-gradient(90deg, rgba(255,122,134,0.05), transparent 45%); }
|
||||||
|
|
||||||
|
.chk { font-weight: 600; white-space: nowrap; }
|
||||||
|
.chk.ok { color: var(--gain); }
|
||||||
|
.chk.warn { color: var(--warn); }
|
||||||
|
.chk.off { color: var(--text-3); }
|
||||||
|
|
||||||
|
.pill {
|
||||||
|
display: inline-block; font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500;
|
||||||
|
border-radius: 6px; padding: 2px 9px; letter-spacing: 0.02em; white-space: nowrap;
|
||||||
|
}
|
||||||
|
.pill.p1 { color: var(--bad); background: var(--bad-bg); border: 1px solid rgba(255,122,134,0.3); }
|
||||||
|
.pill.p2 { color: var(--warn); background: var(--warn-bg); border: 1px solid rgba(242,190,92,0.3); }
|
||||||
|
.pill.p3 { color: var(--text-2); background: rgba(169,183,204,0.08); border: 1px solid var(--hairline-strong); }
|
||||||
|
.pill.crit { color: var(--bad); background: var(--bad-bg); border: 1px solid rgba(255,122,134,0.3); }
|
||||||
|
.pill.req { color: var(--warn); background: var(--warn-bg); border: 1px solid rgba(242,190,92,0.3); }
|
||||||
|
.pill.okp { color: var(--gain); background: var(--gain-bg); border: 1px solid rgba(70,224,160,0.3); }
|
||||||
|
.pill.grade { color: var(--text); background: var(--bg-soft); border: 1px solid var(--hairline-strong); }
|
||||||
|
|
||||||
|
.tag-gain { color: var(--gain); }
|
||||||
|
.tag-warn { color: var(--warn); }
|
||||||
|
|
||||||
|
/* ---------- Before / after delta rows ---------- */
|
||||||
|
.delta-row { display: grid; grid-template-columns: 220px 1fr 1fr 130px; gap: 14px; align-items: center; padding: 13px 0; border-bottom: 1px solid var(--hairline); }
|
||||||
|
.delta-row:last-child { border-bottom: none; }
|
||||||
|
.delta-row .k { font-weight: 500; color: var(--text); font-size: 0.93rem; }
|
||||||
|
.delta-row .k small { display: block; color: var(--text-3); font-size: 0.78rem; font-weight: 400; }
|
||||||
|
.delta-val { font-family: var(--font-mono); font-size: 0.92rem; }
|
||||||
|
.delta-val.before { color: var(--text-3); }
|
||||||
|
.delta-val.after { color: var(--text); font-weight: 600; }
|
||||||
|
.delta-chip { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; text-align: right; color: var(--gain); white-space: nowrap; }
|
||||||
|
|
||||||
|
.bar-track { height: 8px; border-radius: 99px; background: var(--bg-soft); border: 1px solid var(--hairline); overflow: hidden; display: flex; margin-top: 6px; }
|
||||||
|
.bar-before { background: rgba(111,183,255,0.35); height: 100%; }
|
||||||
|
.bar-gain { background: linear-gradient(90deg, rgba(70,224,160,0.55), var(--gain)); height: 100%; }
|
||||||
|
.bar-target { background: repeating-linear-gradient(90deg, transparent 0 4px, rgba(233,238,247,0.25) 4px 6px); height: 100%; }
|
||||||
|
|
||||||
|
.legend { display: flex; gap: 18px; flex-wrap: wrap; margin: 12px 2px 0; font-size: 0.8rem; color: var(--text-2); }
|
||||||
|
.legend span { display: inline-flex; align-items: center; gap: 7px; }
|
||||||
|
.legend i { width: 16px; height: 8px; border-radius: 3px; display: inline-block; }
|
||||||
|
.legend .i-b { background: rgba(111,183,255,0.35); }
|
||||||
|
.legend .i-g { background: var(--gain); }
|
||||||
|
.legend .i-t { background: repeating-linear-gradient(90deg, transparent 0 3px, rgba(233,238,247,0.3) 3px 5px); }
|
||||||
|
|
||||||
|
/* ---------- Finding list ---------- */
|
||||||
|
.find-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-bottom: 20px; }
|
||||||
|
.find { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 16px 18px; }
|
||||||
|
.find .fid { font-family: var(--font-mono); font-size: 0.76rem; color: var(--text-3); display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
|
||||||
|
.find .fid::before { content: "▸"; color: var(--accent); }
|
||||||
|
.find h4 { font-size: 0.95rem; margin: 0 0 5px; font-weight: 600; color: var(--text); }
|
||||||
|
.find p { margin: 0; color: var(--text-2); font-size: 0.86rem; }
|
||||||
|
.find .loc { font-family: var(--font-mono); font-size: 0.74rem; color: var(--text-3); margin-top: 8px; display: block; }
|
||||||
|
|
||||||
|
.grade-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 18px; }
|
||||||
|
.grade-cell { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--radius); padding: 13px 14px; text-align: center; }
|
||||||
|
.grade-cell .gv { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; display: block; }
|
||||||
|
.grade-cell .gl { font-size: 0.74rem; color: var(--text-3); display: block; margin-top: 3px; }
|
||||||
|
|
||||||
|
.quote-verdict { border-left: 3px solid var(--warn); background: var(--warn-bg); padding: 16px 18px; border-radius: 0 var(--radius) var(--radius) 0; margin-bottom: 22px; }
|
||||||
|
.quote-verdict .qv-label { font-family: var(--font-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--warn); margin-bottom: 4px; }
|
||||||
|
.quote-verdict p { margin: 0; color: var(--text); font-size: 0.95rem; }
|
||||||
|
|
||||||
|
/* ---------- Quiz ---------- */
|
||||||
|
.quiz-shell { border: 1px solid var(--hairline-strong); border-radius: 12px; overflow: hidden; background: var(--surface); margin-bottom: 40px; }
|
||||||
|
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 24px; border-bottom: 1px solid var(--hairline); background: var(--bg-soft); flex-wrap: wrap; }
|
||||||
|
.quiz-head h3 { margin: 0; font-family: var(--font-display); font-size: 1.05rem; font-weight: 600; }
|
||||||
|
.quiz-progress { font-family: var(--font-mono); font-size: 0.82rem; color: var(--text-2); }
|
||||||
|
.quiz-progress b { color: var(--text); font-weight: 600; }
|
||||||
|
.quiz-body { padding: 10px 24px 24px; }
|
||||||
|
.q-item { padding: 22px 0; border-bottom: 1px solid var(--hairline); }
|
||||||
|
.q-item:last-of-type { border-bottom: none; }
|
||||||
|
.q-no { font-family: var(--font-mono); font-size: 0.72rem; color: var(--accent); letter-spacing: 0.06em; margin-bottom: 6px; }
|
||||||
|
.q-stem { font-weight: 600; font-size: 0.97rem; margin: 0 0 12px; }
|
||||||
|
.q-opts { display: grid; gap: 8px; }
|
||||||
|
.q-opt {
|
||||||
|
display: flex; gap: 12px; align-items: flex-start;
|
||||||
|
width: 100%; text-align: left; cursor: pointer;
|
||||||
|
font-family: var(--font-body); font-size: 0.9rem; color: var(--text-2);
|
||||||
|
background: var(--bg-soft); border: 1px solid var(--hairline); border-radius: 8px;
|
||||||
|
padding: 10px 14px; transition: border-color 120ms, background 120ms;
|
||||||
|
}
|
||||||
|
.q-opt:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
|
||||||
|
.q-opt .opt-key { font-family: var(--font-mono); font-weight: 600; color: var(--text-3); flex: 0 0 auto; }
|
||||||
|
.q-opt.correct { background: var(--gain-bg); border-color: var(--gain); color: var(--text); }
|
||||||
|
.q-opt.correct .opt-key { color: var(--gain); }
|
||||||
|
.q-opt.wrong { background: var(--bad-bg); border-color: var(--bad); color: var(--text); }
|
||||||
|
.q-opt.wrong .opt-key { color: var(--bad); }
|
||||||
|
.q-opt.dim { opacity: 0.5; }
|
||||||
|
.q-opt:disabled { cursor: default; }
|
||||||
|
.q-feedback { margin-top: 10px; font-size: 0.86rem; border-left: 3px solid var(--hairline-strong); padding: 8px 14px; background: var(--bg-soft); border-radius: 0 6px 6px 0; color: var(--text-2); }
|
||||||
|
.q-feedback b { color: var(--text); }
|
||||||
|
.feedback-hint { margin-top: 10px; font-size: 0.84rem; color: var(--text-3); font-style: italic; }
|
||||||
|
|
||||||
|
.quiz-verdict { margin: 18px 0 6px; }
|
||||||
|
.verdict-box {
|
||||||
|
display: none; padding: 20px 24px; border-radius: var(--radius); border: 1px solid var(--hairline-strong);
|
||||||
|
background: var(--bg-soft);
|
||||||
|
}
|
||||||
|
.verdict-box.show { display: block; }
|
||||||
|
.verdict-box .v-title { font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; margin: 0 0 6px; }
|
||||||
|
.verdict-box.pass .v-title { color: var(--gain); }
|
||||||
|
.verdict-box.fail .v-title { color: var(--bad); }
|
||||||
|
.verdict-box p { margin: 0 0 16px; color: var(--text-2); font-size: 0.92rem; }
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
font-family: var(--font-display); font-weight: 600; font-size: 0.9rem; letter-spacing: 0.02em;
|
||||||
|
border: 1px solid var(--accent); color: #0B1018; background: var(--accent);
|
||||||
|
padding: 10px 22px; border-radius: 8px; cursor: pointer; transition: filter 120ms;
|
||||||
|
}
|
||||||
|
.btn:hover { filter: brightness(1.08); }
|
||||||
|
.btn:disabled { border-color: var(--hairline-strong); background: var(--surface-2); color: var(--text-3); cursor: not-allowed; }
|
||||||
|
.btn.ghost { background: transparent; color: var(--accent); }
|
||||||
|
|
||||||
|
footer { border-top: 1px solid var(--hairline); padding: 34px 0 46px; margin-top: 40px; }
|
||||||
|
.foot-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
|
||||||
|
.foot-col .fh { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-3); margin-bottom: 10px; }
|
||||||
|
.foot-col ul { list-style: none; margin: 0; padding: 0; }
|
||||||
|
.foot-col li { font-size: 0.85rem; color: var(--text-2); margin-bottom: 7px; }
|
||||||
|
.foot-note { margin-top: 22px; font-size: 0.78rem; color: var(--text-3); font-family: var(--font-mono); }
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.stats { grid-template-columns: repeat(2, 1fr); }
|
||||||
|
.grid-2, .find-grid { grid-template-columns: 1fr; }
|
||||||
|
.grade-grid { grid-template-columns: repeat(3, 1fr); }
|
||||||
|
.delta-row { grid-template-columns: 1fr; gap: 6px; }
|
||||||
|
.delta-chip { text-align: left; }
|
||||||
|
.foot-grid { grid-template-columns: 1fr; }
|
||||||
|
section { padding-top: 44px; }
|
||||||
|
.hero { padding-top: 52px; }
|
||||||
|
}
|
||||||
|
@media (max-width: 560px) {
|
||||||
|
.stats { grid-template-columns: 1fr 1fr; }
|
||||||
|
.container { padding: 0 18px; }
|
||||||
|
.quiz-body { padding: 6px 16px 18px; }
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
html { scroll-behavior: auto; }
|
||||||
|
* { transition: none !important; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="topbar">
|
||||||
|
<div class="topbar-inner">
|
||||||
|
<div class="brand"><span class="brand-dot"></span>GHBOT · v2.0</div>
|
||||||
|
<nav class="nav" aria-label="目录">
|
||||||
|
<a href="#context">CTX</a>
|
||||||
|
<a href="#changes">CHANGES</a>
|
||||||
|
<a href="#metrics">METRICS</a>
|
||||||
|
<a href="#audit">AUDIT</a>
|
||||||
|
<a href="#review">REVIEW</a>
|
||||||
|
<a href="#quiz">QUIZ</a>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<header class="hero">
|
||||||
|
<div class="container">
|
||||||
|
<p class="kicker">ghbot<em>/</em>iteration report<em>/</em>v1.2.0 → v2.0</p>
|
||||||
|
<h1>ghbot v2.0 迭代报告</h1>
|
||||||
|
<p class="hero-sub">
|
||||||
|
ghbot 是基于 GitHub Actions 的机器人,用 goose CLI(OpenAI 兼容 chat API)完成
|
||||||
|
<strong>PR 审查、Issue/PR 分类、@bot 对话、冲突修复</strong>,并可选运行只读 webhook 长驻模式。
|
||||||
|
本次 v2.0 半程迭代按《下一步改进指南》M0–M7 推进,第一阶段落地
|
||||||
|
<strong>M0 测试加固、M1 可靠性、M2 可观测性</strong>三个方向,全部门禁通过、无 P0 阻塞项。
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="meta-row">
|
||||||
|
<span class="meta-chip">基准版本 <b>v1.2.0</b> · commit <b>db53296</b></span>
|
||||||
|
<span class="meta-chip">当前 <b>v2.0 半程</b></span>
|
||||||
|
<span class="meta-chip">阶段 <b>M0 · M1 · M2</b></span>
|
||||||
|
<span class="meta-chip">审计日期 <b>2026-08-24</b></span>
|
||||||
|
<span class="meta-chip">覆盖范围 <b>src 35 + test 48</b></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="gate-strip" role="list" aria-label="门禁状态">
|
||||||
|
<span class="gate" role="listitem"><span class="ok">✓</span><span class="gate-label">typecheck</span><span class="gate-result">PASS</span></span>
|
||||||
|
<span class="gate" role="listitem"><span class="ok">✓</span><span class="gate-label">lint</span><span class="gate-result">0 error</span></span>
|
||||||
|
<span class="gate" role="listitem"><span class="ok">✓</span><span class="gate-label">format:check</span><span class="gate-result">Prettier OK</span></span>
|
||||||
|
<span class="gate" role="listitem"><span class="ok">✓</span><span class="gate-label">test</span><span class="gate-result">321 / 321</span></span>
|
||||||
|
<span class="gate" role="listitem"><span class="ok">✓</span><span class="gate-label">build</span><span class="gate-result">dist/ OK</span></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="stats">
|
||||||
|
<div class="stat">
|
||||||
|
<b class="delta num"><span class="g">+170</span></b>
|
||||||
|
<span class="pair">151 <span class="from">→</span> 321</span>
|
||||||
|
<span class="lbl">测试用例 · ×2.1</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat">
|
||||||
|
<b class="delta num"><span class="g">+12</span></b>
|
||||||
|
<span class="pair">36 <span class="from">→</span> 48</span>
|
||||||
|
<span class="lbl">测试文件</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat">
|
||||||
|
<b class="delta num">66.20<span class="g">%</span></b>
|
||||||
|
<span class="pair">lines <span class="from">+4.79pp</span></span>
|
||||||
|
<span class="lbl">行覆盖率</span>
|
||||||
|
</div>
|
||||||
|
<div class="stat">
|
||||||
|
<b class="delta num">87.36<span class="g">%</span></b>
|
||||||
|
<span class="pair">branches <span class="from">+4.38pp</span></span>
|
||||||
|
<span class="lbl">分支覆盖率</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<main class="container">
|
||||||
|
|
||||||
|
<!-- ================= Context ================= -->
|
||||||
|
<section id="context">
|
||||||
|
<div class="sec-head">
|
||||||
|
<p class="eyebrow">CTX</p>
|
||||||
|
<h2>项目与本次迭代范围</h2>
|
||||||
|
<p class="sec-lead">处理不受信任的 PR 内容与多种凭据,凭据隔离是硬性红线:GitHub token、App 私钥、R2 与真实 goose API key 绝不进入 goose 容器、PR 快照或 git 子进程环境。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>系统能力地图</h3>
|
||||||
|
<p class="card-sub">ghbot 在生产中同时承担五个链路,本次迭代未改变其对外行为,仅加固内部质量。</p>
|
||||||
|
<div class="flow">
|
||||||
|
<span class="flow-step">1 <b>PR 审查</b> review / change / comment / result</span>
|
||||||
|
<span class="flow-step">2 <b>Issue/PR 分类</b> 标签 + 两阶段重复检测</span>
|
||||||
|
<span class="flow-step">3 <b>@bot 对话</b> 一次性 Docker 容器 + 脱敏快照</span>
|
||||||
|
<span class="flow-step">4 <b>冲突修复</b> safeToCommit=true 后才推送</span>
|
||||||
|
<span class="flow-step">5 <b>Webhook 模式</b> 可选 · 默认关闭 · 只读</span>
|
||||||
|
</div>
|
||||||
|
<p style="margin:0;color:var(--text-2);font-size:0.9rem">
|
||||||
|
合并策略由 <code>REVIEW_POLICY</code> 控制(默认 <code>allow</code>),<code>AUTO_MERGE</code> 保持 opt-in;
|
||||||
|
事件路由在 v1.2.0 已提取为 <code>src/actions/router.ts</code> 的 <code>EventRouter</code>,review / triage / chat / conflict 四类流程在此分发。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>v2.0 迭代覆盖了什么</h3>
|
||||||
|
<p class="card-sub">范围:M0 测试基建与覆盖率、M1 可靠性组件、M2 可观测性组件。M3 大文件拆分与 M4–M7 后续里程碑留待下一阶段。</p>
|
||||||
|
<div class="grid-2">
|
||||||
|
<div>
|
||||||
|
<p style="font-family:var(--font-mono);font-size:0.78rem;margin:0 0 10px;color:var(--text-3)">已落地方向</p>
|
||||||
|
<ul style="margin:0;padding-left:18px;color:var(--text-2);font-size:0.9rem">
|
||||||
|
<li>M0:7 个模块覆盖率补测,新增 10 个专项测试文件</li>
|
||||||
|
<li>M1:<code>withRetry</code> 智能重试、<code>MergeGuard</code>、<code>failureMessages</code></li>
|
||||||
|
<li>M2:<code>MetricsCollector</code> 指标收集器</li>
|
||||||
|
<li>测试总数 151 → <b>321</b>,行覆盖率 61.41% → 66.20%</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p style="font-family:var(--font-mono);font-size:0.78rem;margin:0 0 10px;color:var(--text-3)">依赖前置、暂缓方向</p>
|
||||||
|
<ul style="margin:0;padding-left:18px;color:var(--text-2);font-size:0.9rem">
|
||||||
|
<li>M0-8 集成测试:需 testcontainers / MinIO 基础设施</li>
|
||||||
|
<li>M1-2 陈旧检测、M2-1 全链路日志:待 <code>processor.ts</code> 拆分</li>
|
||||||
|
<li>M3 大文件拆分:<code>processor.ts</code> 1736 行 / <code>conflictResolver.ts</code> 1250 行</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ================= Changes ================= -->
|
||||||
|
<section id="changes">
|
||||||
|
<div class="sec-head">
|
||||||
|
<p class="eyebrow">CHANGES</p>
|
||||||
|
<h2>本轮落地内容(M0 / M1 / M2)</h2>
|
||||||
|
<p class="sec-lead">11 个里程碑项落地:其中 8 项完整接入并验证,3 个新模块已交付(含 100% 测试)但尚未接线到生产路径——这是审计与 critical review 的共同关注点。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table>
|
||||||
|
<caption style="font-family:var(--font-mono);font-size:0.72rem;text-align:left;color:var(--text-3);padding:10px 16px 2px">M0 · 测试加固</caption>
|
||||||
|
<thead>
|
||||||
|
<tr><th>里程碑</th><th>目标模块</th><th>变化</th><th style="text-align:right">状态</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td class="mono">M0-1</td><td><code>repository/knowledge.ts</code> normalizeKnowledge</td><td>CRLF/LF 行尾归一,缓存校验与快照写入一致</td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M0-2</td><td><code>review/gooseReviewer.ts</code></td><td>覆盖 26.57% → <b class="num">97.35%</b></td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M0-3</td><td><code>storage/cacheStore.ts</code>(R2)</td><td>覆盖 49.01% → <b class="num">100%</b></td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M0-4</td><td><code>triage/processor.ts</code></td><td>覆盖 56.77% → <b class="num">63.19%</b></td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M0-5</td><td><code>webhook/processor.ts</code></td><td>覆盖 63.90% → <b class="num">72.39%</b></td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M0-6</td><td><code>review/conflictResolver.ts</code></td><td>覆盖 56.56% → <b class="num">57.52%</b></td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M0-7</td><td><code>review/processor.ts</code></td><td>覆盖 49.08% → <b class="num">49.42%</b></td><td style="text-align:right"><span class="chk ok">✓ 落地</span></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table>
|
||||||
|
<caption style="font-family:var(--font-mono);font-size:0.72rem;text-align:left;color:var(--text-3);padding:10px 16px 2px">M1 · 可靠性</caption>
|
||||||
|
<thead>
|
||||||
|
<tr><th>里程碑</th><th>组件</th><th>内容</th><th style="text-align:right">状态</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td class="mono">M1-1</td><td><code>src/retry.ts</code> withRetry</td><td>指数退避 + 抖动 + 4xx 可重试分类 + 总超时兜底</td><td style="text-align:right"><span class="chk ok">✓ 落地接入</span></td></tr>
|
||||||
|
<tr><td class="mono">M1-3</td><td><code>src/review/merge-guard.ts</code></td><td>合并防重入锁,<b>100% 测试覆盖</b></td><td style="text-align:right"><span class="chk warn">◇ 已建未接入</span></td></tr>
|
||||||
|
<tr><td class="mono">M1-4</td><td><code>src/ai/failureMessages.ts</code></td><td><code>categorizeFailure</code> / <code>formatFailureMessage</code>,失败分类与告警文案,<b>100% 覆盖</b></td><td style="text-align:right"><span class="chk warn">◇ 已建未接入</span></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table>
|
||||||
|
<caption style="font-family:var(--font-mono);font-size:0.72rem;text-align:left;color:var(--text-3);padding:10px 16px 2px">M2 · 可观测性</caption>
|
||||||
|
<thead>
|
||||||
|
<tr><th>里程碑</th><th>组件</th><th>内容</th><th style="text-align:right">状态</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td class="mono">M2-2</td><td><code>src/metrics/collector.ts</code></td><td><code>recordReviewDuration</code> / <code>recordGooseCall</code> / <code>recordConflictResolution</code> / <code>recordMergeAttempt</code>,<b>100% 覆盖</b></td><td style="text-align:right"><span class="chk warn">◇ 已建未接入</span></td></tr>
|
||||||
|
<tr><td class="mono">M2-1</td><td>全链路日志贯穿</td><td>需 <code>processor.ts</code> 拆分后接入</td><td style="text-align:right"><span class="chk off">○ 未落地</span></td></tr>
|
||||||
|
<tr><td class="mono">M1-2</td><td>陈旧检测(stale detection)</td><td>LLM 运行期间 head 变化时丢弃结果、浪费完整调用;需处理器拆分</td><td style="text-align:right"><span class="chk off">○ 未落地</span></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card" style="border-color:var(--hairline-strong)">
|
||||||
|
<h3>新增专项测试文件(10 个 / 125 条用例)</h3>
|
||||||
|
<p class="card-sub">其余 +45 条用例来自既有测试文件的增强。审计复核:新模块全部 100% 覆盖,核心大模块仍有缺口。</p>
|
||||||
|
<div class="tblwrap" style="margin-bottom:0;border:none">
|
||||||
|
<table style="min-width:560px">
|
||||||
|
<thead>
|
||||||
|
<tr><th>测试文件</th><th style="text-align:right">用例数</th><th style="text-align:right">覆盖</th><th style="text-align:right">评价</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td><code>test/goose-reviewer.test.ts</code></td><td class="num" style="text-align:right">11</td><td class="num" style="text-align:right">97.35%</td><td style="text-align:right"><span class="chk ok">✓ 达标</span></td></tr>
|
||||||
|
<tr><td><code>test/r2-storage.test.ts</code></td><td class="num" style="text-align:right">22</td><td class="num" style="text-align:right">100%</td><td style="text-align:right"><span class="chk ok">✓ 达标</span></td></tr>
|
||||||
|
<tr><td><code>test/webhook-processor-extra.test.ts</code></td><td class="num" style="text-align:right">35</td><td class="num" style="text-align:right">72.39%</td><td style="text-align:right"><span class="pill p2" style="text-align:center">中</span></td></tr>
|
||||||
|
<tr><td><code>test/conflict-resolver-extra.test.ts</code></td><td class="num" style="text-align:right">12</td><td class="num" style="text-align:right">57.52%</td><td style="text-align:right"><span class="pill p1" style="text-align:center">待补</span></td></tr>
|
||||||
|
<tr><td><code>test/triage-processor-extra.test.ts</code></td><td class="num" style="text-align:right">11</td><td class="num" style="text-align:right">—</td><td style="text-align:right"><span class="chk ok">✓ 已覆盖</span></td></tr>
|
||||||
|
<tr><td><code>test/merge-guard.test.ts</code></td><td class="num" style="text-align:right">5</td><td class="num" style="text-align:right">100%</td><td style="text-align:right"><span class="chk ok">✓ 达标</span></td></tr>
|
||||||
|
<tr><td><code>test/metrics-collector.test.ts</code></td><td class="num" style="text-align:right">9</td><td class="num" style="text-align:right">100%</td><td style="text-align:right"><span class="chk ok">✓ 达标</span></td></tr>
|
||||||
|
<tr><td><code>test/failure-messages.test.ts</code></td><td class="num" style="text-align:right">8</td><td class="num" style="text-align:right">100%</td><td style="text-align:right"><span class="chk ok">✓ 达标</span></td></tr>
|
||||||
|
<tr><td><code>test/retry-extra.test.ts</code></td><td class="num" style="text-align:right">5</td><td class="num" style="text-align:right">100%</td><td style="text-align:right"><span class="chk ok">✓ 达标</span></td></tr>
|
||||||
|
<tr><td><code>test/review-processor-extra.test.ts</code></td><td class="num" style="text-align:right">7</td><td class="num" style="text-align:right">49.42%</td><td style="text-align:right"><span class="pill p1" style="text-align:center">待补</span></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ================= Metrics ================= -->
|
||||||
|
<section id="metrics">
|
||||||
|
<div class="sec-head">
|
||||||
|
<p class="eyebrow">METRICS</p>
|
||||||
|
<h2>指标对照:v1.2.0 → v2.0</h2>
|
||||||
|
<p class="sec-lead">测试规模翻倍以上,覆盖率各分项稳步上升;核心大模块仍低于 80% 目标,是下一阶段主攻方向。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card" style="padding:18px 24px 12px">
|
||||||
|
<div class="delta-row">
|
||||||
|
<div class="k">测试文件<small>test/*.test.ts</small></div>
|
||||||
|
<div class="delta-val before num">36</div>
|
||||||
|
<div class="delta-val after num">48</div>
|
||||||
|
<div class="delta-chip num">+12</div>
|
||||||
|
</div>
|
||||||
|
<div class="delta-row">
|
||||||
|
<div class="k">测试用例<small>node:test + tsx</small></div>
|
||||||
|
<div class="delta-val before num">151</div>
|
||||||
|
<div class="delta-val after num">321</div>
|
||||||
|
<div class="delta-chip num">+170 · ×2.1</div>
|
||||||
|
</div>
|
||||||
|
<div class="delta-row">
|
||||||
|
<div class="k">行覆盖率 lines<small>全局</small></div>
|
||||||
|
<div class="delta-val before num">61.41%</div>
|
||||||
|
<div class="delta-val after num">66.20%</div>
|
||||||
|
<div class="delta-chip num">+4.79pp</div>
|
||||||
|
</div>
|
||||||
|
<div class="delta-row">
|
||||||
|
<div class="k">分支覆盖率 branches<small>全局</small></div>
|
||||||
|
<div class="delta-val before num">82.98%</div>
|
||||||
|
<div class="delta-val after num">87.36%</div>
|
||||||
|
<div class="delta-chip num">+4.38pp</div>
|
||||||
|
</div>
|
||||||
|
<div class="delta-row">
|
||||||
|
<div class="k">函数覆盖率 functions<small>全局</small></div>
|
||||||
|
<div class="delta-val before num">69.97%</div>
|
||||||
|
<div class="delta-val after num">75.57%</div>
|
||||||
|
<div class="delta-chip num">+5.60pp</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="delta-row">
|
||||||
|
<div class="k">覆盖率趋势<small>虚线为 80% 目标线</small></div>
|
||||||
|
<div style="grid-column:2 / span 3">
|
||||||
|
<div class="bar-track" role="img" aria-label="行覆盖率 61.41% 提升至 66.20%,目标 80%">
|
||||||
|
<span class="bar-before" style="width:76.76%"></span>
|
||||||
|
<span class="bar-gain" style="width:5.99%"></span>
|
||||||
|
<span class="bar-target" style="width:17.25%"></span>
|
||||||
|
</div>
|
||||||
|
<div class="legend">
|
||||||
|
<span><i class="i-b"></i>基线 61.41%</span>
|
||||||
|
<span><i class="i-g"></i>本轮 +4.79pp</span>
|
||||||
|
<span><i class="i-t"></i>距 80% 目标缺口 13.80pp</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table>
|
||||||
|
<caption style="font-family:var(--font-mono);font-size:0.72rem;text-align:left;color:var(--text-3);padding:10px 16px 2px">关键模块覆盖现状(审计 7.1,目标 ≥80%)</caption>
|
||||||
|
<thead>
|
||||||
|
<tr><th>模块</th><th style="text-align:right">当前 lines</th><th style="text-align:right">目标</th><th style="text-align:right">缺口</th><th>主要待补路径</th></tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="row-danger"><td><code>review/processor.ts</code>(1736 行)</td><td class="num" style="text-align:right">49.42%</td><td class="num" style="text-align:right">80%</td><td class="num tag-danger" style="text-align:right;color:var(--bad)">-30.58pp</td><td>主流程、旧审查清理、合并/审批、调度</td></tr>
|
||||||
|
<tr class="row-danger"><td><code>review/conflictResolver.ts</code>(1250 行)</td><td class="num" style="text-align:right">57.52%</td><td class="num" style="text-align:right">80%</td><td class="num" style="text-align:right;color:var(--bad)">-22.48pp</td><td>冲突解析主流程、验证运行、命令执行</td></tr>
|
||||||
|
<tr><td><code>triage/processor.ts</code></td><td class="num" style="text-align:right">63.19%</td><td class="num" style="text-align:right">80%</td><td class="num" style="text-align:right;color:var(--warn)">-16.81pp</td><td>两阶段详查、标签创建、重复评论</td></tr>
|
||||||
|
<tr><td><code>webhook/processor.ts</code></td><td class="num" style="text-align:right">72.39%</td><td class="num" style="text-align:right">80%</td><td class="num" style="text-align:right;color:var(--warn)">-7.61pp</td><td>提及主流程、上下文加载、组织成员分支</td></tr>
|
||||||
|
<tr><td><code>webhook/server.ts</code></td><td class="num" style="text-align:right">75.87%</td><td class="num" style="text-align:right">80%</td><td class="num" style="text-align:right;color:var(--warn)">-4.13pp</td><td>队列满 503、body 超时 413、启动流程</td></tr>
|
||||||
|
<tr><td><code>storage/cacheStore.ts</code></td><td class="num" style="text-align:right">95.73%</td><td class="num" style="text-align:right">95%</td><td class="num" style="text-align:right;color:var(--gain)">达标</td><td>—</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ================= Audit ================= -->
|
||||||
|
<section id="audit">
|
||||||
|
<div class="sec-head">
|
||||||
|
<p class="eyebrow">AUDIT</p>
|
||||||
|
<h2>审计发现(audit-v2-final)</h2>
|
||||||
|
<p class="sec-lead">最终审计覆盖全部 src/ 35 文件、test/ 48 文件、配置、文档与工作流。结论:无 P0 阻塞,整体安全评级 <b style="color:var(--text)">A-</b>;8 项 P1、10 项 P2、10 项 P3。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="find-grid" style="margin-bottom:22px">
|
||||||
|
<div class="find"><span class="fid">P0 阻塞项</span><h4>0</h4><p>构建、类型检查、测试全部通过,无阻塞项。</p></div>
|
||||||
|
<div class="find"><span class="fid">安全评级</span><h4 style="color:var(--gain)">A-</h4><p>凭据隔离 A · 注入防护 A · 快照脱敏 B+ · 密钥脱敏 A · 子进程安全 B。</p></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3 style="font-family:var(--font-display);font-size:1.05rem;margin:0 0 12px">P1 · 高优先级(合并前应处理)</h3>
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table style="min-width:760px">
|
||||||
|
<thead><tr><th>ID</th><th>问题</th><th>位置</th><th>说明</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="row-danger"><td><span class="pill p1">P1-01</span></td><td><code>MergeGuard</code> 未接入生产</td><td><code>review/merge-guard.ts</code></td><td>有定义有测试,<code>maybeMergePullRequest</code> 未调用,无实际防重入</td></tr>
|
||||||
|
<tr class="row-danger"><td><span class="pill p1">P1-02</span></td><td><code>failureMessages</code> 未接入</td><td><code>ai/failureMessages.ts</code></td><td>无任何模块 import,告警文案能力未生效</td></tr>
|
||||||
|
<tr class="row-danger"><td><span class="pill p1">P1-03</span></td><td><code>MetricsCollector</code> 未接入</td><td><code>metrics/collector.ts</code></td><td>Actions 模式指标收集完全未启用</td></tr>
|
||||||
|
<tr><td><span class="pill p1">P1-04</span></td><td>大文件:<code>processor.ts</code> 1736 行</td><td><code>review/processor.ts</code></td><td>远超 800 行上限,7+ 职责混排</td></tr>
|
||||||
|
<tr><td><span class="pill p1">P1-05</span></td><td>大文件:<code>conflictResolver.ts</code> 1250 行</td><td><code>review/conflictResolver.ts</code></td><td>5+ 独立职责,<b>未落地</b>到下一阶段</td></tr>
|
||||||
|
<tr><td><span class="pill p1">P1-06</span></td><td>覆盖率不足 80% 目标</td><td>全局</td><td>lines 66.20%;<code>processor</code> 49.42%、<code>triage</code> 63.19%</td></tr>
|
||||||
|
<tr><td><span class="pill p1">P1-07</span></td><td><code>waitForMergeable</code> 无总超时</td><td><code>processor.ts:1411-1432</code></td><td>5 次重试 ×1s 无兜底,mergeable 可能无限返回 null</td></tr>
|
||||||
|
<tr><td><span class="pill p1">P1-08</span></td><td>审查运行期间无陈旧检测</td><td><code>processor.ts:98-105</code></td><td>LLM 期间 head 变化直接丢弃结果,浪费完整调用</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h3 style="font-family:var(--font-display);font-size:1.05rem;margin:26px 0 12px">P2 · 中优先级(抽样)</h3>
|
||||||
|
<div class="find-grid">
|
||||||
|
<div class="find"><span class="fid">P2-01</span><h4>快照排除清单不完整</h4><p>缺 <code>.npmrc</code>、<code>terraform/</code>、<code>kube/</code>、<code>docker/</code> 配置,可能含注册表令牌或云凭据。</p><span class="loc">security/sanitization.ts</span></div>
|
||||||
|
<div class="find"><span class="fid">P2-02</span><h4>Webhook 队列无持久化</h4><p>进程重启丢失全部待处理任务。</p><span class="loc">webhook/server.ts</span></div>
|
||||||
|
<div class="find"><span class="fid">P2-03/04</span><h4>两处分页缺失</h4><p><code>processScheduledPendingMerges</code> 与 <code>triage listCandidates</code> 均只取第一页 100 条。</p><span class="loc">review/processor.ts · triage/processor.ts</span></div>
|
||||||
|
<div class="find"><span class="fid">P2-08/09</span><h4>凭据进入子进程环境</h4><p><code>OPENAI_API_KEY</code> 暴露到 goose 子进程 env;<code>GHBOT_GIT_TOKEN</code> 经 askpass 环境变量传递。</p><span class="loc">ai/gooseCli.ts · review/conflictResolver.ts</span></div>
|
||||||
|
<div class="find"><span class="fid">P2-10</span><h4>日志 redact 模式不一致</h4><p>redact 覆盖 <code>err.stderr</code> 但遗漏 <code>error.stderr</code>。</p><span class="loc">logger.ts:33-34</span></div>
|
||||||
|
<div class="find"><span class="fid">P3-07</span><h4>CI 无覆盖率门槛</h4><p><code>ci.yml</code> 未设置覆盖率阈值,下降不会被阻止。</p><span class="loc">.github/workflows/ci.yml</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>安全评审逐项评级</h3>
|
||||||
|
<p class="card-sub">审计独立给出六个维度的评级与要点,作为生产准入依据。</p>
|
||||||
|
<div class="grade-grid">
|
||||||
|
<div class="grade-cell"><span class="gv" style="color:var(--gain)">A</span><span class="gl">凭据隔离</span></div>
|
||||||
|
<div class="grade-cell"><span class="gv" style="color:var(--gain)">A</span><span class="gl">注入防护</span></div>
|
||||||
|
<div class="grade-cell"><span class="gv" style="color:var(--warn)">B+</span><span class="gl">快照脱敏</span></div>
|
||||||
|
<div class="grade-cell"><span class="gv" style="color:var(--gain)">A</span><span class="gl">密钥脱敏</span></div>
|
||||||
|
<div class="grade-cell"><span class="gv" style="color:var(--warn)">B</span><span class="gl">子进程安全</span></div>
|
||||||
|
</div>
|
||||||
|
<p style="margin:0;color:var(--text-2);font-size:0.9rem">
|
||||||
|
摘要:容器内无真实凭据、一次性代理认证可靠;路径/分支/仓库名白名单校验完善;
|
||||||
|
正则 + pino redact 双保险覆盖 PAT / npm / OpenAI / Bearer / 私钥样式;
|
||||||
|
子进程环境变量存在低频泄露风险,故子进程安全为 B。
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ================= Critical Review ================= -->
|
||||||
|
<section id="review">
|
||||||
|
<div class="sec-head">
|
||||||
|
<p class="eyebrow">REVIEW</p>
|
||||||
|
<h2>关键评审发现(critical-review-v2)</h2>
|
||||||
|
<p class="sec-lead">独立 critical review 逐文件复核 src/ 与 test/,给出 6 项 CRITICAL、8 项 REQUIRED、10 项 SUGGESTION。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="quote-verdict">
|
||||||
|
<div class="qv-label">Verdict</div>
|
||||||
|
<p><b style="color:var(--warn)">Needs Discussion</b> — 代码结构良好、安全基线强,但存在若干真实缺陷:以"已定义但未接线"的死代码为主,另有排序比较器契约违规与合并前审批竞态。当前部署无即时可利用或数据破坏性缺陷。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table style="min-width:840px">
|
||||||
|
<caption style="font-family:var(--font-mono);font-size:0.72rem;text-align:left;color:var(--text-3);padding:10px 16px 2px">CRITICAL · 发布前必须处理</caption>
|
||||||
|
<thead><tr><th>ID</th><th>发现</th><th>位置</th><th>影响</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr class="row-danger"><td><span class="pill crit">C1</span></td><td><code>MergeGuard</code> 从未被调用</td><td><code>review/merge-guard.ts</code></td><td>并发 schedule/approval/recheck 可对同一 PR 竞态调用 <code>pulls.merge</code></td></tr>
|
||||||
|
<tr class="row-danger"><td><span class="pill crit">C2</span></td><td><code>MetricsCollector</code> 从未被 import</td><td><code>metrics/collector.ts</code></td><td>Actions 模式观测能力完全失效,可观测性承诺落空</td></tr>
|
||||||
|
<tr class="row-danger"><td><span class="pill crit">C3</span></td><td><code>failureMessages.ts</code> 无生产引用</td><td><code>ai/failureMessages.ts</code></td><td>更优的用户侧失败文案未生效</td></tr>
|
||||||
|
<tr><td><span class="pill crit">C4</span></td><td>Sort 比较器返回 <code>NaN</code></td><td><code>processor.ts:1347-1351</code></td><td><code>Date.parse("")</code> 为 NaN,可能选错 check run 或抛"Could not find"</td></tr>
|
||||||
|
<tr><td><span class="pill crit">C5</span></td><td>冲突修复先于管理员审批</td><td><code>processor.ts:188-249</code></td><td><code>require_approval</code> 下 admin 审批前即可推提交并合并,策略被绕过</td></tr>
|
||||||
|
<tr><td><span class="pill crit">C6</span></td><td><code>isNotFoundError</code> 五处重复</td><td>processor / chat / webhook / conflictResolver / knowledge</td><td>API 404 形态变化需同步五处,违 DRY</td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="tblwrap">
|
||||||
|
<table style="min-width:720px">
|
||||||
|
<caption style="font-family:var(--font-mono);font-size:0.72rem;text-align:left;color:var(--text-3);padding:10px 16px 2px">REQUIRED · 建议优先(非阻塞)</caption>
|
||||||
|
<thead><tr><th>ID</th><th>发现</th><th>位置</th><th>说明</th></tr></thead>
|
||||||
|
<tbody>
|
||||||
|
<tr><td><span class="pill req">R3</span></td><td><code>GOOSE_MODEL</code> 默认 <code>gpt-5.4</code> 可能不存在</td><td><code>config.ts:62</code></td><td>新部署将模型找不到失败,除非覆盖环境变量</td></tr>
|
||||||
|
<tr><td><span class="pill req">R8</span></td><td><code>waitForMergeable</code> 仅轮询 5 次 ×1s</td><td><code>processor.ts:1411-1432</code></td><td>大 PR 合并性计算 >10s,建议指数退避(对应审计 P1-07)</td></tr>
|
||||||
|
<tr><td><span class="pill req">R2</span></td><td>webhook 内类型守卫重复</td><td><code>webhook/processor.ts:500-514</code></td><td><code>isRecord/asRecord/asString</code> 建议抽共享工具模块</td></tr>
|
||||||
|
<tr><td><span class="pill req">R1</span></td><td>重复守卫收敛</td><td>全局</td><td>与 C6 同源:单点导出 <code>isNotFoundError</code></td></tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>评审确认的"干净项"</h3>
|
||||||
|
<p class="card-sub">无需改动,评审明确认可。</p>
|
||||||
|
<ul style="margin:0;padding-left:18px;color:var(--text-2);font-size:0.9rem">
|
||||||
|
<li>安全态势:容器隔离、凭据脱敏、路径穿越防护、快照过滤均强</li>
|
||||||
|
<li>配置 zod schema 校验彻底、错误处理一致、全程遵循不可变风格</li>
|
||||||
|
<li>全部既有测试通过且结构良好</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<!-- ================= Quiz ================= -->
|
||||||
|
<section id="quiz">
|
||||||
|
<div class="sec-head">
|
||||||
|
<p class="eyebrow">QUIZ</p>
|
||||||
|
<h2>知识校验:读完即答</h2>
|
||||||
|
<p class="sec-lead">10 道单选题,全部基于上方报告数据。<b style="color:var(--gain)">答对 ≥8 题(80%)视为通过</b>。逐题作答自动判分,全部答完后可查看结业结论。</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="quiz-shell">
|
||||||
|
<div class="quiz-head">
|
||||||
|
<h3>v2.0 迭代知识校验</h3>
|
||||||
|
<div class="quiz-progress" aria-live="polite">
|
||||||
|
已作答 <b id="qp-answered">0</b>/10 · 正确 <b id="qp-correct">0</b>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="quiz-body" id="quiz-body" aria-live="polite"></div>
|
||||||
|
<div style="padding:0 24px 24px">
|
||||||
|
<div class="quiz-verdict">
|
||||||
|
<div class="verdict-box" id="verdict-panel" role="status">
|
||||||
|
<p class="v-title" id="verdict-title">—</p>
|
||||||
|
<p id="verdict-detail"></p>
|
||||||
|
<button class="btn ghost" type="button" id="btn-reset">重新答题</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div style="display:flex;gap:10px;flex-wrap:wrap">
|
||||||
|
<button class="btn" type="button" id="btn-submit" disabled>查看结业结论</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
<div class="container">
|
||||||
|
<div class="foot-grid">
|
||||||
|
<div class="foot-col">
|
||||||
|
<div class="fh">数据来源</div>
|
||||||
|
<ul>
|
||||||
|
<li><code>workflow_status.md</code>(仓库根)</li>
|
||||||
|
<li><code>docs/audit-v2-final.md</code></li>
|
||||||
|
<li><code>docs/critical-review-v2.md</code></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="foot-col">
|
||||||
|
<div class="fh">本报告内容</div>
|
||||||
|
<ul>
|
||||||
|
<li>门禁与指标:基于实际运行输出</li>
|
||||||
|
<li>审计发现:基于 audit-v2-final 复核</li>
|
||||||
|
<li>评审发现:基于 critical-review-v2 复核</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="foot-col">
|
||||||
|
<div class="fh">范围声明</div>
|
||||||
|
<ul>
|
||||||
|
<li>v2.0 半程:M0 / M1 / M2 第一阶段</li>
|
||||||
|
<li>M3 大文件拆分、M4–M7 未在本轮范围</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class="foot-note">ghbot · v2.0 iteration report · generated 2026-08-24</p>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var PASS_THRESHOLD = 8;
|
||||||
|
|
||||||
|
var QUESTIONS = [
|
||||||
|
{
|
||||||
|
q: "本次 v2.0 半程迭代(第一阶段)聚焦的技术方向是?",
|
||||||
|
opts: [
|
||||||
|
"引入新的 AI Provider / 模型",
|
||||||
|
"可靠性、可观测性与测试基建加固(M0/M1/M2)",
|
||||||
|
"将 Actions 模式全部迁移到 webhook 长驻模式",
|
||||||
|
"从头重写冲突修复引擎"
|
||||||
|
],
|
||||||
|
a: 1,
|
||||||
|
why: "依《下一步改进指南》M0–M7 推进,第一阶段落地 M0 测试加固、M1 可靠性、M2 可观测性;M3 大文件拆分与 M4–M7 留待后续。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "相比 v1.2.0,测试用例数量如何变化?",
|
||||||
|
opts: [
|
||||||
|
"151 → 321(+170)",
|
||||||
|
"36 → 48(+12)",
|
||||||
|
"100 → 200",
|
||||||
|
"321 → 151"
|
||||||
|
],
|
||||||
|
a: 0,
|
||||||
|
why: "测试文件 36→48(+12),测试数 151→321(+170,×2.1)。36→48 是文件数变化,不是用例数。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "全局行覆盖率(lines)从 v1.2.0 到 v2.0 的变化是?",
|
||||||
|
opts: [
|
||||||
|
"66.20% → 80.00%(达标)",
|
||||||
|
"61.41% → 66.20%(+4.79pp)",
|
||||||
|
"82.98% → 87.36%",
|
||||||
|
"49.42% → 57.52%"
|
||||||
|
],
|
||||||
|
a: 1,
|
||||||
|
why: "lines 61.41%→66.20%;82.98%→87.36% 是分支覆盖率;49.42% 与 57.52% 分别是 processor 与 conflictResolver 单模块覆盖。80% 是目标而非已达成值。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "本轮新增的三个 100% 覆盖模块是?",
|
||||||
|
opts: [
|
||||||
|
"EventRouter / apiProxy / knowledge",
|
||||||
|
"metrics / retry / cache",
|
||||||
|
"MergeGuard / failureMessages / MetricsCollector",
|
||||||
|
"server / processor / queue"
|
||||||
|
],
|
||||||
|
a: 2,
|
||||||
|
why: "新增源文件为 src/review/merge-guard.ts、src/ai/failureMessages.ts、src/metrics/collector.ts,三个均为 100% 测试覆盖。EventRouter 是 v1.2.0 的产物。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "审计结论中 P0(阻塞)项的数量是?",
|
||||||
|
opts: ["0", "1", "3", "6"],
|
||||||
|
a: 0,
|
||||||
|
why: "审计 P0 表明确:构建、类型检查、测试全部通过,P0-01 为「无」。6 是 critical review 的 CRITICAL 数量。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "审计给出的整体安全评级是?",
|
||||||
|
opts: ["A+", "A-", "B+", "B"],
|
||||||
|
a: 1,
|
||||||
|
why: "凭据隔离 A、注入防护 A、快照脱敏 B+、密钥脱敏 A、子进程安全 B,综合 A-。B 是子进程安全的单项评级。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "Critical review 的最终结论(verdict)是?",
|
||||||
|
opts: [
|
||||||
|
"Approve(直接通过)",
|
||||||
|
"Block(阻塞发布)",
|
||||||
|
"Needs Discussion(需讨论)",
|
||||||
|
"No Action Needed"
|
||||||
|
],
|
||||||
|
a: 2,
|
||||||
|
why: "结论「Needs Discussion」:无即时可利用或数据破坏性缺陷,但多项真实缺陷需在下一版本前解决。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "Critical review 标记的核心缺陷类型是?",
|
||||||
|
opts: [
|
||||||
|
"已定义但未接入生产路径的死代码(MergeGuard / MetricsCollector / failureMessages)",
|
||||||
|
"数据库迁移脚本失败",
|
||||||
|
"认证绕过漏洞",
|
||||||
|
"全局性能瓶颈"
|
||||||
|
],
|
||||||
|
a: 0,
|
||||||
|
why: "C1/C2/C3 均为「模块有定义、有测试、零生产 import」;审计侧对应 P1-01/02/03。Security 评审确认当前部署无可利用漏洞。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "C5 描述的 require_approval 策略绕过场景是?",
|
||||||
|
opts: [
|
||||||
|
"审查结果缓存未经校验被直接复用",
|
||||||
|
"API 限流被绕过导致配额耗尽",
|
||||||
|
"冲突修复在管理员审批通过前启动,可能提前推提交并合并 PR",
|
||||||
|
"Webhook 签名校验被弱化"
|
||||||
|
],
|
||||||
|
a: 2,
|
||||||
|
why: "processor.ts 中冲突资格判定硬编码 reviewPassed:true,require_approval 下 admin 审批前冲突修复即可推进。修复建议为冲突资格加 requiresAdminApproval 守卫。"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
q: "下列哪项属于「已定义但本轮未落地」的里程碑?",
|
||||||
|
opts: [
|
||||||
|
"M0-3:r2 测试覆盖 100%",
|
||||||
|
"M2-2:MetricsCollector 已实现",
|
||||||
|
"M0-8:集成测试(依赖 testcontainers / MinIO 基础设施)",
|
||||||
|
"M1-1:withRetry 智能重试"
|
||||||
|
],
|
||||||
|
a: 2,
|
||||||
|
why: "M0-8 因需 testcontainers/MinIO 基础设施而暂缓。M0-3、M2-2、M1-1 均已落地。"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
var body = document.getElementById("quiz-body");
|
||||||
|
var pbAnswered = document.getElementById("qp-answered");
|
||||||
|
var pbCorrect = document.getElementById("qp-correct");
|
||||||
|
var btnSubmit = document.getElementById("btn-submit");
|
||||||
|
var verdictPanel = document.getElementById("verdict-panel");
|
||||||
|
var verdictTitle = document.getElementById("verdict-title");
|
||||||
|
var verdictDetail = document.getElementById("verdict-detail");
|
||||||
|
var btnReset = document.getElementById("btn-reset");
|
||||||
|
|
||||||
|
var state = { answered: 0, correct: 0, done: new Array(QUESTIONS.length).fill(false) };
|
||||||
|
|
||||||
|
function updateProgress() {
|
||||||
|
pbAnswered.textContent = String(state.answered);
|
||||||
|
pbCorrect.textContent = String(state.correct);
|
||||||
|
}
|
||||||
|
|
||||||
|
function render() {
|
||||||
|
body.textContent = "";
|
||||||
|
QUESTIONS.forEach(function (item, qi) {
|
||||||
|
var wrap = document.createElement("div");
|
||||||
|
wrap.className = "q-item";
|
||||||
|
|
||||||
|
var no = document.createElement("div");
|
||||||
|
no.className = "q-no";
|
||||||
|
no.textContent = "Q" + (qi + 1) + " / 10";
|
||||||
|
wrap.appendChild(no);
|
||||||
|
|
||||||
|
var stem = document.createElement("p");
|
||||||
|
stem.className = "q-stem";
|
||||||
|
stem.textContent = item.q;
|
||||||
|
wrap.appendChild(stem);
|
||||||
|
|
||||||
|
var opts = document.createElement("div");
|
||||||
|
opts.className = "q-opts";
|
||||||
|
|
||||||
|
item.opts.forEach(function (opt, oi) {
|
||||||
|
var btn = document.createElement("button");
|
||||||
|
btn.type = "button";
|
||||||
|
btn.className = "q-opt";
|
||||||
|
btn.setAttribute("aria-label", "选项 " + "ABCD"[oi] + ": " + opt);
|
||||||
|
|
||||||
|
var key = document.createElement("span");
|
||||||
|
key.className = "opt-key";
|
||||||
|
key.textContent = "ABCD"[oi];
|
||||||
|
var txt = document.createElement("span");
|
||||||
|
txt.textContent = opt;
|
||||||
|
|
||||||
|
btn.appendChild(key);
|
||||||
|
btn.appendChild(txt);
|
||||||
|
opts.appendChild(btn);
|
||||||
|
|
||||||
|
btn.addEventListener("click", function () {
|
||||||
|
if (state.done[qi]) return;
|
||||||
|
state.done[qi] = true;
|
||||||
|
state.answered += 1;
|
||||||
|
var isCorrect = oi === item.a;
|
||||||
|
if (isCorrect) state.correct += 1;
|
||||||
|
|
||||||
|
opts.querySelectorAll(".q-opt").forEach(function (b2, bi) {
|
||||||
|
b2.disabled = true;
|
||||||
|
if (bi === item.a) { b2.classList.add("correct"); }
|
||||||
|
else if (bi === oi && !isCorrect) { b2.classList.add("wrong"); }
|
||||||
|
else { b2.classList.add("dim"); }
|
||||||
|
});
|
||||||
|
|
||||||
|
var fb = document.createElement("div");
|
||||||
|
fb.className = "q-feedback";
|
||||||
|
if (isCorrect) {
|
||||||
|
fb.innerHTML = "<b style='color:var(--gain)'>正确。</b> " + item.why;
|
||||||
|
} else {
|
||||||
|
fb.innerHTML = "<b style='color:var(--bad)'>错误。正确答案是 " + "ABCD"[item.a] + "。</b> " + item.why;
|
||||||
|
}
|
||||||
|
wrap.appendChild(fb);
|
||||||
|
|
||||||
|
updateProgress();
|
||||||
|
if (state.answered === QUESTIONS.length) {
|
||||||
|
btnSubmit.disabled = false;
|
||||||
|
btnSubmit.focus({ preventScroll: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
wrap.appendChild(opts);
|
||||||
|
body.appendChild(wrap);
|
||||||
|
});
|
||||||
|
updateProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
function showVerdict() {
|
||||||
|
verdictPanel.classList.add("show");
|
||||||
|
var pass = state.correct >= PASS_THRESHOLD;
|
||||||
|
verdictPanel.classList.toggle("pass", pass);
|
||||||
|
verdictPanel.classList.toggle("fail", !pass);
|
||||||
|
if (pass) {
|
||||||
|
verdictTitle.textContent = "通过 · " + state.correct + " / 10";
|
||||||
|
verdictDetail.textContent = "已达 80% 通过线,说明已掌握 v2.0 迭代的核心内容:测试规模翻倍、覆盖率走势、审计 P0=0 与安全 A-、critical review 的死代码/竞态发现。记录并行项目可推进。";
|
||||||
|
} else {
|
||||||
|
verdictTitle.textContent = "未通过 · " + state.correct + " / 10";
|
||||||
|
verdictDetail.textContent = "需答对 ≥" + PASS_THRESHOLD + " 题(80%)才视为通过。建议重读「变更记录」与「审计/评审发现」两节后重新答题。";
|
||||||
|
}
|
||||||
|
verdictPanel.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
||||||
|
}
|
||||||
|
|
||||||
|
btnSubmit.addEventListener("click", showVerdict);
|
||||||
|
|
||||||
|
btnReset.addEventListener("click", function () {
|
||||||
|
state = { answered: 0, correct: 0, done: new Array(QUESTIONS.length).fill(false) };
|
||||||
|
verdictPanel.classList.remove("show", "pass", "fail");
|
||||||
|
btnSubmit.disabled = true;
|
||||||
|
render();
|
||||||
|
window.scrollTo({ top: document.getElementById("quiz").offsetTop - 74, behavior: "smooth" });
|
||||||
|
});
|
||||||
|
|
||||||
|
render();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -6,6 +6,7 @@ import { config } from "../config.js";
|
|||||||
import { postPermissionDeniedComment } from "../github/commandFeedback.js";
|
import { postPermissionDeniedComment } from "../github/commandFeedback.js";
|
||||||
import { logger } from "../logger.js";
|
import { logger } from "../logger.js";
|
||||||
import { withRetry } from "../retry.js";
|
import { withRetry } from "../retry.js";
|
||||||
|
import { isNotFoundError } from "../github/errors.js";
|
||||||
import { compactFilesForReview } from "../review/prompt.js";
|
import { compactFilesForReview } from "../review/prompt.js";
|
||||||
import type { PullRequestFile } from "../types.js";
|
import type { PullRequestFile } from "../types.js";
|
||||||
import {
|
import {
|
||||||
@@ -304,10 +305,6 @@ function escapeRegExp(value: string): string {
|
|||||||
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNotFoundError(error: unknown): boolean {
|
|
||||||
return typeof error === "object" && error !== null && "status" in error && error.status === 404;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createRepositorySnapshot(sourceWorktree: string): Promise<string> {
|
export async function createRepositorySnapshot(sourceWorktree: string): Promise<string> {
|
||||||
const sourceRoot = await fs.realpath(sourceWorktree);
|
const sourceRoot = await fs.realpath(sourceWorktree);
|
||||||
const tempRoot = tempRootDirectory();
|
const tempRoot = tempRootDirectory();
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/**
|
||||||
|
* Shared GitHub API error utilities.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function isNotFoundError(error: unknown): boolean {
|
||||||
|
return typeof error === "object" && error !== null && "status" in error && error.status === 404;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isAlreadyMergedError(error: unknown): boolean {
|
||||||
|
if (typeof error !== "object" || error === null || !("status" in error)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const candidate = error as { status?: unknown; message?: unknown };
|
||||||
|
if (candidate.status !== 405 && candidate.status !== 409) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
typeof candidate.message === "string" &&
|
||||||
|
/already.{0,20}merged|Pull Request is not mergeable/i.test(candidate.message)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isRetryableGitHubError(error: unknown): boolean {
|
||||||
|
if (typeof error !== "object" || error === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const candidate = error as { status?: unknown };
|
||||||
|
if (typeof candidate.status === "number") {
|
||||||
|
if (candidate.status === 429) return true;
|
||||||
|
if (candidate.status >= 500 && candidate.status < 600) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
+24
-20
@@ -21,6 +21,9 @@ import {
|
|||||||
} from "./policy.js";
|
} from "./policy.js";
|
||||||
import { compactFilesForReview } from "./prompt.js";
|
import { compactFilesForReview } from "./prompt.js";
|
||||||
import { loadRepositoryKnowledge } from "../repository/knowledge.js";
|
import { loadRepositoryKnowledge } from "../repository/knowledge.js";
|
||||||
|
import { MergeGuard } from "./merge-guard.js";
|
||||||
|
import { metrics } from "../metrics/collector.js";
|
||||||
|
import { isNotFoundError, isAlreadyMergedError } from "../github/errors.js";
|
||||||
import {
|
import {
|
||||||
canAutoResolveConflicts,
|
canAutoResolveConflicts,
|
||||||
describeConflictResolutionFailure,
|
describeConflictResolutionFailure,
|
||||||
@@ -28,6 +31,7 @@ import {
|
|||||||
} from "./conflictResolver.js";
|
} from "./conflictResolver.js";
|
||||||
|
|
||||||
const reviewer = new GooseReviewer();
|
const reviewer = new GooseReviewer();
|
||||||
|
const mergeGuard = new MergeGuard();
|
||||||
const CHECK_RUN_NAME = "ghbot review";
|
const CHECK_RUN_NAME = "ghbot review";
|
||||||
export const RECHECK_COMMENT_COMMAND = "/recheck";
|
export const RECHECK_COMMENT_COMMAND = "/recheck";
|
||||||
export const CONFLICT_COMMENT_COMMAND = "/conflict";
|
export const CONFLICT_COMMENT_COMMAND = "/conflict";
|
||||||
@@ -186,7 +190,7 @@ export async function processPullRequest(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mergeablePullRequest = await waitForMergeable(octokit, owner, repo, pullNumber);
|
const mergeablePullRequest = await waitForMergeable(octokit, owner, repo, pullNumber);
|
||||||
const conflictResolutionEligible = canAutoResolveConflicts({
|
const conflictResolutionEligible = !disposition.requiresAdminApproval && canAutoResolveConflicts({
|
||||||
enabled: config.autoResolveConflicts,
|
enabled: config.autoResolveConflicts,
|
||||||
reviewPassed: true,
|
reviewPassed: true,
|
||||||
mergeable: mergeablePullRequest.mergeable,
|
mergeable: mergeablePullRequest.mergeable,
|
||||||
@@ -918,9 +922,17 @@ async function maybeMergePullRequest(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
metrics.recordMergeAttempt("failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mergeGuard.isAlreadyAttempted(owner, repo, pullNumber)) {
|
||||||
|
logger.info({ owner, repo, pullNumber }, "Skipping merge because MergeGuard already attempted it.");
|
||||||
|
metrics.recordMergeAttempt("already_merged");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mergeGuard.markAttempt(owner, repo, pullNumber);
|
||||||
|
|
||||||
if (config.requireChecks) {
|
if (config.requireChecks) {
|
||||||
const checks = await requiredChecksAreGreen(octokit, {
|
const checks = await requiredChecksAreGreen(octokit, {
|
||||||
owner,
|
owner,
|
||||||
@@ -961,24 +973,13 @@ async function maybeMergePullRequest(
|
|||||||
{ owner, repo, pullNumber, headSha: params.headSha },
|
{ owner, repo, pullNumber, headSha: params.headSha },
|
||||||
"Pull request was already merged by a concurrent run."
|
"Pull request was already merged by a concurrent run."
|
||||||
);
|
);
|
||||||
|
metrics.recordMergeAttempt("already_merged");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
metrics.recordMergeAttempt("failed");
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
metrics.recordMergeAttempt("merged");
|
||||||
|
|
||||||
function isAlreadyMergedError(error: unknown): boolean {
|
|
||||||
if (typeof error !== "object" || error === null || !("status" in error)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const candidate = error as { status?: unknown; message?: unknown };
|
|
||||||
if (candidate.status !== 405 && candidate.status !== 409) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
typeof candidate.message === "string" &&
|
|
||||||
/already.{0,20}merged|Pull Request is not mergeable/i.test(candidate.message)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function hasCurrentHeadApprovalFrom(
|
async function hasCurrentHeadApprovalFrom(
|
||||||
@@ -1062,8 +1063,9 @@ async function hasCurrentHeadApprovalFrom(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNotFoundError(error: unknown): boolean {
|
function errorHasStatus(error: unknown, key: string, expected: number): boolean {
|
||||||
return typeof error === "object" && error !== null && "status" in error && error.status === 404;
|
const candidate = error as Record<string, unknown>;
|
||||||
|
return typeof candidate[key] === "number" && candidate[key] === expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
function reviewProgressMarker(headSha: string): string {
|
function reviewProgressMarker(headSha: string): string {
|
||||||
@@ -1346,9 +1348,11 @@ async function markReviewCheckApproved(
|
|||||||
});
|
});
|
||||||
const check = checks.data.check_runs
|
const check = checks.data.check_runs
|
||||||
.filter((item) => item.name === CHECK_RUN_NAME)
|
.filter((item) => item.name === CHECK_RUN_NAME)
|
||||||
.sort(
|
.sort((left, right) => {
|
||||||
(left, right) => Date.parse(right.started_at ?? "") - Date.parse(left.started_at ?? "")
|
const lt = left.started_at ? Date.parse(left.started_at) : 0;
|
||||||
)[0];
|
const rt = right.started_at ? Date.parse(right.started_at) : 0;
|
||||||
|
return (Number.isNaN(rt) ? 0 : rt) - (Number.isNaN(lt) ? 0 : lt);
|
||||||
|
})[0];
|
||||||
|
|
||||||
if (!check) {
|
if (!check) {
|
||||||
throw new Error(`Could not find ${CHECK_RUN_NAME} check for ${params.headSha}.`);
|
throw new Error(`Could not find ${CHECK_RUN_NAME} check for ${params.headSha}.`);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { withRetry } from "../retry.js";
|
|||||||
import { compactFilesForReview } from "../review/prompt.js";
|
import { compactFilesForReview } from "../review/prompt.js";
|
||||||
import type { PullRequestFile } from "../types.js";
|
import type { PullRequestFile } from "../types.js";
|
||||||
import { listPullRequestFiles } from "../github/pulls.js";
|
import { listPullRequestFiles } from "../github/pulls.js";
|
||||||
|
import { isNotFoundError } from "../github/errors.js";
|
||||||
|
|
||||||
const WEBHOOK_CHAT_MARKER = "<!-- ghbot-webhook-chat:v1";
|
const WEBHOOK_CHAT_MARKER = "<!-- ghbot-webhook-chat:v1";
|
||||||
const MAX_WEBHOOK_REPLY_CHARS = 60_000;
|
const MAX_WEBHOOK_REPLY_CHARS = 60_000;
|
||||||
@@ -512,7 +513,3 @@ function asString(value: unknown): string | undefined {
|
|||||||
function asPositiveInteger(value: unknown): number | undefined {
|
function asPositiveInteger(value: unknown): number | undefined {
|
||||||
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
return typeof value === "number" && Number.isSafeInteger(value) && value > 0 ? value : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNotFoundError(error: unknown): boolean {
|
|
||||||
return typeof error === "object" && error !== null && "status" in error && error.status === 404;
|
|
||||||
}
|
|
||||||
+23
-11
@@ -14,6 +14,7 @@
|
|||||||
| npm test | ✅ 321 tests / 321 pass / 0 fail |
|
| npm test | ✅ 321 tests / 321 pass / 0 fail |
|
||||||
| npm run build | ✅ dist/ 构建成功 |
|
| npm run build | ✅ dist/ 构建成功 |
|
||||||
| 覆盖率 | 66.20% lines / 87.36% branches / 75.57% functions |
|
| 覆盖率 | 66.20% lines / 87.36% branches / 75.57% functions |
|
||||||
|
| 审计报告 | ✅ docs/audit-v2-final.md 已生成(含盲点扫描、安全评审、架构评审、测试评审) |
|
||||||
|
|
||||||
## 测试规模增长
|
## 测试规模增长
|
||||||
|
|
||||||
@@ -29,11 +30,11 @@
|
|||||||
|
|
||||||
### 源文件(新模块)
|
### 源文件(新模块)
|
||||||
|
|
||||||
| 文件 | 功能 | 覆盖 |
|
| 文件 | 功能 | 覆盖 | 生产接入 |
|
||||||
|------|------|------|
|
|------|------|------|---------|
|
||||||
| `src/ai/failureMessages.ts` | 失败分类与告警文案 | 100% |
|
| `src/ai/failureMessages.ts` | 失败分类与告警文案 | 100% | ❌ 未接入 |
|
||||||
| `src/review/merge-guard.ts` | 合并防重入锁 | 100% |
|
| `src/review/merge-guard.ts` | 合并防重入锁 | 100% | ❌ 未接入 |
|
||||||
| `src/metrics/collector.ts` | Actions 运行指标收集器 | 100% |
|
| `src/metrics/collector.ts` | Actions 运行指标收集器 | 100% | ❌ 未接入 |
|
||||||
|
|
||||||
### 测试文件(新)
|
### 测试文件(新)
|
||||||
|
|
||||||
@@ -62,9 +63,10 @@
|
|||||||
| M0-6 | conflict-resolver 测试(56.56%→57.52%) | ✅ |
|
| M0-6 | conflict-resolver 测试(56.56%→57.52%) | ✅ |
|
||||||
| M0-7 | processor 测试(49.08%→49.42%) | ✅ |
|
| M0-7 | processor 测试(49.08%→49.42%) | ✅ |
|
||||||
| M1-1 | withRetry 智能重试(抖动+总超时) | ✅ |
|
| M1-1 | withRetry 智能重试(抖动+总超时) | ✅ |
|
||||||
| M1-3 | MergeGuard 合并防重入 | ✅ |
|
| M1-3 | MergeGuard 合并防重入(定义+测试) | ✅ 定义完成,待接入生产代码 |
|
||||||
| M1-4 | failureMessages 失败分类 | ✅ |
|
| M1-4 | failureMessages 失败分类(定义+测试) | ✅ 定义完成,待接入生产代码 |
|
||||||
| M2-2 | MetricsCollector 指标收集器 | ✅ |
|
| M2-2 | MetricsCollector 指标收集器(定义+测试) | ✅ 定义完成,待接入生产代码 |
|
||||||
|
| 审计 | 完整审计报告 | ✅ docs/audit-v2-final.md |
|
||||||
|
|
||||||
## 未落地项
|
## 未落地项
|
||||||
|
|
||||||
@@ -77,8 +79,18 @@
|
|||||||
| M3 | 大文件拆分(processor/conflictResolver) | 单独里程碑 |
|
| M3 | 大文件拆分(processor/conflictResolver) | 单独里程碑 |
|
||||||
| M4-M7 | 后续里程碑 | 逐步推进 |
|
| M4-M7 | 后续里程碑 | 逐步推进 |
|
||||||
|
|
||||||
|
## 审计发现摘要(详见 docs/audit-v2-final.md)
|
||||||
|
|
||||||
|
| 类别 | 计数 | 关键项 |
|
||||||
|
|------|------|--------|
|
||||||
|
| P0 | 0 | 无阻塞项 |
|
||||||
|
| P1 | 8 | MergeGuard/failureMessages/MetricsCollector 未接入、processor.ts 1736行、conflictResolver.ts 1250行、覆盖率不足、waitForMergeable 无超时、无陈旧检测 |
|
||||||
|
| P2 | 10 | sanitization 排除清单不完整、webhook 队列无持久化、分页缺失等 |
|
||||||
|
| P3 | 10 | 分片审查、AI Provider 抽象、国际化等 |
|
||||||
|
|
||||||
## 下一阶段建议
|
## 下一阶段建议
|
||||||
|
|
||||||
1. 先提交当前成果(v2.0-alpha),推送到 origin
|
1. 先提交当前成果,推送到 origin
|
||||||
2. 第二阶段处理 processor.ts 拆分(M3),再补 M1-2 陈旧检测
|
2. **第二阶段**:接入 3 个新模块到生产代码(MergeGuard→processor.ts, failureMessages→gooseCli.ts, MetricsCollector→runReview.ts)
|
||||||
3. 第三阶段做集成测试(M0-8)
|
3. **第三阶段**:拆分 processor.ts 和 conflictResolver.ts(M3),再补 M1-2 陈旧检测
|
||||||
|
4. **第四阶段**:做集成测试(M0-8)
|
||||||
Reference in new issue
Block a user