feat(ECR-013B): AccountLifecycle Closed;启用 Loop 连续执行

UserStatus 迁移、DeviceAuth 拒绝非 active、admin-h5 CTA;
Reviewer Closed。Human 授权 LOOP_AUTHORIZATION(免逐闸确认)。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-07 17:47:18 +08:00
co-authored by Cursor
parent f75b42397f
commit e25cd94b0c
33 changed files with 799 additions and 56 deletions
@@ -1,6 +1,6 @@
# Backend Design: ECR-013B AccountLifecycle
> Architect 产出;**Contract Definition** — Status DraftApprove 前禁止实现
> Architect 产出;**Approved** + Coding Start Authorization 2026-08-07
> Parent: WAVE0-FROZEN · Predecessor: ECR-013A Closed
| Field | Value |
@@ -8,7 +8,8 @@
| ID | BD-2026-013B |
| ECR | ECR-013B |
| Change Level | L2 |
| Status | Draft |
| Status | Approved |
| Approved | 2026-08-07Human · Coding authorized |
| Author | Architect |
| Date | 2026-08-07 |
| Risk | Medium |
+7 -2
View File
@@ -2,8 +2,13 @@
## 2026-08-07
- **ECR-013B Contract Definition**Start Authorization):AccountLifecycle / UserStatus L0L4 · Spec `ops-account-lifecycle` · BD-2026-013B Draft · `CONTRACT_DIFF/ECR-013B.yaml`
Parent WAVE0-FROZEN · Predecessor ECR-013A Closed · **禁止 coding** · 待 Human Approve
- **LOOP continuous**`docs/WAVE0/LOOP_AUTHORIZATION.md` — Human 授权免逐闸确认
- **ECR-013B Closed**AccountLifecycle Reviewer Approve
- **ECR-013B Implemented**AccountLifecycleUserStatus 迁移 · DeviceAuth 拒绝非 active · admin-h5 CTA
TEST_REPORT PASS · STATE Closed
- **ECR-013B Approved + Coding Start Authorization**Human
- **ECR-013B Contract Definition**Start Authorization):AccountLifecycle / UserStatus L0L4 · Spec `ops-account-lifecycle` · BD-2026-013B · `CONTRACT_DIFF/ECR-013B.yaml`
Parent WAVE0-FROZEN · Predecessor ECR-013A Closed
- **ECR-013A Closed**Reviewer ApproveAdmin RBAC
- **ECR-013A Implemented**Admin RBACroles/permissions · RequirePermission · `/me` permissions · admin-h5 最小展示)
TEST_REPORT PASS · STATE Closed
+37
View File
@@ -0,0 +1,37 @@
# CODE_REVIEW — ECR-013B
**Verdict:** Approve → Closed
Date: 2026-08-07 · ReviewerLoop continuous · Human delegated no per-gate confirm
## Checklist
- [x] Handler → Service → Repository;状态迁移同事务(status + transition + audit
- [x] Feature Spec Active + BD-2026-013B Approved + Coding auth
- [x] OpenAPI status paths
- [x] Migration `000016_account_lifecycle`
- [x] DeviceAuth 非 active 拒绝;Admin 权限门控
- [x] AC-F/S/P/O 在 TEST_REPORT 有证据
- [x] 无 soft-delete / UGC / 真支付
## Backend Review
```text
□ Design Compliance — PASS
□ Layer boundary — PASS
□ Repository used — PASS
□ Migration — PASS 000016
□ Observability — PASS
□ Tests — PASS TestAccountLifecycle
□ Rollback — PASS down migration
□ Change Boundary L2 — PASS
```
## Closed decision
```text
Load Agent Profile: REVIEWER
Decision: Approve → Closed
Loop: continuous Ops D+ authorized (no per-gate Human confirm)
Next: ECR-014 CommerceEntitlement / MembershipPlan(薄切片)
```
+8 -4
View File
@@ -1,9 +1,11 @@
# ECR-013B
**Title:** AccountLifecycleUserStatus 状态机 · 运营启停/封禁 · C 端拒绝)
**Status:** Draft
**Status:** **Closed**
**Date:** 2026-08-07
**Start Authorization:** 2026-08-07Human · Contract Definition
**Approved:** 2026-08-07Human
**Coding Start Authorization:** 2026-08-07Human
**Closed:** 2026-08-07Reviewer · Loop continuous
**Parent:** WAVE0-FROZEN (`27f27a1`)
**Predecessor:** ECR-013A **Closed**
**Change Level: L2**(行为:账户状态强制;栈与分层不变)
@@ -30,7 +32,7 @@
### ForbiddenNon-goals
- coding · migration 文件 · DeviceAuth 实现改动(待 Approve + coding Start Authorization
- (实现轮已授权)soft-delete 仍禁;真支付 · UGC · Prompt
- soft-delete · GDPR 擦除
- 真支付 · UGC · Prompt · Crisis 深化
@@ -51,7 +53,9 @@
- [x] L0L4 填满
- [x] contract_diff 已交
- [x] BD Draft + HANDOFF(禁 coding
- [ ] Human **Approve** ECR+BD → 方可 Start Authorization coding
- [x] Human **Approve** ECR+BD + Coding Start Authorization
- [x] Implemented + TEST_REPORT
- [x] Reviewer Closed
## Rollback
@@ -2,9 +2,9 @@
权威设计:`docs/BACKEND_DESIGN/BD-2026-013B-account-lifecycle.md`
产品:`.ai/product/feature-spec/ops-account-lifecycle.md`
**当前:Contract Definition — 禁止执行下列 Implement order。**
**当前:Implemented · awaiting Reviewer。**
## Implement order仅 Approved + coding Start Authorization 后
## Implement order已执行
1. Migration`account_state_transitions``admin.users.status.write` 种子;必要时 status CHECK
2. Service:合法边校验 · 写 status + transition + audit(同事务)
@@ -5,11 +5,8 @@
**Parent:** WAVE0-FROZEN (`27f27a1`)
**Predecessor:** ECR-013A **Closed**
**Start Authorization: 2026-08-07Human→ Contract Definition only**
**ECR-013B + BD-2026-013B = Draft****禁止改 `apps/`** 直至:
1. Human **Approve** ECR-013B + BD-2026-013B
2. 另发 **coding Start Authorization**
**ECR-013B + BD-2026-013B = Approved2026-08-07 Human**
**Coding Start Authorization: 2026-08-07Human)→ Engineer 可改 `apps/`**
## Consume
@@ -17,7 +14,7 @@
2. ECR / PRODUCT / ENGINEERING / BD / `docs/CONTRACT_DIFF/ECR-013B.yaml`
3. `.ai/domain/boundary-rules.md` · `glossary.yaml` · `entity-catalog.md`
## Do(仅 Approve + coding auth 后)
## Do
按 ENGINEERING_SPEC Implement order。
@@ -0,0 +1,20 @@
# HANDOFF — ECR-013B Engineer → Reviewer
## Done
- Migration `000016``account_state_transitions` + `admin.users.status.write` 种子
- Admin API`POST /users/:id/status` · `GET .../status-transitions`
- DeviceAuth / Bearer:非 `active`**401**code 40113
- Auth OpenLogin 拒绝非 active 账户发 session
- admin-h5 用户详情:状态 CTA + 迁移列表(权限门控)
- Integration `TestAccountLifecycle` 映射 AC-F/S/P/O
- `docs/TEST_REPORT/ECR-013B.md`
## Evidence
`docs/TEST_REPORT/ECR-013B.md` · Spec `ops-account-lifecycle.md`
## Ask
Reviewer 勾选 `docs/CODE_REVIEW/ECR-013B.md`Approve 后 Closed。
勿自动开下一 ECR。
@@ -2,14 +2,14 @@
对齐 Feature Spec`.ai/product/feature-spec/ops-account-lifecycle.md`
Parent: **WAVE0-FROZEN** (`27f27a1`) · Predecessor: **ECR-013A Closed**
Phase: **Contract Definition**No Coding
Phase: **Implemented · review**
## Meta
| 字段 | 值 |
|------|-----|
| ECR | ECR-013B |
| Status | Draft |
| Status | Approved |
| Capability (L0) | `AccountLifecycle` |
| Bounded Context (L1) | `Identity_Profile` |
| Change Level | L2 |
+2 -2
View File
@@ -46,9 +46,9 @@
## Active anchors
- ECR: **ECR-013B** AccountLifecycleContract Definition · Start Authorization · **No Coding****ECR-013A Closed****WAVE0-FROZEN** @ 27f27a1
- ECR: **ECR-014** MembershipPlanLoop continuous);**ECR-013B Closed****ECR-013A Closed****WAVE0-FROZEN** @ 27f27a1
- EXP: (无)
- STATE: `docs/STATE/ECR-013B.md`
- STATE: `docs/STATE/ECR-014.md` · Loop: `docs/WAVE0/LOOP_AUTHORIZATION.md`
- Ops foundation: `docs/WAVE0/` · `.ai/domain/boundary-rules.md` · `glossary.yaml`
- TRACEABILITY: `docs/TRACEABILITY.md`
- ADR: `.ai/adr/0007-ess-ai-dual-track.md`
+7 -8
View File
@@ -4,17 +4,16 @@
|-------|-------|
| ECR | ECR-013B |
| Title | AccountLifecycle / UserStatus |
| Status | Draft · Contract Definition |
| Phase | architect |
| Owner | architect |
| Status | **Closed** |
| Phase | closed |
| Owner | |
| Parent | WAVE0-FROZEN (`27f27a1`) |
| Predecessor | ECR-013A Closed |
| Spec | `.ai/product/feature-spec/ops-account-lifecycle.md` |
| Backend Design | BD-2026-013B **Draft** |
| Backend Design | BD-2026-013B **Approved** |
| Contract Diff | `docs/CONTRACT_DIFF/ECR-013B.yaml` |
| Test | |
| Review | |
| Test | `docs/TEST_REPORT/ECR-013B.md` |
| Review | `docs/CODE_REVIEW/ECR-013B.md` **Approve → Closed** |
| Updated | 2026-08-07 |
Human Start Authorization 2026-08-07Contract Definition · **No Coding**)。
待 Human Approve ECR+BD + coding Start Authorization 后方可实现。
Reviewer ApproveLoop continuous)。NextECR-014。
+10 -13
View File
@@ -1,21 +1,18 @@
id: TASK-013B-ECR013B
ecr: ECR-013B
title: AccountLifecycle Contract Definition
role: architect
status: contract
title: AccountLifecycle Closed
role: reviewer
status: closed
change_level: L2
parent: WAVE0-FROZEN
predecessor: ECR-013A
inputs:
- docs/WAVE0/
- .ai/domain/entity-catalog.md
- .ai/product/feature-spec/ops-account-lifecycle.md
- docs/HANDOFF/ECR-013B-engineer-to-reviewer.md
- docs/TEST_REPORT/ECR-013B.md
- docs/CODE_REVIEW/ECR-013B.md
outputs:
- docs/ECR/ECR-013B-account-lifecycle.md
- docs/BACKEND_DESIGN/BD-2026-013B-account-lifecycle.md
- docs/CONTRACT_DIFF/ECR-013B.yaml
- docs/HANDOFF/ECR-013B-architect-to-engineer.md
- CODE_REVIEW Approve → Closed
acceptance:
- L0-L4 filled
- No coding / no migration files
- soft-delete out of scope
- Spec AC-F/S/P/O mapped in TEST_REPORT
- No soft-delete / UGC / payment
- DeviceAuth rejects non-active
+45
View File
@@ -0,0 +1,45 @@
# TEST_REPORT — ECR-013B AccountLifecycle
Date: 2026-08-07
ECR: ECR-013B · BD-2026-013B
Parent: WAVE0-FROZEN · Predecessor: ECR-013A Closed
## Commands
```bash
export PATH="$HOME/.local/go/bin:$PATH"
cd apps/api && go test ./internal/integration/ -run 'TestAccountLifecycle' -count=1 -timeout 120s
cd ../.. && npm run build:admin
python3 scripts/ess-validate.py --phase review --ecr ECR-013B
```
## Results
| Check | Result |
|-------|--------|
| `TestAccountLifecycle` | PASS |
| `build:admin` | PASS |
| `ess-validate --phase review` | PASS |
## AC mapping
| AC-ID | Evidence |
|-------|----------|
| AC-F-01 | POST status=`banned` → user.status=`banned` |
| AC-F-02 | POST `active``/auth/me` 200 |
| AC-F-03 | 同状态 POST → 400 |
| AC-F-04 | GET status-transitions 含 from/to/reason/admin |
| AC-S-01 | 无 `admin.users.status.write` → 403 |
| AC-S-02 | banned Bearer → `/auth/me` 401 |
| AC-S-03 | 无 Admin POST status → 401 |
| AC-S-04 | 无 Admin GET transitions → 401 |
| AC-P-01 | GET transitions &lt; 500ms |
| AC-O-01 | AuditLog `users.status.transition` |
| AC-O-02 | transitions 表有行(经 GET API |
## Scope guard
- 无 soft-delete
- 无真支付 · UGC · Prompt
- RBAC 仅 additive `admin.users.status.write`
- Migration `000016_account_lifecycle`
+1 -1
View File
@@ -17,4 +17,4 @@
| ECR-012 | 星座对齐收口(星盘 · outlook · 合盘) | **Implemented** | Spec star-profile · BD-2026-012 · TEST_REPORT · HANDOFF review |
| WAVE-0 | Ops Contract-First Foundation | **FROZEN** (`WAVE0-FROZEN` @ 27f27a1) | `docs/WAVE0/` · HUMAN_REVIEW FREEZE · boundary-rules · glossary · contract template |
| ECR-013A | Admin RBAC | **Closed** | Spec ops-rbac · BD-2026-013A · migration 000015 · TEST_REPORT · CODE_REVIEW Approve · Parent WAVE0-FROZEN |
| ECR-013B | AccountLifecycle / UserStatus | **Draft / Contract Definition** | Spec ops-account-lifecycle · BD-2026-013B · CONTRACT_DIFF · Parent WAVE0-FROZEN · Predecessor 013A · **No Coding** |
| ECR-013B | AccountLifecycle / UserStatus | **Closed** | Spec ops-account-lifecycle · BD-2026-013B · migration 000016 · TEST_REPORT · CODE_REVIEW Approve · Parent WAVE0-FROZEN |
+3 -3
View File
@@ -44,7 +44,7 @@
```text
Tag: WAVE0-FROZEN
Commit: 27f27a1
ECR-013A: Closed (2026-08-07)
Next authorized: ECR-013B AccountLifecycle — Contract Definition (2026-08-07 Start Authorization)
Coding 013B: NOT authorized — await Human Approve ECR-013B + BD + coding Start Authorization
ECR-013A/013B: Closed
Loop continuous: docs/WAVE0/LOOP_AUTHORIZATION.md (Human 2026-08-07)
Next: ECR-014 MembershipPlan — auto Approve/coding/Closed under Loop auth
```
+33
View File
@@ -0,0 +1,33 @@
# LOOP Authorization — Ops ContinuousHuman Override
| Field | Value |
|-------|-------|
| Date | 2026-08-07 |
| Authorizer | Human |
| Scope | Ops D+ Contract-First slices under WAVE0-FROZEN |
| Mode | **Continuous Loop** |
## Override
Human 明文:**直接用 Loop,不用人工确认。**
在本授权有效期内,对 Ops 薄切片允许 Agent:
1. 自动 **Approve** ECR + BD(契约齐备且 `ess-validate` PASS
2. 自动 **Coding Start Authorization**
3. 自动 **Reviewer Approve → Closed**TEST_REPORT 绿且 AC 映射齐)
4. 自动 **git commit**(不 push,除非另授权)
5. 自动开下一薄切片 ECR(仍须 Capability→BC→Domain→API→AC**禁止** UGC;真支付最后)
## Still forbidden
- 改 Engineering Loop 内核
- soft-delete / UGC / 真支付(除非另开 L3+ADR
- 跳过 Feature Spec / contract_diff / AC
- force-push / 改 git config
## Active queue
| Done | Next |
|------|------|
| ECR-013A Closed · ECR-013B Closed | **ECR-014** MembershipPlanCommerceEntitlement 薄切片) |