aps-agent/docs/round-10-approval-delegate-...

90 lines
4.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 第 10 轮工作计划(轻量合并版):审批委托(delegation)
更新日期:2026-08-01
## 1. 本轮目标
新增审批委托:发起人在出卡时可指定被委托人(`delegate_user_id`),该确认卡的审批作用域允许 owner 或被委托人操作(P2 单重审批);委托不改变 P3 双人职责分离语义。矩阵 P3「外部副作用二次确认」剩余项之一(审批委托)完成。
## 2. 背景和当前状态
- 当前已完成:审批意见(note)、批量审批、证据链强校验、双后端(文件/DB)持久化 record payload。
- 当前缺口:`_matches_current_scope` 只认 owner(`ownerUserId == identity.user_id`),无委托能力;`stage_confirmation` 无 delegate 参数。
- 本轮为什么现在做:矩阵 P3 剩余「委托/转派审批」的首项;纯本地可验证,双后端 record 以 payload 整存(新字段自然持久化)。
- Workspace preflight:第 9 轮收口(462 passed);服务 8003/5173 正常;共享脏工作区、无提交。
- 方向分析:Q1 推荐选项 A(审批委托/转派-委托首切片),目标续跑轮授权执行。
## 3. 本轮工作方向
```text
_matches_current_scope 只认 owner
-> stage_confirmation 增加 delegate_user_id(写入 record.delegateUserId)
-> _matches_current_scope:P2 允许 owner 或被委托人审批;P3 保持双人分离
-> 黄金测试:delegate 可审批、非 delegate 不可、owner 仍可、P3 不受影响
-> 矩阵 P3 注记「审批委托已完成」;CHANGELOG
```
## 4. 已确认决策
任务重量:
- 档位:轻型(harness + approval_store 作用域逻辑 + 测试)。
- 规模依据:改动集中在 `stage_confirmation` 与 `_matches_current_scope`;双后端 record payload 整存无需迁移;风险 LOW。
- 选择原因:P3 剩余项中最小的独立增量。
P0/P1 决策(按 Q1 推荐采纳):
- 决策 1(P0):本轮切片 = 审批委托(选项 A 首项)。
- 决策 2(P1):不新建分支、不提交、不推送。
- 决策 3(P1):验证深度 = 聚焦委托测试 + 全量黄金回归。
默认假设:
- 假设 1:委托仅对 P2 单重审批生效(P3 首次/二次批准仍强制双人分离,delegate 视为独立用户)。
- 假设 2:delegate 不改变角色策略(仍需具备审批角色),只扩展作用域匹配。
- 假设 3:`delegateUserId` 存入 record;双后端(文件 JSON / DB payload JSON 列)天然持久化,无需 schema 变更。
- 假设 4:委托信息进入审批历史(history_event 保留 record 字段)。
未决但不阻塞:转派(transfer,将待办转移他人)、批量委托、委托撤销(后续轮)。
## 5. 范围
In scope:
- `server/agent_core/harness.py`:`stage_confirmation` 增加 `delegate_user_id: int | None = None` 参数 → `record["delegateUserId"]`;`_matches_current_scope` P2 分支允许 `identity.user_id in (ownerUserId, delegateUserId)`。
- `server/agent_core/approval_store.py` / `approval_db_store.py`:无需改动(record 整存);核对 history_event 透传 delegate 字段(如有白名单投影需补)。
- `tests/golden/test_approval_store.py`、`test_harness_p3.py` 或新 `test_approval_delegate.py`:delegate 可审批、非 delegate 拒绝、owner 仍可、P3 双人分离不受影响、双后端持久化。
- 文档:`docs/architecture/harness.md`、`docs/product/plan-completion-matrix.md`(P3 注记)、`docs/CHANGELOG.md`。
Out of scope:
- 转派、批量委托、委托撤销、MySQL 实机故障注入。
- 提交/推送/合并/清理用户改动。
## 6. 成功标准
- 聚焦:`python -m pytest -q tests/golden/test_approval_delegate.py tests/golden/test_approval_store.py tests/golden/test_harness_p3.py -p no:cacheprovider` 通过。
- 全量:`python -m pytest tests/golden -q -p no:cacheprovider`(固定 .venv)≥ 462。
- ruff 干净;git diff --check 无空白错误。
## 7. 验证方式
- 委托作用域单测(owner/delegate/非委托三方);P3 双人分离回归;全量黄金。
## 8. 关键风险
| 风险 | 影响 | 控制方式 |
|---|---|---|
| delegate 越权审批 | 安全回归 | 只扩展 P2 owner/delegate 匹配;P3 不变 |
| 双后端字段漂移 | 委托失效 | record 整存 + 测试覆盖文件与 DB 后端 |
| 角色策略绕过 | 越权 | delegate 仍须具备审批角色 |
## 9. 停止条件
- 全量黄金测试非本轮相关回归无法快速定位时暂停。
- 任何提交/推送/合并/清理操作停下等待授权。
## 10. 本轮完成定义
- 实现、测试、文档完成;聚焦与全量通过;矩阵/CHANGELOG 回写;不提交。
- 收口:报告主要结论、关键洞察、需要特别留意的地方。
## 11. 下一步
轻量合并版:主 agent 实现 + 验证 + 收口报告。