Skip to content

feat(projects): keep member roles, fix ownerless write access and add join requests - #1264

Merged
newexploreor merged 14 commits into
mainfrom
fix/project-member-roles
Nov 24, 2026
Merged

newexploreor merged 14 commits into
mainfrom
fix/project-member-roles

Conversation

@newexploreor

@newexploreor newexploreor commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

本 PR 包含两部分:修复项目成员权限的缺陷,以及新增「申请加入项目」。

一、成员权限修复(第 1 个提交)

问题

  1. 项目设置页把所有成员角色硬编码成 member(projectDraftFrom、captureProjectAdminForm、buildProjectPayload),后端又整体覆盖成员列表。Owner 每保存一次项目设置,maintainer 被降级、viewer 被提升为可写成员;界面上也无法设置角色。
  2. 后端不校验成员角色,任意字符串都能写入;insights 按 member.Role == "maintainer" 精确比较,大小写或空格不一致会失效。
  3. 无 Owner 项目的判定不一致:工作区编辑、浏览器、助手工作区都按「无 Owner 且无成员才开放」,只有 projectMemberWrites 是「无 Owner 就开放」,带成员的无主项目因此对任意登录用户可写。

改动

  • domain.NormalizeProjectMemberRole:空值归为 member,大小写和空格归一,只接受 maintainer / member / viewer;PUT /api/projects 遇到未知角色返回 400。
  • projectMemberWrites 与其他入口对齐:无 Owner 且无成员的项目才共享。
  • 项目设置「项目成员」每行增加角色选择(维护者 / 成员 / 只读),草稿、脏检查和保存都保留角色;说明文案改为各角色的实际权限。

二、申请加入项目(第 2 个提交)

流程

  • 非成员在项目卡片上点「申请加入」,可填写理由(最多 500 字),以成员身份申请;卡片随后显示「申请中 · 撤回」。
  • 项目 Owner、维护者和平台管理员在卡片上看到「N 个加入申请」,在「项目成员」页的「加入申请」区通过或拒绝,通过前可调整授予的角色。
  • 维护者只能授予成员或只读;只有 Owner 和平台管理员能授予维护者。
  • 每人每个项目同时只能有一条待审批申请;Owner、已是成员的用户,以及对所有人开放的项目(无 Owner 且无成员)不能申请。被拒绝或撤回后可以重新申请。
  • 通过时在同一事务里写入 project_members。前端把新成员同步进当前打开的项目草稿,避免之后保存项目设置时把刚通过的成员覆盖掉。

接口

方法 路径 说明
POST /api/projects/{id}/join-requests 发起申请 {role?, reason?}
GET /api/project-join-requests 自己的申请,以及自己负责审批的项目的全部申请;可按 projectId、status 过滤
POST /api/project-join-requests/{id}/approve 通过,可传 {role}
POST /api/project-join-requests/{id}/reject 拒绝
POST /api/project-join-requests/{id}/withdraw 申请人撤回

这些接口同时注册为 MCP 操作(project_join_request_*、project_join_requests_list),并补齐了 docs/api/openapi.yaml 契约。

数据

新表 project_join_requests,启动时由 AutoMigrate 自动创建;migrations/041_project_join_requests.sql 提供可选的手动 DDL。

目前没有站内通知:审批人通过项目卡片上的待审批数和「项目成员」页看到申请。

验证

  • go test ./internal/httpapi/ -run 'TestProjectJoinRequests|TestProjectContentWritesRequireMembership':覆盖申请、重复申请 409、Owner 或成员申请 409、申请维护者 400、开放项目 400、列表可见范围、普通成员或外人审批 403、维护者授予维护者 403、通过后入成员表、重复通过 409、撤回、拒绝后重新申请、Owner 授予维护者,以及上面三项权限修复。全部通过。
  • node web/project_admin_layout_test.js ...:覆盖角色保留和脏检查、卡片上的申请入口与「申请中」状态、审批人可见性、仅列出待审批申请、维护者看不到「维护者」选项、通过后成员同步进草稿且不会标记为未保存。全部通过。
  • 在本地服务里用浏览器完整走了一遍:非成员申请,看到「申请中」;维护者看到待审批数,进入「项目成员」后只能选成员或只读,点通过后列表更新、没有出现未保存提示;接口确认成员已入库,申请人随后能在该项目创建需求。
  • go vet ./...、scripts/check-public.py 通过。
  • go test -p=2 ./...:cmd/agentflow 的 TestSDNotifySendsReadyAndMainPID、internal/runtime 的 Docker 相关用例,以及 web 的 TestNativeChatLazyImportsAreEmbedded(需要构建 web/native-chat)失败。在同一沙箱里切到干净的 main 也同样失败,属于环境问题,与本 PR 无关。

兼容性

  • 存量空角色按 member 处理,与原有写权限语义一致。
  • 无 Owner 但有成员的存量项目,非成员将不再能写入。
  • 新表只增不改,不影响已有数据。

yowucai and others added 2 commits November 23, 2026 13:23
… members

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@newexploreor newexploreor changed the title fix(projects): keep member roles and limit ownerless team projects to members feat(projects): keep member roles, fix ownerless write access and add join requests Nov 23, 2026

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

定向 HTTP 测试和项目设置前端测试通过。本地 Docker MySQL 复现了旧草稿覆盖已通过成员、审批角色与实际角色不一致,以及归档后仍能审批。前端复现了角色选择被刷新重置、申请人获批后仍看到申请入口。

Comment thread web/app/projects.js Outdated
renderProjectList();toast('已撤回加入申请','ok');
}catch(err){toast(err.message,'err');loadProjectJoinRequests(true)}
}
// Approval writes the member server-side; mirror it into the open draft so a later save does not drop the new member.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 防止旧项目草稿移除新获批成员

当前同步只更新发起审批的页面。Owner 已打开项目设置时,维护者可在另一会话通过申请;Owner 随后只改项目说明也会提交旧的 members,writeProject 会按旧名单替换成员。本地 MySQL 复现后,申请仍是 approved,申请人已退出成员表。建议由服务端保护成员变更,例如校验成员名单版本并拒绝过期写入,或把成员变更改为增量操作。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 432b139 修复:成员名单替换必须携带 membersVersion,并在项目写事务内校验当前名单版本;旧草稿保存返回 409,不能移除其他会话刚批准的成员。省略 members 的设置更新则保留事务内的当前名单。TestProjectMembersVersionProtectsReplacement 已覆盖旧令牌、缺失令牌和设置更新。

now := timePtr(time.Now().UTC())
out.Status, out.ReviewerID, out.Reviewed, out.Updated = domain.JoinRequestRejected, &reviewerID, now, now
if approve {
out.Status, out.Role = domain.JoinRequestApproved, role

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 让审批记录反映实际成员角色

申请提交后,Owner 可能先把申请人直接加为 viewer。如果随后以默认角色 member 通过申请,冲突分支保留成员表里的 viewer,审批记录却返回 approved/member。已在本地 MySQL 确认这个差异。前端还会用返回的角色补进旧草稿,后续保存可能改掉原先的只读角色。建议在事务内发现已有成员时返回冲突,或按实际成员角色结算申请。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 432b139 修复:审批事务内重新检查申请人的当前身份,若已是 Owner 或成员就返回 409,申请继续保持 pending,已有角色不变。TestReviewProjectJoinRequestChecksLockedProject 覆盖了申请人已被直接加入为 viewer 和已成为 Owner 的场景。前端通过审批后也会读取完整的实际成员名单。

Comment thread internal/repo/project_join_requests.go Outdated
if out.Status != domain.JoinRequestPending {
return apperr.New(apperr.Conflict, "申请已处理,请刷新后查看")
}
if err := r.lockProjectInTx(tx, out.ProjectID); err != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 在审批事务里检查项目是否已归档

Project() 会返回归档项目,这里的加锁也只检查项目行是否存在。归档前提交的待审批申请仍然可以获批并新增成员,本地 MySQL 已复现。建议锁定项目行后校验归档状态和当前审批人权限,再更新申请和成员名单。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 432b139 修复:锁定项目行后,在同一审批事务内检查归档状态、当前 Owner/维护者权限及可授予角色,再更新申请与成员表。补充的测试覆盖归档后通过/拒绝、维护者权限撤销、Owner 变更以及维护者越权授予维护者,失败时申请和名单均保持不变。

Comment thread web/app/projects.js
function syncProjectJoinBox(){
const box=$('#projectAdminForm [data-pa-join-box]'),p=(state.data.projects||[]).find(x=>x.id===state.projectAdminDetailId);
if(!box||!p)return;
box.innerHTML=projectJoinRowsHTML(p);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 刷新申请列表时保留审批人选定的角色

列表请求还在进行时,审批人可以把某条申请从「成员」改成「只读」。响应到达后,innerHTML 会按申请人的原始角色重建下拉框,已经选好的「只读」会悄悄变回「成员」。处理一条申请也会重置其他待审批行。建议按申请 ID 保留已经选择的角色,直到该申请处理完成。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 432b139 修复:按申请 ID 保存审批人选择的角色,列表刷新和处理其他申请时会恢复该选择;对应申请结束后才清理。前端回归覆盖了请求未返回时选择 viewer,以及拒绝另一条申请后保留 viewer 选择,两条路径均通过。

Comment thread web/app/projects.js Outdated
if(!state.authRequired||!state.currentUser||state.currentUser.isGuest)return;
if(!force&&state.projectJoinLoadedAt&&Date.now()-state.projectJoinLoadedAt<30000)return;
state.projectJoinLoadedAt=Date.now();
try{state.projectJoinRequests=await api('/api/project-join-requests')||[]}catch{return}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 申请获批后同步申请人侧的项目成员名单

另一会话通过申请后,即使申请人重新打开项目页并拉到 approved,这里也只更新申请列表。projectJoinCardHTML 仍用旧的项目成员缓存判断身份,并且只查 pending 申请,卡片会从「申请中」退回「申请加入」。建议拉到当前用户获批的申请时同步对应项目的成员名单,再重绘卡片。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 432b139 修复:拉到当前用户的获批记录时先刷新对应项目的实际成员名单,再重绘卡片。使用服务端当前名单判断身份,避免历史获批记录把后来被移除的用户重新加入缓存。前端回归覆盖了获批后隐藏申请入口,以及移除后允许重新申请。

Reject stale member replacements with a roster snapshot token. Recheck project state, reviewer permissions and existing membership in approval transactions. Preserve review role selections across refreshes and refresh applicant membership after approval.

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 432b1398。本地 Docker MySQL 回归通过,覆盖旧成员令牌、已有成员、归档和审批权限;定向 HTTP、MCP 和前端测试也通过。前端另复现了两处刷新顺序导致的成员名单问题,见行内。

Comment thread web/app/projects.js
for(const id of Object.keys(state.projectJoinRoles||{}))if(!requests.some(r=>String(r.id)===id&&r.status==='pending'))delete state.projectJoinRoles[id];
}catch{return}
if(activeViewName()!=='projects')return;
if(state.projectAdminDetailId)syncProjectJoinBox();else renderProjectList();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 采纳新成员令牌时同步成员表单

refreshProjectJoinMembers() 会一起更新草稿、基线的名单和 membersVersion。项目详情打开时,这里只刷新申请区,成员表单保留旧数据。比如曾经申请加入、后来成为 Owner 的用户打开项目设置,其历史获批记录触发了成员刷新。若此时服务端已有刚获批的新成员,Owner 再改项目说明,captureProjectAdminForm() 会从旧表单重读名单,保存仍带有效的新令牌。我确认了这条路径会生成「旧名单 + 当前令牌」的提交,服务端会按该名单替换成员。请在采纳名单和令牌时同步更新成员表单,保留其他未保存字段。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 729f451 修复:采纳名单和 membersVersion 后立即同步成员面板里的 Owner/成员控件,包括隐藏面板;其他设置字段的 DOM 和未保存内容保留。新增回归按“历史获批记录触发刷新 → 修改说明 → 保存”验证,提交包含新成员和对应令牌。本地成员修改存在冲突时继续保留旧令牌。

Comment thread web/app/projects.js
async function refreshProjectJoinMembers(projectId){
const fresh=await api('/api/projects/'+encodeURIComponent(projectId)).catch(()=>null);
if(!fresh?.id)return;
storeSavedProject(fresh);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 防止较早的审批刷新覆盖最新成员名单

快速通过同一项目的两条申请会并发刷新名单。如果第一条审批读到的名单只包含第一位成员,响应比第二次刷新晚到,它会覆盖已经包含两位成员的缓存和草稿,并把令牌回退到第一次审批后的版本。用延迟响应验证后,两条申请都已通过,成员表少一人,当前草稿一保存就会收到 409。建议按项目串行刷新,或丢弃已被更新响应取代的快照。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 729f451 修复:为每个项目分别跟踪最新成员刷新请求,被后续请求取代的响应不会写入项目缓存、草稿、基线或表单。新增回归让第二次响应先返回、第一次后返回,确认两位新成员和最新令牌都保留;也覆盖不同项目独立刷新。移除该保护后回归能稳定复现名单回退。

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 729f4511。上轮的两条回归用例均通过,定向 Go 和前端测试也通过。用延迟响应交叉验证时,另复现了项目保存或归档被旧成员响应回退,以及已完成审批被旧列表恢复为待审批。

Comment thread web/app/projects.js Outdated
const refresh={};projectJoinMemberRefreshes.set(projectId,refresh);
const fresh=await api('/api/projects/'+encodeURIComponent(projectId)).catch(()=>null);
// A later refresh supersedes this snapshot, even if its response arrived first.
if(projectJoinMemberRefreshes.get(projectId)!==refresh)return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 让项目保存和归档也使旧的成员刷新失效

这个检查覆盖了两次成员 GET 之间的顺序。审批后的 GET 在途时,如果 Owner 在同一页面归档了项目,迟到的响应会经 storeSavedProject() 把已从缓存移除的项目插回,下一次重绘又出现该项目。用延迟响应也复现了保存成功后,旧的成员响应把缓存里的角色和项目说明回退。建议统一按项目使保存或归档之前发出的读取失效,并阻止归档项目重新进入列表。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 f4bda4b 修复:项目设置保存、默认仓库保存及归档成功后,统一使该项目的在途成员读取失效;成员响应还会检查归档状态及项目是否仍在当前列表中,避免旧响应回退角色、说明、默认仓库或恢复已归档项目。新增真实 DOM 回归分别覆盖这三种保存/归档后旧 GET 才返回的顺序。相关 Go 检查和控制台全量 243 个测试通过,行覆盖率 85.44%。

Comment thread web/app/projects.js
}
// Fetch the authoritative roster: an old approval must not re-add a user who was later removed.
await Promise.all([...approved].map(id=>refreshProjectJoinMembers(id)));
state.projectJoinRequests=requests;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] 保留申请列表刷新期间已完成的审批

审批人在上一次缓存的待审批列表上点击「通过」时,后台列表 GET 可能已读到旧的 pending 快照。复现时审批先成功,成员表也已更新;列表响应迟到后,这里的整体替换又把已通过的申请显示为待审批,再点「通过」会收到 409。建议保留读取发出后已经完成的本地操作,或让该列表响应失效并重新加载。

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在 f4bda4b 修复:申请、通过、拒绝、撤回成功后统一保留本地结果,并标记在途列表已过期;列表响应返回时、以及等待成员刷新完成后都会再次检查,只允许最新有效响应更新缓存和界面,过期列表会丢弃并重新读取。新增真实 DOM 回归覆盖四类写入、两次列表乱序和等待成员读取期间发生审批,确认不会恢复待审批按钮。控制台全量检查及覆盖率门槛通过。

@crispinhu27 crispinhu27 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 53498820。本轮更新了测试并同步 main,项目加入申请的前端代码与上轮相同。用最新提交重跑延迟响应验证,以下两处仍可复现。

  • 迟到的成员响应会回退保存后的缓存,也会把已归档的项目插回列表。原评论
  • 迟到的申请列表会把已通过的申请重新显示为待审批。原评论

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 53498820。项目加入、成员版本和项目设置的定向测试通过。我在前端测试中控制请求返回顺序,确认上轮两处问题仍可复现。

  • [P2] 审批后发出的成员 GET 在归档成功后返回,已从列表移除的项目被重新加入缓存。建议在项目保存或归档成功时,使此前发出的成员读取失效。 对应代码讨论
  • [P2] 待审批列表 GET 在途时通过一条申请,旧响应最后返回会再次显示该申请的「通过」按钮。建议丢弃写入成功前发出的旧列表响应,并重新读取。 对应代码讨论

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 f4bda4b7。9 项加入申请 DOM 回归通过,上轮指出的迟到成员读取和迟到申请列表均已修复。用反向响应顺序又复现了一个缓存回退。

[P2] 防止较慢的设置保存响应覆盖已刷新成员名单

Owner 保存项目说明,服务端完成 PUT 后响应暂缓。随后通过一条加入申请,成员 GET 已把新成员和新 membersVersion 写到前端。旧 PUT 最后返回,storeSavedProject() 整体替换项目,把新成员和成员版本一起回退。本地用两个延迟响应复现,申请已通过,名单从两人又回到一人。

请在采纳设置保存响应时核对成员名单是否已在请求期间刷新,冲突时重新读取项目。 涉及的保存逻辑

@newexploreor

Copy link
Copy Markdown
Collaborator Author

@Robert0622 已针对本轮复审在 be7baf1 修复反向响应顺序。

项目保存现在统一核对请求发出时的缓存快照和本地修订号;期间发生过成员读取、缓存更新或归档时,不采纳迟到的保存快照,而是重读仍存在的项目。已归档的项目不会恢复。设置页、默认仓库保存和新建向导共用此路径,向导还会同步实际成员名单、草稿和基线。

新增 11 项真实 DOM 回归,覆盖保存晚于审批刷新、审批成员读取尚未返回或失败、保存期间归档、交错设置保存,以及创建响应晚于缓存刷新或归档。原有回归也保留。

验证:254 个控制台测试全部通过,行覆盖率 85.45%;项目设置/向导与 JS 解析的 Go 检查、公开内容检查通过。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 be7baf15。上轮的晚到设置响应覆盖新成员用例已通过,21 项 DOM 回归和项目相关的定向 Go 测试通过。我补测了向导草稿刷新和重读失败,复现以下两处。

  • [P1] 向导应提交与成员草稿对应的版本。 打开向导的成员步骤后,另一会话通过加入申请,工作台触发的项目列表刷新把新名单和版本载入缓存。向导仍保留旧名单。此时在向导里移除一个原有成员并保存,clone(saved) 带入最新版本,fields.members 却送出旧名单。DOM 回归确认 PUT 带的是审批后的版本,名单却漏了刚获批的成员,后端会接受并整体替换。建议让成员草稿和版本一起刷新,或提交草稿原来的版本,让服务端拦住冲突。 向导保存逻辑
  • [P2] 保存后的重读失败时应提示页面同步失败。 项目说明的 PUT 已成功,如果在途期间发生过成员刷新,persistProject() 会重读项目。用 503 模拟重读失败后,页面仍提示「项目设置已保存」并清空草稿,缓存里的项目说明却保持旧值。建议让重读结果区分失败与成功,失败时保留编辑内容并提示重新加载。 保存与重读逻辑

The wizard members step built its payload from the cached project, so a
roster refreshed by someone else's approval was paired with the step's
older member list and the server accepted the replacement, dropping the
member that had just been approved. The step now submits the token of the
roster it loaded, so a conflicting write is rejected, and reloads the
current members afterwards so the next save targets them.

A project save that needs an authoritative re-read also reported success
when that read failed, clearing the draft while the page still showed
pre-save content. The refresh now reports whether it settled, and the save
raises a sync warning instead, keeping the edits for a retry.
@newexploreor

Copy link
Copy Markdown
Collaborator Author

@Robert0622 已针对本轮复审在 58cdde2 修复两处。

[P1] 向导提交与成员草稿对应的版本。 成员步骤改为提交它加载的那份名单的 membersVersion,而不是缓存里被刷新过的最新版本;buildProjectPayload 现在把 members 和 membersVersion 当作同一份快照,谁带名单就得带对应令牌。这样在成员步骤打开期间别处通过加入申请时,整体替换会被服务端拦下而不是悄悄删掉刚获批的成员。失败后该步骤会重新载入当前名单并提示「项目成员已经变化」,下一次保存针对的是最新名单,不会卡死。

[P2] 保存后的重读失败会提示页面未同步。 refreshProjectJoinMembers() 现在区分「读取失败」与「已被更新的请求取代/项目已归档」:只有读取本身失败才返回 false。persistProject() 在需要权威重读却读取失败时抛出「保存已提交,但页面没能同步到最新内容,请刷新页面后确认。」,设置页因此保留草稿和未保存标记并提示,不再清空草稿、谎报已保存。

验证:新增 2 项真实 DOM 回归(向导提交旧名单对应的令牌并在失败后载入最新名单;503 重读失败后缓存未采纳保存快照、草稿保留、toast 提示未同步),移除修复后两条都能稳定复现。控制台全量 256 个测试通过,行覆盖率 85.46%(门槛 85%);go test ./web/ -run 'TestProjectAdminLayout|TestProjectWizard|TestProjectDefaultSOP|TestSyntax'、项目加入申请与成员版本相关的 Go 定向测试、scripts/check-public.py 均通过。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了 58cdde2e。上轮两个独立复现都通过了。向导提交草稿对应的成员版本,冲突后载入最新名单。保存后单次重读返回 503 时,页面提示未同步并保留草稿。

[P2] 保存应等待接替的项目重读完成

设置 PUT 成功后,persistProject() 发出用于更新页面的 GET。此时另一条加入申请获批,发出的成员 GET 取代前一个请求。DOM 回归让两次 GET 都返回 503,第一条因为已被取代,在判断 failed 前就返回了 true。设置页随后提示「项目设置已保存」并清空草稿,第二条 GET 也失败后,缓存仍显示旧项目说明。

建议让保存路径等待接替请求的结果,或在还没有可用的新快照时提示未同步并保留草稿。 成员重读逻辑 保存逻辑

A member refresh that was superseded reported success without knowing
whether anything had reached the page, so a save whose own read was
replaced by an approval refresh cleared the draft and claimed success
even when both reads failed and the cache still held the old project.

A superseded refresh now resolves to the outcome of the refresh that
replaced it; a missing entry still counts as settled because only a
project write or delete removes it, and both install authoritative state.
@newexploreor

Copy link
Copy Markdown
Collaborator Author

@Robert0622 已针对本轮复审在 3ee357c 修复被接替的重读。

[P2] 保存等待接替请求的结果。 之前被接替的 refreshProjectJoinMembers() 直接返回 true,等于替后来的请求打包票。现在每次刷新带一个 settle 句柄:被接替时等待接替它的那次刷新的结果并原样返回,自己读到的内容一律不采纳;映射里没有条目才算已落定,因为只有项目写入或归档会清掉条目,而这两者都会装入权威状态。采纳快照的部分拆成 adoptProjectRoster(),读取失败时不再有中途 return 漏掉结论。

这样两次 GET 都失败时,保存路径拿到的是 false,设置页提示「保存已提交,但页面没能同步到最新内容,请刷新页面后确认。」并保留草稿和未保存标记;接替请求成功时则照常静默采纳,不会误报。

验证:新增 1 项真实 DOM 回归(保存自己的重读在途时被审批刷新接替,两次读取都返回 503 → 缓存未采纳保存快照、提示未同步、草稿保留且仍标记未保存),移除修复后可稳定复现。控制台全量 257 个测试通过,行覆盖率 85.47%;go test ./web/ -run 'TestProjectAdminLayout|TestProjectWizard|TestProjectDefaultSOP|TestSyntax' 与 scripts/check-public.py 通过。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

增量复审 + 实机验证:#1264 feat(projects): keep member roles, fix ownerless write access and add join requests

结论:通过(无阻塞问题,仅 1 条 P3 健壮性建议,可在本 PR 或后续顺手处理)

  • Reviewed head:54fcd7a271d3f98485b92cd70f58d9d70f742866
  • 上次复审 head:58cdde2e;本轮增量:3ee357c2(修上一轮 P2)、bcfe650e(合并 origin/main be35aff8)、54fcd7a2(测试夹具刷新 + e2e 用例)

上一轮问题复核

[P2] 被取代的 refreshProjectJoinMembers() 返回 true,替后发的请求做担保:已修复

3ee357c2 改成每次 refresh 带一个 done/settle 句柄。被取代的 refresh 改为等待取代它的那次的结果(web/app/projects.js:556);当前那次结束后先 adoptProjectRoster(fresh) 再 settle(!failed)(:559-560);map 中没有条目时按“已由写入/删除落定”处理,返回 true。

证据:

  1. 作者新增的用例 a save waits for the refresh that superseded its own read,在 3ee357c2 上把 web/app/projects.js 换回 58cdde2e 版本后跑,失败(not ok 1);用当前版本跑,通过。说明这个用例确实覆盖了上一轮的问题。
  2. 我另外写了 3 个探针用例(jsdom,复用 webtest/lib/load-app.mjs),都通过:
    • 自己的读后返回且失败,但取代它的审批读已成功拿到包含本次保存的项目:保存按成功处理,description 和 membersVersion 都落到缓存,草稿清空,没有误报“没能同步”。
    • 三次 refresh 串联(A←B←C),A、B 先返回,C 最后失败:A 会一直等到 C 结束,最终 A、B、C 都返回 false,页面提示“没能同步到最新内容”,草稿保留。
    • refresh 进行中项目被删除:两次 refresh 都返回 true,项目没有被旧读复活。
  3. 推演过的边界:只有旧的 refresh 等新的,新的从不等旧的,所以不会形成等待环。已结束的 refresh 留在 map 里,下一次 refresh 开始时会被 invalidateProjectJoinMembers 覆盖,storeSavedProject 也会删掉它,不会被拿来当成别的请求的结果。persistProject 用的 revision 计数没有变,并发保存的判定和之前一致。

新发现

[P3] adoptProjectRoster() 抛异常时,等待中的前一次 refresh 永远不会 settle

  • 现象:refreshProjectJoinMembers 在 adoptProjectRoster(fresh) 之后才调 refresh.settle(...),中间没有 try/finally。如果 adopt 过程中渲染相关代码抛错(captureProjectAdminForm、renderProjectDetail 等),当前那次 refresh 的调用方会收到 reject,但等着它的 latest.done 一直不会 resolve。依赖它的保存(persistProject → saveProjectAdmin)就一直挂着,提交按钮保持 disabled。
  • 复现:探针用例:A、B 两次 refresh,A 先返回;把 captureProjectAdminForm 改成抛错后让 B 返回。B 以 boom reject,A 300ms 后仍是 pending。触发条件是人为构造的,目前正常路径下没有发现会抛错的输入,所以只算健壮性问题。
  • 位置:web/app/projects.js:559-560
  • 建议:改成 try{ if(...) adoptProjectRoster(fresh) } finally { refresh.settle(!failed) }(或在 catch 里 settle(false)),保证每个句柄都一定会 settle。

其他检查(未发现问题)

  • bcfe650e 合并:git show --remerge-diff bcfe650e 输出为空;git merge-tree --write-tree 3ee357c2 be35aff8 得到的 tree f15e4641 和合并提交的 tree 完全一致。说明这是纯自动合并,没有手工改动冲突。两边都改过的文件有 docs/api/openapi.yaml、internal/httpapi/server.go、internal/repo/models.go、web/i18n-en.js。逐个看过:路由、allModels() 和 i18n 两边的内容都保留了。
  • 54fcd7a2 夹具刷新没有掩盖真实失败:三个 Go 测试原来的写法是读一次项目、两次 PutProject 改成员。PR 在 store 层加了 MembersVersion 校验,第二次写会因为版本过期被拒,这是预期行为。改动只是在第二次写之前重新读项目拿到当前版本,另外 bot_drafts_test.go 原来忽略了 PutProject 的错误,现在改成 t.Fatal,比之前更严格。我把生产代码里所有 PutProject 调用方都看了一遍(auth_register.go 欢迎项目加人、catalog.go 删仓库清默认仓库、assistant_acceptance.go、projects.go),都是先读后写或者只写全新项目(acceptance 只在 repo.OpenTest() 的新库上 seed)。main 合进来的 #1114 机器人代码里没有新增修改成员的写入点,所以没有生产路径会被新校验误伤。
  • 迁移:新增的 migrations/041_project_join_requests.sql 是可选 DDL。启动时 autoMigrateIncremental 会自动建 project_join_requests 表,lane 上确认表已经自动建好,不需要手工执行。我又手工跑了一次这个 SQL,CREATE TABLE IF NOT EXISTS 幂等,没有报错。编号和 main 的 041_native_sandbox_inline_assets.sql 重号,仓库里已经有 036/037/039 重号的先例,不影响执行。

验证

环境:PR lane http://127.0.0.1:18101(54fcd7a2,库 lf_pr1264),基线 main lane http://127.0.0.1:18091(be35aff8)。用户有 admin、alice、bob、carol、dave。

项目 命令 / 方法 结果
webtest 全量 cd webtest && node --test --test-concurrency=4 'tests/**/*.test.mjs' 281/281 通过(含 project-join-requests.test.mjs 全部用例)
上一轮问题的回归用例 新用例跑在把 projects.js 换回 58cdde2e 的版本上 旧代码失败,新代码通过
探针用例 我写的 4 个 jsdom 用例(见上) 3 个行为用例通过;1 个用于确认 P3(挂起可复现)
Go vet go vet ./internal/{repo,httpapi,domain,application,notification,botinteraction} ./web 通过
Go test go test -count=1 ./internal/{repo,httpapi,domain,application,notification,botinteraction}/... ./web/... repo/domain/notification/botinteraction/web 全过;httpapi 有 14 个失败,在 main 上跑同一组测试失败完全一致,原因是环境缺少 bwrap、浏览器、ssh 等,和本 PR 无关
e2e API AGENTFLOW_E2E_BASE=…18101 AGENTFLOW_E2E_TOKEN=<admin> AGENTFLOW_E2E_TOKEN_B=<dave> node --test api/58-permissions.test.mjs api/59-project-join-requests.test.mjs 59 通过(撤回、拒绝、通过以及过期名单 409 都覆盖到);58 需要本机验收登录,跳过

实机 API 检查(脚本用 curl 带 cookie 和 Origin 头):

  • 成员角色保留:创建无 Owner 的团队项目 team1,成员 alice=maintainer、carol=viewer,POST 和 GET 返回的角色都正确。审批通过时指定的角色(bob=viewer、dave=member)原样写入;Owner 在 UI 里把 dave 改成 maintainer 后保存,服务端返回 [{4,viewer},{5,maintainer}]。
  • 无 Owner 团队项目的写权限(用 POST /api/knowledge/submissions 测):PR 上 alice(maintainer)=200、bob(非成员)=403、carol(viewer)=403。main 上同样配置的项目 bob(非成员)=200,说明修复生效。没有 Owner 也没有成员的 open1 仍然对所有人开放:bob=200,bob 申请加入返回 400「该项目对所有人开放,无需申请」。
  • 加入申请:bob 申请后 200,重复申请 409;carol(viewer) 审批 403;bob 自己审批 403;alice(maintainer) 能在列表里看到这条申请。maintainer 的角色下拉只有「成员/只读」两项,只有 Owner 和平台管理员能授予维护者。
  • membersVersion:PUT 带 members 但不带 membersVersion 返回 409「更新成员名单需要 membersVersion」;带过期 membersVersion 返回 409「项目成员已变化」;不带 members 的设置保存返回 200,成员名单不变。
  • UI 审批后名单刷新:alice 在 team2 的「项目成员」页点「通过」后,申请从待审批里消失,成员列表立即出现 bob(viewer)。projectAdminDirty() 前后都是 false,草稿的 membersVersion 和缓存一致,toast 显示「已通过,bob(bob)已加入项目」。
  • UI 并发冲突:alice 在 team3 改了 carol 的角色但还没保存,期间 dave 的申请在服务端被通过,alice 再提交,toast 显示「项目成员已变化,请刷新项目后重试」。服务端名单仍是 [{4,viewer},{5,member}],dave 没有被旧名单覆盖,alice 的本地编辑也保留着。
  • server.log 里没有 panic,也没有 5xx。

截图

申请人 bob 在项目列表看到「申请中 / 撤回」

维护者 alice 在项目成员页看到两条待审批申请(角色下拉只有成员/只读)

点击「通过」后成员列表立即刷新,bob 以只读身份加入,页面未变脏

成员名单已被并发修改时保存,提示「项目成员已变化」,本地编辑保留

Owner 修改成员角色后保存成功,角色保留

@newexploreor
newexploreor merged commit c42e224 into main Nov 24, 2026
16 checks passed
@newexploreor
newexploreor deleted the fix/project-member-roles branch November 24, 2026 14:30
Robert0622 pushed a commit that referenced this pull request Nov 24, 2026
…e to main's new copy

main added 042_project_credentials.sql and 042_skill_bodies_to_files.sql,
so the terminology migration becomes 043_loop_terminology.sql; the
installer, its test and the deployment guide follow.

Rename the user-visible SOP copy from #1264, #1294, #1295, #1296 and
#1298 (project roles, join requests, project credentials, workspace
preview messages) with the same rules as the rest of the branch.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Robert0622 added a commit that referenced this pull request Nov 26, 2026
* feat: rename SOP to LOOP across LoopForge

* Apply LOOP terminology to copy merged from main and fix CHANGELOG anchor

Rename the user-visible SOP copy that main added for the enterprise IM
channels, observability dashboard and docs, following the same rules as
the rest of this branch (routes, JSON fields and identifiers unchanged).

Keep accepting the old wording where it can still arrive: notification
cards skip both LOOP and SOP header lines, chat drafts recognise both
(LOOP:…) and (SOP:…) notes, and the clarification command accepts
"保存并启动 LOOP" as well as "保存并启动 SOP".

Point the CHANGELOG link at #updating-existing-public-loops.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Renumber the LOOP terminology migration to 043 and re-apply the rename to main's new copy

main added 042_project_credentials.sql and 042_skill_bodies_to_files.sql,
so the terminology migration becomes 043_loop_terminology.sql; the
installer, its test and the deployment guide follow.

Rename the user-visible SOP copy from #1264, #1294, #1295, #1296 and
#1298 (project roles, join requests, project credentials, workspace
preview messages) with the same rules as the rest of the branch.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Restore the legacy (SOP:…) draft note check clobbered by the rename sweep

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(chatbot): recognize proposal receipts saved before the LOOP rename

Conversations saved before the rename still hold the SOP wording of the
declined and timed-out proposal receipts. The chat matched only the new
LOOP text, so these internal resume turns showed up as user messages.
Accept both wordings.

Rooms also parse LOOP「…」 authors with the correct length and keep
recognizing legacy SOP「…」 authors.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Apply LOOP terminology to the chat attribution copy merged from main

#1300 added a clarification test that expects the bot reply "已启动 SOP" and a comment that says "a SOP started". This branch already renders "已启动 LOOP", so the test failed after merging main.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Resume paused children marked before the LOOP rename

The child-resume marker merged from #1327 now reads "等待继续子 LOOP". A parent paused on a build that stored "等待继续子 SOP" still resumes its child after admission.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* test: cover run evaluation before approval

* test: exercise five previously uncovered platform routes

* fix: translate LOOP evaluation and runner allocation messages

* fix(engine): name LOOP in the remaining auto-assign errors

The default-executor fallback label and the no-compatible-sandbox
error still said SOP after the main merge.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix: name LOOP in errors merged from main

Four user-visible errors that arrived with main (#1342 work branch naming,
#1343/#1348 runner auto-assign, #1301 child artifacts) still said SOP.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* fix(migrations): preserve customized LOOP template copy

* test(install): copy migration 043 into the live install fixture

install-schema-extensions.sh now replays migrations/043_loop_terminology.sql,
but test-install-live.sh only copied 001/033/038/042 into its trimmed
fixture, so every live install identity stopped at the first install with
'cat: migrations/043_loop_terminology.sql: No such file or directory'.

Copy 043 as well, and add a test-install.py check that every migration the
installer replays is in the live fixture's copy list, so CI catches the
next one.

Co-Authored-By: Claude Code <noreply@anthropic.com>

* Name LOOP in comments and test copy merged from main

The merge of main kept the product copy for requirements without a LOOP,
but comments, test fixtures and failure messages around #1411's sopMode
still said SOP. Use the LOOP terminology there too; protocol values such as
sopMode none/sop and Go identifiers keep their names.

Co-Authored-By: Claude Code <noreply@anthropic.com>

---------

Co-authored-by: roberttwang <roberttwang@tencent.com>
Co-authored-by: roberttwang <u_dc6754cd1ee5@users.noreply.local>
Co-authored-by: Claude Code <noreply@anthropic.com>
Co-authored-by: Codex <codex@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants