skillhub/openspec/changes/clarify-skill-ownership-transfer/tasks.md
XiaoSeS babd254862 fix(handover): convert each item in its own transaction and gate same-slug cases
Two defects found by review of the branch itself.

**Batch conversion was one transaction.** `convertBatch` carried `@Transactional` and
called `convertItem` directly, so the self-invocation bypassed the proxy and folded the
whole batch into one transaction. A single failing item rolled back the items that had
already converted, contradicting the method's own guarantee. The batch is now
non-transactional and calls through an injected self reference, so each item commits or
rolls back alone. `aFailingItemDoesNotUndoTheItemsThatAlreadyCommitted` forces the second
item to fail and asserts the first stays DONE; re-adding `@Transactional` makes it fail.

**REQ-ADDR-04 was absent.** Nothing refused a handover whose completion would leave the
recipient or the former owner holding another ACTIVE record under the same slug, even
though `(namespace_id, slug, owner_id)` permits those records to coexist and completion
turns the Skill into one with no owner. `assertNoSameSlugConflict` now refuses such a
request at start and again under the lock at completion (REQ-HO-04), with a localized
message in the base, zh and ru bundles. A third party's same-slug record still does not
block, because exact addressing resolves that case. Removing the guard makes the tests fail.

Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
2026-12-02 14:10:12 +08:00

70 lines
10 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.

## 0. Contract
- [x] Record the ownership, maintenance and handover contract from the PR #1060 discussion.
- [x] Settle the open questions (maintainer decisions, 2026-11-17).
- [x] Maintainers confirm the slug-only upload case (REQ-ADDR-05, confirmed 2026-11-18).
- [x] DCO and CLA checks pass on the contract PR.
- [x] Apply the 2026-11-23 clarifications: event-bound conversion restriction, set-based registration and scale validation.
## 1. Delivery 1: TEAM access-rule fix
- [x] Require current membership for internal reads by the owner (REQ-DEP-01), for sessions and Tokens, including auto-provisioned namespaces (REQ-OM-06). Delivered in #1134 (`06f23ee42`).
- [x] Replace the read-only UI message; release note on the behavior change and the download-link boundary (REQ-DEP-07). Delivered in #1134.
- [x] Tests: departed owner denied on old and new records; public content still readable; admin paths unchanged. Delivered in #1134; the review attempt-history route is covered in the same PR.
## 2a. Delivery 2 prerequisite: exact addressing and compatibility
- [x] Call-site inventory: every slug lookup and owner read, marked "must change" or "retest only". Recorded in `inventory-2a.md`.
- [x] Compatibility matrix for historical data and legacy clients, including the REQ-ADDR-05 case (maintainer of 202, no personal record, slug-only upload: selection-required error listing 202, nothing updated or created). Scenarios D1-D10 in `inventory-2a.md`.
- [x] Additive schema migration; no conversion. `V131__skill_ownership_columns.sql`; runtime check kept 35 existing Skills `USER` with revision 0.
- [x] Responsibility resolver, including global copies through `source_skill_id` (REQ-OM-04, REQ-OM-05, REQ-OM-07 to REQ-OM-09); migrate every "must change" owner read. `SkillResponsibilityResolver` plus the C1 migrations; notification, auto-publication and lifecycle reads use `SkillOwnerAccess.isResponsible`.
- [x] Extend `SkillSlugResolutionService` with optional `skillId` and the selection-required error (REQ-ADDR-02, REQ-ADDR-03, REQ-ADDR-07, REQ-ADDR-08). 11 resolver tests; 409 verified at runtime.
- [x] Upload target selection: create vs. update (REQ-ADDR-05). Publish accepts `skillId`; 4 runtime cases plus 3 unit tests.
- [x] Web: carry `skillId` through routes, queries and mutations. CLI: `--skill-id` and install-record use. Detail, versions, compare, files and document queries send it; navigation between versions and into compare keeps it; suite member links pass `member.skillId`.
- [x] Regenerate OpenAPI types and check consumers. Generated against the running 2a backend; `pnpm run typecheck` clean.
- [x] Validate the compatibility matrix (REQ-ADDR-06), with maintainer help for populated data and old clients. D1-D10 results recorded in `inventory-2a.md` §D.1.
## 2b. Delivery 2: ownership model and handover
- [x] Handover service: start, accept, reject, cancel, expire, invalidate (REQ-HO-01 to REQ-HO-04, REQ-HO-06, REQ-HO-09, REQ-HO-10). `SkillHandoverServiceTest` covers each transition, `expireDue` and membership-loss invalidation; `SkillHandoverConcurrencyPostgresTest` covers the competing completions on real PostgreSQL.
- [x] No pending-work blocking; lock the source Skill and compare `ownership_revision` in review decisions, promotion approval and auto-approval (REQ-HO-05, REQ-HO-11, REQ-DEP-03, REQ-DEP-10). `ReviewService.approveReview` and `PromotionService.approvePromotion` lock and refresh the Skill before reading authorization; `TeamAutoPublicationService` compares the recorded revision under `lockForScanCompletion` and falls back to a human. `SkillHandoverReviewConcurrencyPostgresTest` exercises the human decision racing a completion.
- [x] Archived and hidden Skills keep their state; no unhide path (REQ-HO-08, REQ-HO-12, REQ-HO-13). `SkillHandoverServiceTest` pins that an archived Skill stays `ARCHIVED` and a hidden one stays hidden through acceptance, that a hidden Skill can be handed over without being unhidden first, and that completion touches neither hidden nor publication state. `VisibilityCheckerTest` pins that the recorded maintainer of a hidden, namespace-owned Skill can read it while anonymous users and plain members still cannot. Both tests were mutation-checked: injecting an accidental unhide or status reset makes them fail.
- [x] Notifications (`OWNERSHIP`) and audit actions (REQ-HO-07). `SkillHandoverNotificationListenerTest` covers recipient, initiator and previous-responsible notifications; each transition writes its audit action.
- [x] UI: handover dialog with recipient search, My Skills requests tab, Skill detail panel. Dialog, `/dashboard/handover` inbox (received and sent) and the Skill detail panel are delivered; `web/e2e/skill-handover.spec.ts` drives start → inbox → accept against the real API, and the flow was also verified in a browser against a local stack.
- [x] Keep same-slug handover cases off until 2a validation passes (REQ-ADDR-04). `SkillHandoverService.assertNoSameSlugConflict` refuses a request whose completion would leave the recipient or the former owner holding another ACTIVE record under the same slug, both at start and again under the lock at completion (REQ-HO-04). A third party's same-slug record does not block, because exact addressing already resolves that case. Four tests, mutation-checked by removing the guard.
- [x] Feature switch, rollback-boundary check and its validation. The default-off `SKILLHUB_HANDOVER_ENABLED` switch and its dev-stack wiring are delivered. `SkillOwnershipConversionTaskTest` pins that the conversion switch converts nothing when off and one bounded batch when on; the restriction lives in the resolver and the My Skills query, so switching conversions off never restores a removed user's access.
- [x] Tests: unit, controller, real-database concurrency, E2E and populated-database upgrade. E2E (`web/e2e/skill-handover.spec.ts`) is delivered. `SkillOwnershipUpgradeTest` migrates a populated V130 database to V134 and asserts existing Skills stay user-owned with their owner, revision and version link untouched, pre-migration applications keep a null snapshot, and the ownership shape constraint still rejects a user-owned Skill with no owner.
## 3. Delivery 3: removal conversion and historical remediation
- [x] Record the removal event and register affected items with a set-based insert in the removal transaction; end access at commit (REQ-DEP-01, REQ-DEP-02, REQ-DEP-08). `V134__skill_ownership_conversion.sql`, `SkillOwnershipConversionService.registerRemoval`; both the namespace page and the admin console call it.
- [x] Batched, idempotent, retryable conversion worker with progress shown in namespace management (REQ-DEP-09). `SkillOwnershipConversionTask` plus `GET /namespaces/{slug}/ownership/conversions`.
- [x] Restriction bound to the removal event: a pending item restricts only its recorded responsibility while the recorded `ownership_revision` is current (REQ-DEP-09). `SkillResponsibilityResolver.responsibleUser` filters through `SkillOwnershipConversionService.isRestricted`.
- [x] Large-data validation: removal-transaction duration, lock waits and rollback on failure. Add a snapshot mechanism only if the results require it. `SkillOwnershipConversionPostgresTest` registers 500 owned Skills in one removal and asserts the item count plus a coarse 5s bound on the set-based insert, and asserts a forced failure keeps no event and no item; no snapshot mechanism was needed.
- [x] Remediation list and explicit audited actions for historical records (REQ-DEP-05). `GET /namespaces/{slug}/ownership/departed` plus `POST .../departed/{skillId}/convert`; the conversion is audited as `SKILL_OWNERSHIP_CONVERTED` with `trigger=HISTORICAL_REMEDIATION`, the real operator and the reason. Starting a maintainer assignment still uses the handover flow.
- [x] Remove-member dialog, "no maintainer" list and messages for old links (REQ-DEP-06). The remove dialog, the remediation list and the "no maintainer" list are in the web UI. A removed user following a saved Skill link gets the 403 carrying `error.skill.owner.membershipEnded`, which the detail page renders from `serverMessage` instead of a "may have been deleted" message.
- [x] Tests: removal not blocked by pending work, retry after partial failure, rejoin while incomplete, rejoin then valid reassignment then retry of the old item, source/copy consistency, audit operator, historical access denial. Unit 6 and real-database 9 delivered, including recovery accept racing the original owner's rejoin. `SkillHandoverConcurrencyPostgresTest` now also runs accept against the recipient's removal and accept against a recorded removal conversion; each ends in exactly one terminal state and never leaves responsibility on a user who is not a member. `SkillOwnershipConversionPostgresTest` already covers retry-after-reassignment, rejoin restriction, idempotency and copy exclusion.
---
## Earlier tasks for #974 (unchanged)
## 1. 实施前收敛
- [x] 刷新目标分支,确认当前需求与实施范围,用户已授权实施并创建 Issue #974。
- [ ] 基于冻结源码补齐各客户端与套件绑定入口的权限追踪,映射 REQ-OWN-01 至 REQ-OWN-07。
## 2. 服务端与界面
- [x] 统一当前所有者读取与成员维护权限,保留管理员独立授权。
- [x] 修正移除后写入口及旧旁路,补齐所有者列表、详情和受控下载读取。
- [x] 保留已有审核申请与现有账号停用/恢复行为。
- [x] 管理页面明确只读状态;如有契约变更,同步 OpenAPI 与生成类型。
- [x] 更新现有领域模型和用户文档中过时的成员移除/所有者权限说明,不新增转让或接管功能。
## 3. 验证和交付
- [ ] 完成关键阶段独立代码审查,并按正式流程冻结验证提交。
- [ ] 覆盖正常成员、移除后可读不可写、停用、重新加入、现有审核、管理员和跨空间回归。
- [ ] 对改动入口执行必要源码检查及固定提交运行/浏览器验收,不以单测替代运行证据。
- [ ] 汇总实际结果、人工复测、未验证项及 PR #797/Issue #732 的建议;未经授权不关闭或评论公开对象。